#from collections import Counter

N=int(eval(input()))

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

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

ans=-(1<<40)

for bit in range(1,1<<10):

    tmp = 0

    for i in range(N):

        c=0

        for j in range(10):

            if bit&(1<<j) and F[i][j]:

                c+=1

        tmp+=P[i][c]

    ans = max(ans,tmp)

print(ans)
#from collections import Counter

N=int(eval(input()))

F=list(int(input().replace(" ",""),2) for i in range(N))

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

ans=-(1<<40)

for bit in range(1,1<<10):

    tmp = 0

    for i in range(N):

        tmp+=P[i][bin(bit&F[i]).count('1')]

    ans = max(ans,tmp)

print(ans)
# from collections import Counter
N = int(eval(input()))
F = list(list(map(int, input().split())) for i in range(N))
P = list(list(map(int, input().split())) for i in range(N))
ans = -(1 << 40)
for bit in range(1, 1 << 10):
    tmp = 0
    for i in range(N):
        c = 0
        for j in range(10):
            if bit & (1 << j) and F[i][j]:
                c += 1
        tmp += P[i][c]
    ans = max(ans, tmp)
print(ans)

# from collections import Counter
N = int(eval(input()))
F = list(int(input().replace(" ", ""), 2) for i in range(N))
P = list(list(map(int, input().split())) for i in range(N))
ans = -(1 << 40)
for bit in range(1, 1 << 10):
    tmp = 0
    for i in range(N):
        tmp += P[i][bin(bit & F[i]).count("1")]
    ans = max(ans, tmp)
print(ans)

-F = list(list(map(int, input().split())) for i in range(N)) +F = list(int(input().replace(" ", ""), 2) for i in range(N)) -        c = 0 -        for j in range(10): -            if bit & (1 << j) and F[i][j]: -                c += 1 -        tmp += P[i][c] +        tmp += P[i][bin(bit & F[i]).count("1")]