N=int(eval(input()))

M=[[0 for i in range(2**10)] for j in range(N)]

K=[0]*(2**10)

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

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



for i in range(2**10):

  for j in range(10):

    for k in range(N):

      if (i>>9-j)&1 and F[k][j]:

        #print(i,j)

        M[k][i]+=1



for i in range(2**10):

  for k in range(N):

    K[i]+=P[k][M[k][i]]

print((max(K[1:])))
N = int(eval(input()))

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

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



answer = []

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

  tmp = 0

  for j in range(N):

    cnt = 0

    for k in range(10):

      if (i >> k) & 1 and F[j][k]:

        cnt += 1

    tmp += P[j][cnt]

  answer.append(tmp)

  

print((max(answer)))
N = int(eval(input()))
M = [[0 for i in range(2**10)] for j in range(N)]
K = [0] * (2**10)
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
for i in range(2**10):
    for j in range(10):
        for k in range(N):
            if (i >> 9 - j) & 1 and F[k][j]:
                # print(i,j)
                M[k][i] += 1
for i in range(2**10):
    for k in range(N):
        K[i] += P[k][M[k][i]]
print((max(K[1:])))

N = int(eval(input()))
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
answer = []
for i in range(1, 2**10):
    tmp = 0
    for j in range(N):
        cnt = 0
        for k in range(10):
            if (i >> k) & 1 and F[j][k]:
                cnt += 1
        tmp += P[j][cnt]
    answer.append(tmp)
print((max(answer)))

-M = [[0 for i in range(2**10)] for j in range(N)] -K = [0] * (2**10) -for i in range(2**10): -    for j in range(10): -        for k in range(N): -            if (i >> 9 - j) & 1 and F[k][j]: -                # print(i,j) -                M[k][i] += 1 -for i in range(2**10): -    for k in range(N): -        K[i] += P[k][M[k][i]] -print((max(K[1:]))) +answer = [] +for i in range(1, 2**10): +    tmp = 0 +    for j in range(N): +        cnt = 0 +        for k in range(10): +            if (i >> k) & 1 and F[j][k]: +                cnt += 1 +        tmp += P[j][cnt] +    answer.append(tmp) +print((max(answer)))