n = int(eval(input()))

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

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



def calcBit(num):

    res = []

    for _ in range(10):

        res.append(num%2)

        num >>= 1

    return res



ans = -float('inf')

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

    ans_t = 0

    for k,l in enumerate(f):

        tmp = 0

        for (a,b) in zip(l,calcBit(i)):

            if a==1 and b==1:

                tmp += 1

        ans_t += p[k][tmp]

    ans = max(ans,ans_t)



print(ans)

n = int(eval(input()))

f = [list(map(int,input().split())) for i in range(n)]

p = [list(map(int,input().split())) for i in range(n)]



res = -float('inf')

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

    a = [0]*n

    for j in range(10):

        for m in range(n):

            if i&1 and f[m][j]:

                a[m] += 1

        i >>= 1

    w = 0

    for j in range(n):

        w += p[j][a[j]]

    res = max(res,w)

print(res)

n = int(eval(input()))
f = [list(map(int, input().split())) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]


def calcBit(num):
    res = []
    for _ in range(10):
        res.append(num % 2)
        num >>= 1
    return res


ans = -float("inf")
for i in range(1, 2**10):
    ans_t = 0
    for k, l in enumerate(f):
        tmp = 0
        for (a, b) in zip(l, calcBit(i)):
            if a == 1 and b == 1:
                tmp += 1
        ans_t += p[k][tmp]
    ans = max(ans, ans_t)
print(ans)

n = int(eval(input()))
f = [list(map(int, input().split())) for i in range(n)]
p = [list(map(int, input().split())) for i in range(n)]
res = -float("inf")
for i in range(1, 1 << 10):
    a = [0] * n
    for j in range(10):
        for m in range(n):
            if i & 1 and f[m][j]:
                a[m] += 1
        i >>= 1
    w = 0
    for j in range(n):
        w += p[j][a[j]]
    res = max(res, w)
print(res)

-f = [list(map(int, input().split())) for _ in range(n)] -p = [list(map(int, input().split())) for _ in range(n)] - - -def calcBit(num): -    res = [] -    for _ in range(10): -        res.append(num % 2) -        num >>= 1 -    return res - - -ans = -float("inf") -for i in range(1, 2**10): -    ans_t = 0 -    for k, l in enumerate(f): -        tmp = 0 -        for (a, b) in zip(l, calcBit(i)): -            if a == 1 and b == 1: -                tmp += 1 -        ans_t += p[k][tmp] -    ans = max(ans, ans_t) -print(ans) +f = [list(map(int, input().split())) for i in range(n)] +p = [list(map(int, input().split())) for i in range(n)] +res = -float("inf") +for i in range(1, 1 << 10): +    a = [0] * n +    for j in range(10): +        for m in range(n): +            if i & 1 and f[m][j]: +                a[m] += 1 +        i >>= 1 +    w = 0 +    for j in range(n): +        w += p[j][a[j]] +    res = max(res, w) +print(res)