N = int(eval(input()))

F = [list(map(int,input().split())) for n in range(N)]

P = [list(map(int,input().split())) for n in range(N)]

ans = []



for i in range(1,1024):

  p = 0

  for j in range(N):

    c = 0

    for k in range(10):

      if (i>>k&1) & F[j][k]:

        c+=1

    p+=P[j][c]

  ans+=[p]

    

print((max(ans)))
N = int(eval(input()))

F = [int("".join(input().split()),2) for n in range(N)]

P = [list(map(int,input().split())) for n in range(N)]

print((max(sum(p[bin(n&f).count("1")]for f,p in zip(F,P)) for n in range(1,1024))))
N = int(eval(input()))
F = [list(map(int, input().split())) for n in range(N)]
P = [list(map(int, input().split())) for n in range(N)]
ans = []
for i in range(1, 1024):
    p = 0
    for j in range(N):
        c = 0
        for k in range(10):
            if (i >> k & 1) & F[j][k]:
                c += 1
        p += P[j][c]
    ans += [p]
print((max(ans)))

N = int(eval(input()))
F = [int("".join(input().split()), 2) for n in range(N)]
P = [list(map(int, input().split())) for n in range(N)]
print(
    (max(sum(p[bin(n & f).count("1")] for f, p in zip(F, P)) for n in range(1, 1024)))
)

-F = [list(map(int, input().split())) for n in range(N)] +F = [int("".join(input().split()), 2) for n in range(N)] -ans = [] -for i in range(1, 1024): -    p = 0 -    for j in range(N): -        c = 0 -        for k in range(10): -            if (i >> k & 1) & F[j][k]: -                c += 1 -        p += P[j][c] -    ans += [p] -print((max(ans))) +print( +    (max(sum(p[bin(n & f).count("1")] for f, p in zip(F, P)) for n in range(1, 1024))) +)