N = int(input())
F = [list(map(int, input().split())) for k in range(N)]
P = [list(map(int, input().split())) for k in range(N)]
B = [(bin(k))[2:] for k in range(1,1024)]
ans = -10**9

for d in B:
    t = 0
    E = [0 for k in range(N)]
    for l in range(N):
        for k in range(len(d)):
            E[l] += int(d[k])*F[l][k]
    for k in range(N):
        t += P[k][E[k]]
    ans = max(t,ans)
print(ans)