n=int(input())
s=[]
k=[]
ans=0
qw=-999999999999999999
for i in range(n):
  a=list(map(int,input().split()))
  s.append(a)
for j in range(n):
  b=list(map(int,input().split()))
  k.append(b)
for i in range(n):
  for j in range(10):
    if s[i][j]==1 and k[i][j]>0:
      ans+=k[i][j]
    elif s[i][j]==1 and k[i][j]<0:
      qw=max(qw,k[i][j])
if ans>0:
  print(ans)
else:
  print(qw)