N = int(input())
F = [[int(i) for i in input().split()] for j in range(N)]
P = [[int(i) for i in input().split()] for k in range(N)]
x = -(10**10)
for i in range(1,2**10):
    L = [int(b) for b in str(bin(i))[2:]]
    y = 0
    for n in range(N):
        m = sum([l&f for l, f in zip(L, F[n])])
        y += P[n][m]
    x = max(x, y)
print(x)
