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**9

def bfs(x):

    if len(x) == 10:

        if 1 in x:

            global ans

            a = 0

            for i in range(n):

                f,p = F[i],P[i]

                c = 0

                for j in range(10):

                    if x[j] == f[j] == 1: c+=1

                a+=p[c]

            ans = max(ans,a)

    else:

        bfs(x + [0])

        bfs(x + [1])

bfs([])

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

data = list(itertools.product(list(range(2)), repeat = 10))[1:]

ans = -10**9

for d in data:

    a = 0

    for i in range(n):

        c = 0

        for j in range(10):

            if f[i][j] and d[j]: c+=1

        a+=p[i][c]

    ans = max(ans,a)

print(ans)
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**9)


def bfs(x):
    if len(x) == 10:
        if 1 in x:
            global ans
            a = 0
            for i in range(n):
                f, p = F[i], P[i]
                c = 0
                for j in range(10):
                    if x[j] == f[j] == 1:
                        c += 1
                a += p[c]
            ans = max(ans, a)
    else:
        bfs(x + [0])
        bfs(x + [1])


bfs([])
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)]
data = list(itertools.product(list(range(2)), repeat=10))[1:]
ans = -(10**9)
for d in data:
    a = 0
    for i in range(n):
        c = 0
        for j in range(10):
            if f[i][j] and d[j]:
                c += 1
        a += p[i][c]
    ans = max(ans, a)
print(ans)

+import itertools + -F = [list(map(int, input().split())) for _ in range(n)] -P = [list(map(int, input().split())) for _ in range(n)] +f = [list(map(int, input().split())) for _ in range(n)] +p = [list(map(int, input().split())) for _ in range(n)] +data = list(itertools.product(list(range(2)), repeat=10))[1:] - - -def bfs(x): -    if len(x) == 10: -        if 1 in x: -            global ans -            a = 0 -            for i in range(n): -                f, p = F[i], P[i] -                c = 0 -                for j in range(10): -                    if x[j] == f[j] == 1: -                        c += 1 -                a += p[c] -            ans = max(ans, a) -    else: -        bfs(x + [0]) -        bfs(x + [1]) - - -bfs([]) +for d in data: +    a = 0 +    for i in range(n): +        c = 0 +        for j in range(10): +            if f[i][j] and d[j]: +                c += 1 +        a += p[i][c] +    ans = max(ans, a)