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

m = -(10 ** 10)
for i in range(1, 1024):
    r = 0
    for f, p in zip(F, P):
        r += p[bin(i & int(''.join(str(_) for _ in f), 2))[2:].count('1')]
    m = max(r, m)
print(m)