import sys

from itertools import product



input = sys.stdin.readline



N = int(eval(input()))

F = [[int(x) for x in input().split()] for _ in range(N)]

P = [[int(x) for x in input().split()] for _ in range(N)]



ans = float('-inf')

for ptn in product([0, 1], repeat=10):

    if sum(ptn) == 0:

        continue



    res = 0

    for i in range(N):

        cnt = 0

        for j in range(10):

            cnt += F[i][j] * ptn[j]

        res += P[i][cnt]

    ans = max(ans, res)

print(ans)

import sys



input = sys.stdin.readline



N = int(eval(input()))

F = [int(input().replace(' ', ''), 2) for _ in range(N)]

P = [[int(x) for x in input().split()] for _ in range(N)]



ans = float('-inf')

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

    res = 0

    for f, p in zip(F, P):

        cnt = bin(i & f).count('1')

        res += p[cnt]

    ans = max(ans, res)

print(ans)
import sys
from itertools import product

input = sys.stdin.readline
N = int(eval(input()))
F = [[int(x) for x in input().split()] for _ in range(N)]
P = [[int(x) for x in input().split()] for _ in range(N)]
ans = float("-inf")
for ptn in product([0, 1], repeat=10):
    if sum(ptn) == 0:
        continue
    res = 0
    for i in range(N):
        cnt = 0
        for j in range(10):
            cnt += F[i][j] * ptn[j]
        res += P[i][cnt]
    ans = max(ans, res)
print(ans)

import sys

input = sys.stdin.readline
N = int(eval(input()))
F = [int(input().replace(" ", ""), 2) for _ in range(N)]
P = [[int(x) for x in input().split()] for _ in range(N)]
ans = float("-inf")
for i in range(1, 2**10):
    res = 0
    for f, p in zip(F, P):
        cnt = bin(i & f).count("1")
        res += p[cnt]
    ans = max(ans, res)
print(ans)

-from itertools import product -F = [[int(x) for x in input().split()] for _ in range(N)] +F = [int(input().replace(" ", ""), 2) for _ in range(N)] -for ptn in product([0, 1], repeat=10): -    if sum(ptn) == 0: -        continue +for i in range(1, 2**10): -    for i in range(N): -        cnt = 0 -        for j in range(10): -            cnt += F[i][j] * ptn[j] -        res += P[i][cnt] +    for f, p in zip(F, P): +        cnt = bin(i & f).count("1") +        res += p[cnt]