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=-float("inf")
for j in range(1,2**10):
  A=list(str(bin(j))[2:])
  for i in range(10-len(A)):
    A.insert(0,"0")  
  prof=0
  for i in range(n):
    k=sum(int(p)*q for p,q in zip(A,F[i]))
    prof+=P[i][k]
  ans=max(ans,prof)
print(ans)