icase=0

if icase==0:

    n=int(eval(input()))



    f=[]

    for i in range(n):

        fi=list(map(int,input().split()))

        f.append(fi)

    p=[]

    for i in range(n):

        pi=list(map(int,input().split()))

        p.append(pi)

elif icase==1: 

    n=1

    f=[[1, 1, 0, 1, 0, 0, 0, 1, 0, 1]]

    p=[[3, 4, 5, 6, 7, 8, 9, -2, -3, 4, -2]]

elif icase==2: 

    n=2

    f=[[1, 1, 1, 1, 1, 0, 0, 0, 0, 0],

       [0, 0, 0, 0, 0, 1, 1, 1, 1, 1]]

    p=[[0, -2, -2, -2, -2, -2, -1, -1, -1, -1, -1],

       [0, -2, -2, -2, -2, -2, -1, -1, -1, -1, -1]]

elif icase==3: 

    n=3

    f=[[1, 1, 1, 1, 1, 1, 0, 0, 1, 1],

       [0, 1, 0, 1, 1, 1, 1, 0, 1, 0],

       [1, 0, 1, 1, 0, 1, 0, 1, 0, 1]]

    p=[[-8, 6, -2, -8, -8, 4, 8, 7, -6, 2, 2],

       [-9, 2, 0, 1, 7, -5, 0, -2, -6, 5, 5],

       [6, -6, 7, -9, 6, -5, 8, 0, -9, -7, -7]]

    

import itertools

sumpmax=-10**11

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

    r=list(i)

    sump=0

    if sum(r)!=0:

        for jj in range(n):

            ci=0

            for j in range(10):

                ci=ci+r[j]*f[jj][j]

            sump=sump+p[jj][ci]

#            print(sump,r)

        sumpmax=max(sump,sumpmax)

print(sumpmax)
import itertools



n=int(eval(input()))

f=[[]]*n

for i in range(n):

    fij=list(map(int,input().split()))

#    f[i].append(fij)

    f[i]=fij

p=[[]]*n

for i in range(n):

    pij=list(map(int,input().split()))

    p[i]=pij

    

pmax=-10**11

for a in itertools.product([0,1], repeat=10):

    if sum(a)==0:

        continue

    psum=0

    for ni in range(n):

        k=0

        for i in range(10):

            if f[ni][i]==1 and a[i]==1:

                k+=1

        psum=psum+p[ni][k] 

    pmax=max(pmax,psum)   



print(pmax)

icase = 0
if icase == 0:
    n = int(eval(input()))
    f = []
    for i in range(n):
        fi = list(map(int, input().split()))
        f.append(fi)
    p = []
    for i in range(n):
        pi = list(map(int, input().split()))
        p.append(pi)
elif icase == 1:
    n = 1
    f = [[1, 1, 0, 1, 0, 0, 0, 1, 0, 1]]
    p = [[3, 4, 5, 6, 7, 8, 9, -2, -3, 4, -2]]
elif icase == 2:
    n = 2
    f = [[1, 1, 1, 1, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 1, 1, 1, 1]]
    p = [
        [0, -2, -2, -2, -2, -2, -1, -1, -1, -1, -1],
        [0, -2, -2, -2, -2, -2, -1, -1, -1, -1, -1],
    ]
elif icase == 3:
    n = 3
    f = [
        [1, 1, 1, 1, 1, 1, 0, 0, 1, 1],
        [0, 1, 0, 1, 1, 1, 1, 0, 1, 0],
        [1, 0, 1, 1, 0, 1, 0, 1, 0, 1],
    ]
    p = [
        [-8, 6, -2, -8, -8, 4, 8, 7, -6, 2, 2],
        [-9, 2, 0, 1, 7, -5, 0, -2, -6, 5, 5],
        [6, -6, 7, -9, 6, -5, 8, 0, -9, -7, -7],
    ]
import itertools

sumpmax = -(10**11)
for i in itertools.product([0, 1], repeat=10):
    r = list(i)
    sump = 0
    if sum(r) != 0:
        for jj in range(n):
            ci = 0
            for j in range(10):
                ci = ci + r[j] * f[jj][j]
            sump = sump + p[jj][ci]
        #            print(sump,r)
        sumpmax = max(sump, sumpmax)
print(sumpmax)

import itertools

n = int(eval(input()))
f = [[]] * n
for i in range(n):
    fij = list(map(int, input().split()))
    #    f[i].append(fij)
    f[i] = fij
p = [[]] * n
for i in range(n):
    pij = list(map(int, input().split()))
    p[i] = pij
pmax = -(10**11)
for a in itertools.product([0, 1], repeat=10):
    if sum(a) == 0:
        continue
    psum = 0
    for ni in range(n):
        k = 0
        for i in range(10):
            if f[ni][i] == 1 and a[i] == 1:
                k += 1
        psum = psum + p[ni][k]
    pmax = max(pmax, psum)
print(pmax)

-icase = 0 -if icase == 0: -    n = int(eval(input())) -    f = [] -    for i in range(n): -        fi = list(map(int, input().split())) -        f.append(fi) -    p = [] -    for i in range(n): -        pi = list(map(int, input().split())) -        p.append(pi) -elif icase == 1: -    n = 1 -    f = [[1, 1, 0, 1, 0, 0, 0, 1, 0, 1]] -    p = [[3, 4, 5, 6, 7, 8, 9, -2, -3, 4, -2]] -elif icase == 2: -    n = 2 -    f = [[1, 1, 1, 1, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 1, 1, 1, 1]] -    p = [ -        [0, -2, -2, -2, -2, -2, -1, -1, -1, -1, -1], -        [0, -2, -2, -2, -2, -2, -1, -1, -1, -1, -1], -    ] -elif icase == 3: -    n = 3 -    f = [ -        [1, 1, 1, 1, 1, 1, 0, 0, 1, 1], -        [0, 1, 0, 1, 1, 1, 1, 0, 1, 0], -        [1, 0, 1, 1, 0, 1, 0, 1, 0, 1], -    ] -    p = [ -        [-8, 6, -2, -8, -8, 4, 8, 7, -6, 2, 2], -        [-9, 2, 0, 1, 7, -5, 0, -2, -6, 5, 5], -        [6, -6, 7, -9, 6, -5, 8, 0, -9, -7, -7], -    ] -sumpmax = -(10**11) -for i in itertools.product([0, 1], repeat=10): -    r = list(i) -    sump = 0 -    if sum(r) != 0: -        for jj in range(n): -            ci = 0 -            for j in range(10): -                ci = ci + r[j] * f[jj][j] -            sump = sump + p[jj][ci] -        #            print(sump,r) -        sumpmax = max(sump, sumpmax) -print(sumpmax) +n = int(eval(input())) +f = [[]] * n +for i in range(n): +    fij = list(map(int, input().split())) +    #    f[i].append(fij) +    f[i] = fij +p = [[]] * n +for i in range(n): +    pij = list(map(int, input().split())) +    p[i] = pij +pmax = -(10**11) +for a in itertools.product([0, 1], repeat=10): +    if sum(a) == 0: +        continue +    psum = 0 +    for ni in range(n): +        k = 0 +        for i in range(10): +            if f[ni][i] == 1 and a[i] == 1: +                k += 1 +        psum = psum + p[ni][k] +    pmax = max(pmax, psum) +print(pmax)