N = int(input())
F = [int(input().replace(' ',''), 2) for _ in range(N)]
P = [[int(i) for i in input().split()] for _ in range(N)]

ma = -1e20
for i in range(1, 2 ** 10):
    count = 0
    for f, p in zip(F, P):
        count += p[bin(f & i).count("1")]
    ma = max(ma, count)
print(ma)