n = int(input())
F = [ int("".join(input().split()), 2) for _ in range(n) ]
P = [ list(map(int, input().split())) for _ in range(n) ]
ans = -float("inf")
for i in range(1, 2**10):
  t = 0
  for j in range(n):
    c = bin(F[j] & i).count("1")
    t += P[j][c]
  ans = max(ans, t)
print(ans)