n = int(input())
f = [int(input().replace(" ",""),2) for j in range(n)]
p = [[int(i) for i in input().split()] for i in range(n)]

out = float('-inf')


for i in range(1,1024):
    b = 0
    for j in range(n):
        b += p[j][bin(f[j] & i).count('1')]
    out = max(b, out)
print(out)

