N = int(eval(input()))

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

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



INF = float('inf')

ans = -INF

for b in range(1,2**10):

    tmp = 0

    for f,p in zip(fs,ps):

        c = 0

        for k in range(10):

            if b&(1<<k)==0: continue

            if f[k]: c += 1

        tmp += p[c]

    ans = max(ans, tmp)

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

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

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



ans = -float('inf')

for k in range(1,1<<10):

    tmp = 0

    for fs,ps in zip(F,P):

        cnt = 0

        for b in range(10):

            if (k>>b)&1 and fs[b]:

                cnt += 1

        tmp += ps[cnt]

    ans = max(ans, tmp)

print(ans)
N = int(eval(input()))
fs = [list(map(int, input().split())) for i in range(N)]
ps = [list(map(int, input().split())) for i in range(N)]
INF = float("inf")
ans = -INF
for b in range(1, 2**10):
    tmp = 0
    for f, p in zip(fs, ps):
        c = 0
        for k in range(10):
            if b & (1 << k) == 0:
                continue
            if f[k]:
                c += 1
        tmp += p[c]
    ans = max(ans, tmp)
print(ans)

N = int(eval(input()))
F = [list(map(int, input().split())) for i in range(N)]
P = [list(map(int, input().split())) for i in range(N)]
ans = -float("inf")
for k in range(1, 1 << 10):
    tmp = 0
    for fs, ps in zip(F, P):
        cnt = 0
        for b in range(10):
            if (k >> b) & 1 and fs[b]:
                cnt += 1
        tmp += ps[cnt]
    ans = max(ans, tmp)
print(ans)

-fs = [list(map(int, input().split())) for i in range(N)] -ps = [list(map(int, input().split())) for i in range(N)] -INF = float("inf") -ans = -INF -for b in range(1, 2**10): +F = [list(map(int, input().split())) for i in range(N)] +P = [list(map(int, input().split())) for i in range(N)] +ans = -float("inf") +for k in range(1, 1 << 10): -    for f, p in zip(fs, ps): -        c = 0 -        for k in range(10): -            if b & (1 << k) == 0: -                continue -            if f[k]: -                c += 1 -        tmp += p[c] +    for fs, ps in zip(F, P): +        cnt = 0 +        for b in range(10): +            if (k >> b) & 1 and fs[b]: +                cnt += 1 +        tmp += ps[cnt]