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(1, 2 ** 10):

    i_bin = "{:010b}".format(i)

    sm = 0

    for shop_i in range(n):

        cnt = 0

        for j, dig in enumerate(i_bin):

            if f[shop_i][j] * int(dig):# == 1

                cnt += 1

        sm += p[shop_i][cnt]

    ans = max(ans, sm)

        

print(ans)

from itertools import combinations



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 = - 10 ** 18

for i in range(1, 11):

    for pat in combinations(list(range(10)), i):

        cnt = [0] * n

        for e in pat:

            for j in range(n):

                cnt[j] += f[j][e]



        score = 0

        for i, e in enumerate(cnt):

            score += p[i][e]



        ans = max(ans, score)



print(ans)

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(1, 2**10):
    i_bin = "{:010b}".format(i)
    sm = 0
    for shop_i in range(n):
        cnt = 0
        for j, dig in enumerate(i_bin):
            if f[shop_i][j] * int(dig):  # == 1
                cnt += 1
        sm += p[shop_i][cnt]
    ans = max(ans, sm)
print(ans)

from itertools import combinations

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 = -(10**18)
for i in range(1, 11):
    for pat in combinations(list(range(10)), i):
        cnt = [0] * n
        for e in pat:
            for j in range(n):
                cnt[j] += f[j][e]
        score = 0
        for i, e in enumerate(cnt):
            score += p[i][e]
        ans = max(ans, score)
print(ans)

+from itertools import combinations + -ans = -float("inf") -for i in range(1, 2**10): -    i_bin = "{:010b}".format(i) -    sm = 0 -    for shop_i in range(n): -        cnt = 0 -        for j, dig in enumerate(i_bin): -            if f[shop_i][j] * int(dig):  # == 1 -                cnt += 1 -        sm += p[shop_i][cnt] -    ans = max(ans, sm) +ans = -(10**18) +for i in range(1, 11): +    for pat in combinations(list(range(10)), i): +        cnt = [0] * n +        for e in pat: +            for j in range(n): +                cnt[j] += f[j][e] +        score = 0 +        for i, e in enumerate(cnt): +            score += p[i][e] +        ans = max(ans, score)