ans = -10 ** 9

A = [0] * 10





def func():

    if sum(A) == 0:

        return

    score = 0

    for i in range(N):

        days = sum([a * f for a, f in zip(A, F[i])])

        score += P[i][days]

    global ans

    ans = max(ans, score)





def dfs(pos):

    if pos == 10:

        func()

        return

    A[pos] = 0

    dfs(pos + 1)

    A[pos] = 1

    dfs(pos + 1)





N = int(eval(input()))



F = []

for i in range(N):

    F.append(list(map(int, input().split())))

P = []

for i in range(N):

    P.append(list(map(int, input().split())))



dfs(0)

print(ans)

def calc(days):

    if sum(days) == 0:

        return

    profit = 0

    for i in range(N):

        both = 0

        for f, d in zip(F[i], days):

            if f == d == 1:

                both += 1

        profit += P[i][both]

    global ans

    ans = max(ans, profit)





def dfs(days):

    if len(days) == 10:

        calc(days)

        return

    dfs(days + [0])

    dfs(days + [1])





ans = 10 ** 9 * (-1)

N = int(eval(input()))

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

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



dfs([])

print(ans)

ans = -(10**9)
A = [0] * 10


def func():
    if sum(A) == 0:
        return
    score = 0
    for i in range(N):
        days = sum([a * f for a, f in zip(A, F[i])])
        score += P[i][days]
    global ans
    ans = max(ans, score)


def dfs(pos):
    if pos == 10:
        func()
        return
    A[pos] = 0
    dfs(pos + 1)
    A[pos] = 1
    dfs(pos + 1)


N = int(eval(input()))
F = []
for i in range(N):
    F.append(list(map(int, input().split())))
P = []
for i in range(N):
    P.append(list(map(int, input().split())))
dfs(0)
print(ans)

def calc(days):
    if sum(days) == 0:
        return
    profit = 0
    for i in range(N):
        both = 0
        for f, d in zip(F[i], days):
            if f == d == 1:
                both += 1
        profit += P[i][both]
    global ans
    ans = max(ans, profit)


def dfs(days):
    if len(days) == 10:
        calc(days)
        return
    dfs(days + [0])
    dfs(days + [1])


ans = 10**9 * (-1)
N = int(eval(input()))
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
dfs([])
print(ans)

-ans = -(10**9) -A = [0] * 10 +def calc(days): +    if sum(days) == 0: +        return +    profit = 0 +    for i in range(N): +        both = 0 +        for f, d in zip(F[i], days): +            if f == d == 1: +                both += 1 +        profit += P[i][both] +    global ans +    ans = max(ans, profit) -def func(): -    if sum(A) == 0: +def dfs(days): +    if len(days) == 10: +        calc(days) -    score = 0 -    for i in range(N): -        days = sum([a * f for a, f in zip(A, F[i])]) -        score += P[i][days] -    global ans -    ans = max(ans, score) +    dfs(days + [0]) +    dfs(days + [1]) -def dfs(pos): -    if pos == 10: -        func() -        return -    A[pos] = 0 -    dfs(pos + 1) -    A[pos] = 1 -    dfs(pos + 1) - - +ans = 10**9 * (-1) -F = [] -for i in range(N): -    F.append(list(map(int, input().split()))) -P = [] -for i in range(N): -    P.append(list(map(int, input().split()))) -dfs(0) +F = [list(map(int, input().split())) for _ in range(N)] +P = [list(map(int, input().split())) for _ in range(N)] +dfs([])