N=int(input())
F=[[int(i) for i in input().split()] for j in range(N)]
P=[[int(i) for i in input().split()] for j in range(N)]
print(max([(sum([P[shop][sum([i*j for i,j in zip([i>>k & 1 for k in range(10)],F[shop])])] for shop in range(N)])) for i in range(1,1024)]))