N=int(input())
F=[int(input().replace(' ',''),2)for _ in[0]*N]
P=[list(map(int,input().split()))for _ in[0]*N]
ans = -float('inf')
for i in range(1,2**10):
    sum = 0
    for k in range(N):
        sum += P[k][bin(F[k]&i).count('1')]
    if ans < sum:
        ans = sum
print(ans)