N=int(input())
F=[int(input().replace(' ', ''), 2) for i in range(N)]
P=[[int(j) for j in input().split()] for j in range(N)]
a=-10**10
for i in range(1,1024):
    a=max(a, sum([P[j][bin(i&F[j]).count('1')] for j in range(N)]))
print(a)