int input for in range append list map int input split for in range До

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
n = int(input())
A = []
B = []
for i in range(n):
A.append(list(map(int, input().split())))
for i in range(n):
k = 0 #Дороги
p = 0 #Направления
for j in range(n):
if A[i][j]+A[j][i]==2:
p += 2
k += 1
if A[i][j]+A[j][i]==1:
p += 1
k += 1
if k > 1:
B.append(p)
else:
B.append(0)
print (sum(B))
print (*B)