import sys input = sys.stdin.readline N=int(input()) X=[set() for i in range(N)] for i in range(N): L=list(map(int,input().split())) for j in range(N): if L[j]==1: X[i].add(j) A=list(map(int,input().split())) ANS=1<<60 for i in range(1<