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

ma = -(1<<100)
for k in range(1, 1024):
    s = 0
    for i in range(N):
        s += P[i][bin(F[i] & k).count("1")]
    ma = max(ma, s)
print(ma)