int input int for in input split for in range list map int input split

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
a = int(input())
k = 0
A = [[int(j) for j in input().split()] for i in range(a)]
b = list(map(int, input().split()))
for i in range(len(b)-1):
if (A[b[i]-1][b[i+1]-1] == 0):
k = 0
break
k+=A[b[i]-1][b[i+1]-1]
print(k)