N = int(input())
F = [list(input().split()) for i in range(N)]
P = [list(map(int,input().split())) for i in range(N)]
F2 = [int("".join(F[i]), 2) for i in range(N)]

ans = - 10**10

def cost(i) :
    tem = 0
    for j in range(N) :
        d = bin(i & F2[j]).count("1")
        tem += P[j][d]
    return tem

for i in range(1, 2**10) :
    ans = max(ans, cost(i))

print(ans)
