n = int(input())
f = [int(''.join(input().split()), 2) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]
print(max(
    sum(p[i][sum(map(int, bin(b & f[i])[2:]))] for i in range(n))
    for b in range(1, 2**10)))