N = int(eval(input()))

F = [[0 for _ in range(10)] for _ in range(N)]

P = [[0 for _ in range(10)] for _ in range(N)]



for i in range(N) :

    F[i] = list(map(int, input().split()))

for i in range(N) :

    P[i] = list(map(int, input().split()))



ans = -float('inf')

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

    profit = 0

    for shop in range(N) :

        count = 0

        for time in range(10) :

            if (mask & (1 << time) != 0) and F[shop][time] == 1 :

                count += 1

        profit += P[shop][count]

    ans = max(ans, profit)



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



F = []

for _ in range(N):

    mask = 0

    for f in map(int, input().split()):

        mask <<= 1

        mask |= f

    F.append(mask)



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



def calc(state):

    ret = 0

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

        f &= state

        cnt = 0

        while f > 0:

            cnt += f % 2

            f //= 2

        ret += ps[cnt]

    return ret



ans = -10**18

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

    ans = max(ans, calc(state))

print(ans)

N = int(eval(input()))
F = [[0 for _ in range(10)] for _ in range(N)]
P = [[0 for _ in range(10)] for _ in range(N)]
for i in range(N):
    F[i] = list(map(int, input().split()))
for i in range(N):
    P[i] = list(map(int, input().split()))
ans = -float("inf")
for mask in range(1, 2**10):
    profit = 0
    for shop in range(N):
        count = 0
        for time in range(10):
            if (mask & (1 << time) != 0) and F[shop][time] == 1:
                count += 1
        profit += P[shop][count]
    ans = max(ans, profit)
print(ans)

N = int(eval(input()))
F = []
for _ in range(N):
    mask = 0
    for f in map(int, input().split()):
        mask <<= 1
        mask |= f
    F.append(mask)
P = [list(map(int, input().split())) for _ in range(N)]


def calc(state):
    ret = 0
    for f, ps in zip(F, P):
        f &= state
        cnt = 0
        while f > 0:
            cnt += f % 2
            f //= 2
        ret += ps[cnt]
    return ret


ans = -(10**18)
for state in range(1, 1 << 10):
    ans = max(ans, calc(state))
print(ans)

-F = [[0 for _ in range(10)] for _ in range(N)] -P = [[0 for _ in range(10)] for _ in range(N)] -for i in range(N): -    F[i] = list(map(int, input().split())) -for i in range(N): -    P[i] = list(map(int, input().split())) -ans = -float("inf") -for mask in range(1, 2**10): -    profit = 0 -    for shop in range(N): -        count = 0 -        for time in range(10): -            if (mask & (1 << time) != 0) and F[shop][time] == 1: -                count += 1 -        profit += P[shop][count] -    ans = max(ans, profit) +F = [] +for _ in range(N): +    mask = 0 +    for f in map(int, input().split()): +        mask <<= 1 +        mask |= f +    F.append(mask) +P = [list(map(int, input().split())) for _ in range(N)] + + +def calc(state): +    ret = 0 +    for f, ps in zip(F, P): +        f &= state +        cnt = 0 +        while f > 0: +            cnt += f % 2 +            f //= 2 +        ret += ps[cnt] +    return ret + + +ans = -(10**18) +for state in range(1, 1 << 10): +    ans = max(ans, calc(state))