import numpy as np
N = int(input())
Fa = [list(map(int,input().split())) for i in range(N)]
P = [list(map(int,input().split())) for i in range(N)]
F = np.array(Fa)
ans = - 10**8
for i in range(1,2**10):
    tmp = 0
    joi = np.array(list(map(int,format(i,"010b"))))
    for j in range(N):
        tmp += P[j][np.dot(joi,F[j])]
    ans = max(tmp, ans)
print(ans)