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 j in range(N)]

ci = 0
c = []
P_max = -1000000000
for i in range(2):
    for j in range(2):
        for k in range(2):
            for l in range(2):
                for m in range(2):
                    for n in range(2):
                        for o in range(2):
                            for p in range(2):
                                for q in range(2):
                                    for r in range(2):
                                        if i==j==k==l==m==n==o==p==q==r==0:
                                            pass
                                        for s in range(N):
                                            ci = F[s][0]*i + F[s][1]*j + F[s][2]*k + F[s][3]*l + F[s][4]*m + F[s][5]*n + F[s][6]*o + F[s][7]*p + F[s][8]*q + F[s][9]*r
                                            c.append(ci)
                                        P_sample = P[0][c[0]] + P[1][c[1]] + P[2][c[2]] + P[3][c[3]] + P[4][c[4]] + P[5][c[5]] + P[6][c[6]] + P[7][c[7]] + P[8][c[8]] + P[9][c[9]]
                                        P_max = max(P_max, P_sample)

print(P_max)
