N = int(input())
f = [int(input().replace(' ',''),2) for _ in range(N)]
p = [list(map(int,input().split())) for _ in range(N)]
g = -9999999999
for i in range(1,1024):
    gg = 0
    for j in range(N):
        s = (format(i & f[j],'b').zfill(10))
        c = s.count('1')
        gg += p[j][c]
    g = max(g,gg)
print(g)