import itertools



N = int(eval(input()))

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

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



ans = -10 ** 10

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

    if f == (0,) * 10:

        continue

    p = 0

    for i in range(N):

        p += P[i][sum([F[i][j] * f[j] for j in range(10)])]

    ans = max(ans, p)



print(ans)

import itertools



N = int(eval(input()))

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

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



ans = -10 ** 10

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

    p = sum([P[i][sum([F[i][j] * f[j] for j in range(10)])] for i in range(N)])

    ans = max(ans, p)



print(ans)

import itertools

N = int(eval(input()))
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
ans = -(10**10)
for f in itertools.product([0, 1], repeat=10):
    if f == (0,) * 10:
        continue
    p = 0
    for i in range(N):
        p += P[i][sum([F[i][j] * f[j] for j in range(10)])]
    ans = max(ans, p)
print(ans)

import itertools

N = int(eval(input()))
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
ans = -(10**10)
for f in list(itertools.product([0, 1], repeat=10))[1:]:
    p = sum([P[i][sum([F[i][j] * f[j] for j in range(10)])] for i in range(N)])
    ans = max(ans, p)
print(ans)

-for f in itertools.product([0, 1], repeat=10): -    if f == (0,) * 10: -        continue -    p = 0 -    for i in range(N): -        p += P[i][sum([F[i][j] * f[j] for j in range(10)])] +for f in list(itertools.product([0, 1], repeat=10))[1:]: +    p = sum([P[i][sum([F[i][j] * f[j] for j in range(10)])] for i in range(N)])