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

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

  tmp=0

  for j in range(N):

    cnt=0

    for k in range(10):

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

        cnt+=1

    tmp+=P[j][cnt]

  ans=max(ans,tmp)

print(ans)
import sys

input=sys.stdin.readline

N=int(eval(input()))

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

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



ans=-10**18

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

  cnt=0

  for j in range(N):

    cnt+=P[j][bin(F[j] & i).count('1')]

  ans=max(ans,cnt)

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**18)
for i in range(1, 2**10):
    tmp = 0
    for j in range(N):
        cnt = 0
        for k in range(10):
            if i & (1 << k) and F[j][k]:
                cnt += 1
        tmp += P[j][cnt]
    ans = max(ans, tmp)
print(ans)

import sys

input = sys.stdin.readline
N = int(eval(input()))
F = [int(input().replace(" ", ""), 2) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
ans = -(10**18)
for i in range(1, 2**10):
    cnt = 0
    for j in range(N):
        cnt += P[j][bin(F[j] & i).count("1")]
    ans = max(ans, cnt)
print(ans)

+import sys + +input = sys.stdin.readline -F = [list(map(int, input().split())) for _ in range(N)] +F = [int(input().replace(" ", ""), 2) for _ in range(N)] -    tmp = 0 +    cnt = 0 -        cnt = 0 -        for k in range(10): -            if i & (1 << k) and F[j][k]: -                cnt += 1 -        tmp += P[j][cnt] -    ans = max(ans, tmp) +        cnt += P[j][bin(F[j] & i).count("1")] +    ans = max(ans, cnt)