n = int(input())
f = [list(map(int, input().split())) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]

ans = -float('inf')
for k in range(1, 2**10):
    *bi, = map(int, bin(k).zfill(10).replace('b', '0')[::-1])
    ans = max(ans, sum([p[i][[bi[j] & f[i][j] for j in range(10)].count(1)]
              for i in range(n)]))
print(ans)
