N = int(eval(input()))

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

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



ans = -10**9

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

    open = []

    for j in range(10):

        if ((i>>j) & 1):

            open.append(1)

        else:

            open.append(0)

    money = 0

    for num in range(N):

        Flist = Flists[num]

        same = sum([int(open[_] and Flist[_]) for _ in range(10)])

        money += Plists[num][same]

    ans = max(ans, money)



print(ans)

N = int(eval(input()))

F = [int("".join(input().split()), 2) for _ in range(N)]

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



# for i in range(N):

#     print(bin(F[i]))



ans = -10**9

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

    money = 0

    for i in range(N):

        cnt = format(bit&F[i], 'b').count('1')

        money += P[i][cnt]

    ans = max(money, ans)

 

print(ans)

N = int(eval(input()))
Flists = [list(map(int, input().split())) for _ in range(N)]
Plists = [list(map(int, input().split())) for _ in range(N)]
ans = -(10**9)
for i in range(1, 2**10):
    open = []
    for j in range(10):
        if (i >> j) & 1:
            open.append(1)
        else:
            open.append(0)
    money = 0
    for num in range(N):
        Flist = Flists[num]
        same = sum([int(open[_] and Flist[_]) for _ in range(10)])
        money += Plists[num][same]
    ans = max(ans, money)
print(ans)

N = int(eval(input()))
F = [int("".join(input().split()), 2) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
# for i in range(N):
#     print(bin(F[i]))
ans = -(10**9)
for bit in range(1, 1 << 10):
    money = 0
    for i in range(N):
        cnt = format(bit & F[i], "b").count("1")
        money += P[i][cnt]
    ans = max(money, ans)
print(ans)

-Flists = [list(map(int, input().split())) for _ in range(N)] -Plists = [list(map(int, input().split())) for _ in range(N)] +F = [int("".join(input().split()), 2) for _ in range(N)] +P = [list(map(int, input().split())) for _ in range(N)] +# for i in range(N): +#     print(bin(F[i])) -for i in range(1, 2**10): -    open = [] -    for j in range(10): -        if (i >> j) & 1: -            open.append(1) -        else: -            open.append(0) +for bit in range(1, 1 << 10): -    for num in range(N): -        Flist = Flists[num] -        same = sum([int(open[_] and Flist[_]) for _ in range(10)]) -        money += Plists[num][same] -    ans = max(ans, money) +    for i in range(N): +        cnt = format(bit & F[i], "b").count("1") +        money += P[i][cnt] +    ans = max(money, ans)