N=int(eval(input()))

H=['']*N

W=['']*N

x=[]

for i in range(N):

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

for j in range(N):

    W[j]=list(map(int,input().split()))

for k in range(1,1024):

    t=[]

    for ii in range(10):

        if k&(1<<ii):

            t+=[1]

        else:

            t+=[0]

    ans=0

    for jj in range(N):

        s=0

        for kk in range(10):

            s+=H[jj][kk]*t[kk]

        ans+=W[jj][s]

    x.append(ans)

print((max(x)))    
N=int(eval(input()))

ans=-10**9

s=["".join(list(input().split())) for i in range(N)]

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

for j in range(1,1024):

    q=0

    for i in range(len(s)):

        q+=t[i][(bin(int(s[i],2)&j)).count("1")]

    ans=max(ans,q)

print(ans)

N = int(eval(input()))
H = [""] * N
W = [""] * N
x = []
for i in range(N):
    H[i] = list(map(int, input().split()))
for j in range(N):
    W[j] = list(map(int, input().split()))
for k in range(1, 1024):
    t = []
    for ii in range(10):
        if k & (1 << ii):
            t += [1]
        else:
            t += [0]
    ans = 0
    for jj in range(N):
        s = 0
        for kk in range(10):
            s += H[jj][kk] * t[kk]
        ans += W[jj][s]
    x.append(ans)
print((max(x)))

N = int(eval(input()))
ans = -(10**9)
s = ["".join(list(input().split())) for i in range(N)]
t = [list(map(int, input().split())) for i in range(N)]
for j in range(1, 1024):
    q = 0
    for i in range(len(s)):
        q += t[i][(bin(int(s[i], 2) & j)).count("1")]
    ans = max(ans, q)
print(ans)

-H = [""] * N -W = [""] * N -x = [] -for i in range(N): -    H[i] = list(map(int, input().split())) -for j in range(N): -    W[j] = list(map(int, input().split())) -for k in range(1, 1024): -    t = [] -    for ii in range(10): -        if k & (1 << ii): -            t += [1] -        else: -            t += [0] -    ans = 0 -    for jj in range(N): -        s = 0 -        for kk in range(10): -            s += H[jj][kk] * t[kk] -        ans += W[jj][s] -    x.append(ans) -print((max(x))) +ans = -(10**9) +s = ["".join(list(input().split())) for i in range(N)] +t = [list(map(int, input().split())) for i in range(N)] +for j in range(1, 1024): +    q = 0 +    for i in range(len(s)): +        q += t[i][(bin(int(s[i], 2) & j)).count("1")] +    ans = max(ans, q) +print(ans)