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 = 0
for j in range(n):
    ans += p[j][f[j][0] & 1]
for i in range(2, 1024):
  bene = 0
  for j in range(n):
    count = 0
    for k in range(10):
      count += f[j][k] & (i >> k)
    bene += p[j][count]
  ans = max(ans, bene)
print(ans)