n=int(input())
f=[[[0for i in range(2)]for j in range(5)]for k in range(n)]
p=[[0for i in range(11)]for j in range(n)]
opn=[[0for i in range(2)]for j in range(5)]
maxi=-10000000
for i in range(n):
  l=list(map(int,input().split()))
  for j in range(5):
    f[i][j][0]=l[j*2]
    f[i][j][1]=l[j*2+1]
for i in range(n):
  p[i]=list(map(int,input().split()))
for i in range(1,2**10):
  s=bin(i)[2:].zfill(10)
  for j in range(10):opn[j//2][j%2]=int(s[j])
  ben=0
  for j in range(n):
    same=0
    for k in range(10):
      same+=opn[k//2][k%2]*f[j][k//2][k%2]
    ben+=p[j][same]
  maxi=max([maxi,ben])
print(maxi)