import itertools

import numpy as np

N = int(eval(input()))

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

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

benefit = -float("inf")



for i in itertools.product((0, 1), repeat=10):

    if sum(i) != 0:

        C = np.array(list(i)) + F

        pre_benefit = 0

        for j in range(N):

            count = len(np.where(C[j]==2)[0])

            pre_benefit += P[j][count]

        if benefit < pre_benefit:

            benefit = pre_benefit

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

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

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

ans = -float('inf')



for i in range(2**10):

    bag = []

    for j in range(10):

        if (i>>j)&1:

            bag += [j]



    tmp = 0

    is_cnt = False

    for n in range(N):

        f = F[n]

        cnt = 0

        for b in bag:

            if f[b] == 1:

                cnt += 1

        tmp += P[n][cnt]

        if cnt:

            is_cnt = True

    

    if is_cnt:

        ans = max(ans, tmp)



print(ans)



    



        







import itertools
import numpy as np

N = int(eval(input()))
F = np.array([list(map(int, input().split())) for _ in range(N)])
P = [list(map(int, input().split())) for _ in range(N)]
benefit = -float("inf")
for i in itertools.product((0, 1), repeat=10):
    if sum(i) != 0:
        C = np.array(list(i)) + F
        pre_benefit = 0
        for j in range(N):
            count = len(np.where(C[j] == 2)[0])
            pre_benefit += P[j][count]
        if benefit < pre_benefit:
            benefit = pre_benefit
print(benefit)

N = int(eval(input()))
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
ans = -float("inf")
for i in range(2**10):
    bag = []
    for j in range(10):
        if (i >> j) & 1:
            bag += [j]
    tmp = 0
    is_cnt = False
    for n in range(N):
        f = F[n]
        cnt = 0
        for b in bag:
            if f[b] == 1:
                cnt += 1
        tmp += P[n][cnt]
        if cnt:
            is_cnt = True
    if is_cnt:
        ans = max(ans, tmp)
print(ans)

-import itertools -import numpy as np - -F = np.array([list(map(int, input().split())) for _ in range(N)]) +F = [list(map(int, input().split())) for _ in range(N)] -benefit = -float("inf") -for i in itertools.product((0, 1), repeat=10): -    if sum(i) != 0: -        C = np.array(list(i)) + F -        pre_benefit = 0 -        for j in range(N): -            count = len(np.where(C[j] == 2)[0]) -            pre_benefit += P[j][count] -        if benefit < pre_benefit: -            benefit = pre_benefit -print(benefit) +ans = -float("inf") +for i in range(2**10): +    bag = [] +    for j in range(10): +        if (i >> j) & 1: +            bag += [j] +    tmp = 0 +    is_cnt = False +    for n in range(N): +        f = F[n] +        cnt = 0 +        for b in bag: +            if f[b] == 1: +                cnt += 1 +        tmp += P[n][cnt] +        if cnt: +            is_cnt = True +    if is_cnt: +        ans = max(ans, tmp) +print(ans)