n = int(input())
F = [input().replace(' ','') for _ in range(n)]
P = [list(map(int, input().split())) for _ in range(n)]
ans = -10**12
for i in range(1, 1033):
  total = 0
  for j in range(n):
    k = int(F[j], 2)
    b = bin(k & i)
    total += P[j][b.count('1')]
    if total>ans:
      ans = total
print(ans)
