N=int(input())
F=[int(input().replace(" ",""), 2) for i in range(N)]
P=[list(map(int,input().split())) for i in range(N)]
ans=-10**7
for i in range(1,1 << 10):
  res=0
  for n in range(N):
    res+=P[n][bin(i & F[n]).count("1")]
  ans=max(res,ans)
print(ans)