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)]

b = [0,1]

ans = -float('inf')

for e in itertools.product(b,repeat=10):

    e = list(e)

    if e == [0]*10:

        continue

    res = 0

    for i in range(N):

        cnt = 0

        for j in range(10):

            if e[j] == 1 and F[i][j] == 1:

                cnt += 1

        res += P[i][cnt]

    if res > ans:

        ans = res

print(ans)
import itertools

inf = float('inf')



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 = -inf



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

    if not any(shift): continue

    res = 0

    for i,line in enumerate(F):

        c = 0

        for s, f in zip(shift, line):

            if s and f:

                c += 1

        res += P[i][c]

    if res > ans:

        ans = res



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)]
b = [0, 1]
ans = -float("inf")
for e in itertools.product(b, repeat=10):
    e = list(e)
    if e == [0] * 10:
        continue
    res = 0
    for i in range(N):
        cnt = 0
        for j in range(10):
            if e[j] == 1 and F[i][j] == 1:
                cnt += 1
        res += P[i][cnt]
    if res > ans:
        ans = res
print(ans)

import itertools

inf = float("inf")
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 = -inf
for shift in itertools.product([0, 1], repeat=10):
    if not any(shift):
        continue
    res = 0
    for i, line in enumerate(F):
        c = 0
        for s, f in zip(shift, line):
            if s and f:
                c += 1
        res += P[i][c]
    if res > ans:
        ans = res
print(ans)

+inf = float("inf") -F = [list(map(int, input().split())) for i in range(N)] -P = [list(map(int, input().split())) for i in range(N)] -b = [0, 1] -ans = -float("inf") -for e in itertools.product(b, repeat=10): -    e = list(e) -    if e == [0] * 10: +F = [list(map(int, input().split())) for _ in range(N)] +P = [list(map(int, input().split())) for _ in range(N)] +ans = -inf +for shift in itertools.product([0, 1], repeat=10): +    if not any(shift): -    for i in range(N): -        cnt = 0 -        for j in range(10): -            if e[j] == 1 and F[i][j] == 1: -                cnt += 1 -        res += P[i][cnt] +    for i, line in enumerate(F): +        c = 0 +        for s, f in zip(shift, line): +            if s and f: +                c += 1 +        res += P[i][c]