import itertools

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

ans = -100000000
for k in range(1,11):
  for j in itertools.combinations(range(10),k):
    tmp = 0
    for f,p in zip(F, P):
      num = sum([f[cnt] for cnt in j])
      tmp += p[num]
    ans = max(ans,tmp)
    
print(ans)