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

ans = -(10 ** 9)
for i in range(1, 2 ** 10):
    tmp = 0
    for j in range(N):
        f = int('0b' + ''.join(F[j]), 0)
        tmp += P[j][bin(i & f).count('1')]
    ans = max(ans, tmp)

print(ans)
