import itertools



N = int(eval(input()))

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

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



#print(F)

#print(P)



ans = -10**10

for v in itertools.product([1,0],repeat=10):

    if v != (0,0,0,0,0,0,0,0,0,0):

        bene = 0

        for i in range(N):

            c = 0

            for j in range(10):

                if v[j] == F[i][j] == 1:

                    c += 1

            bene += P[i][c]

        ans = max(ans,bene)

print(ans)

n = int(eval(input()))

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

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

ans = -10**10

for i in range(1,2**10):

    a = 0

    for j in range(n):

        a += p[j][sum(i>>k&1 and f[j][k] for k in range(10))]

    ans = max(ans,a)

print(ans)

import itertools

N = int(eval(input()))
F = [list(map(int, input().split())) for i in range(N)]
P = [list(map(int, input().split())) for i in range(N)]
# print(F)
# print(P)
ans = -(10**10)
for v in itertools.product([1, 0], repeat=10):
    if v != (0, 0, 0, 0, 0, 0, 0, 0, 0, 0):
        bene = 0
        for i in range(N):
            c = 0
            for j in range(10):
                if v[j] == F[i][j] == 1:
                    c += 1
            bene += P[i][c]
        ans = max(ans, bene)
print(ans)

n = int(eval(input()))
f = [list(map(int, input().split())) for i in range(n)]
p = [list(map(int, input().split())) for i in range(n)]
ans = -(10**10)
for i in range(1, 2**10):
    a = 0
    for j in range(n):
        a += p[j][sum(i >> k & 1 and f[j][k] for k in range(10))]
    ans = max(ans, a)
print(ans)

-import itertools - -N = int(eval(input())) -F = [list(map(int, input().split())) for i in range(N)] -P = [list(map(int, input().split())) for i in range(N)] -# print(F) -# print(P) +n = int(eval(input())) +f = [list(map(int, input().split())) for i in range(n)] +p = [list(map(int, input().split())) for i in range(n)] -for v in itertools.product([1, 0], repeat=10): -    if v != (0, 0, 0, 0, 0, 0, 0, 0, 0, 0): -        bene = 0 -        for i in range(N): -            c = 0 -            for j in range(10): -                if v[j] == F[i][j] == 1: -                    c += 1 -            bene += P[i][c] -        ans = max(ans, bene) +for i in range(1, 2**10): +    a = 0 +    for j in range(n): +        a += p[j][sum(i >> k & 1 and f[j][k] for k in range(10))] +    ans = max(ans, a)