n=int(input())
F=[int(input().replace(" ",""),2) for _ in range(n)]
P=[list(map(int,input().split())) for _ in range(n)]
ans=[]
for i in range(1,1024):
  p=0
  for j in range(n):
    p+=P[j][bin(i&F[j]).count("1")]
  ans.append(p)
print(max(ans))