N = int(eval(input()))

F = [list(map(int, input().split())) for k in range(N)]

P = [list(map(int, input().split())) for k in range(N)]

B = [format(k,'b').zfill(10) 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(10):

            E[l] += int(d[k])*F[l][k]

    for k in range(N):

        t += P[k][E[k]]

    ans = max(t,ans)



print(ans)
N = int(eval(input()))

F = [list(map(int,input().split())) for k in range(N)]

P = [list(map(int,input().split())) for k in range(N)]

ans = -float("inf")

for k in range(2**10):

    temp = 0

    S = [0 for l in range(N)]

    for s in range(N):

        for d in range(10):

            if (k>>d)&1 == 1:

                if F[s][d] == 1:

                    S[s] += 1

    if sum(S) > 0:

        for l in range(N):

            temp += P[l][S[l]]

        ans = max(ans,temp)



print(ans)

N = int(eval(input()))
F = [list(map(int, input().split())) for k in range(N)]
P = [list(map(int, input().split())) for k in range(N)]
B = [format(k, "b").zfill(10) 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(10):
            E[l] += int(d[k]) * F[l][k]
    for k in range(N):
        t += P[k][E[k]]
    ans = max(t, ans)
print(ans)

N = int(eval(input()))
F = [list(map(int, input().split())) for k in range(N)]
P = [list(map(int, input().split())) for k in range(N)]
ans = -float("inf")
for k in range(2**10):
    temp = 0
    S = [0 for l in range(N)]
    for s in range(N):
        for d in range(10):
            if (k >> d) & 1 == 1:
                if F[s][d] == 1:
                    S[s] += 1
    if sum(S) > 0:
        for l in range(N):
            temp += P[l][S[l]]
        ans = max(ans, temp)
print(ans)

-B = [format(k, "b").zfill(10) 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(10): -            E[l] += int(d[k]) * F[l][k] -    for k in range(N): -        t += P[k][E[k]] -    ans = max(t, ans) +ans = -float("inf") +for k in range(2**10): +    temp = 0 +    S = [0 for l in range(N)] +    for s in range(N): +        for d in range(10): +            if (k >> d) & 1 == 1: +                if F[s][d] == 1: +                    S[s] += 1 +    if sum(S) > 0: +        for l in range(N): +            temp += P[l][S[l]] +        ans = max(ans, temp)