n=int(eval(input()))

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

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

A=[]

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

    ans=0

    X=format(i,'b').zfill(10)

    for j in range(n):

        cnt=0

        for k in range(10):

            if S[j][k]=='1' and X[k]=='1':

                cnt+=1

        ans+=C[j][cnt]

    A.append(ans)

print((max(A)))   
n=int(eval(input()))

S=[int(input().replace(' ',''),2) for _ in range(n)]

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

A=[]

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

    ans=0

    for j in range(n):

        cnt=bin(S[j]&i).count('1')

        ans+=C[j][cnt]

    A.append(ans)

print((max(A)))       
n = int(eval(input()))
S = [list(map(str, input().split())) for _ in range(n)]
C = [list(map(int, input().split())) for _ in range(n)]
A = []
for i in range(1, 2**10):
    ans = 0
    X = format(i, "b").zfill(10)
    for j in range(n):
        cnt = 0
        for k in range(10):
            if S[j][k] == "1" and X[k] == "1":
                cnt += 1
        ans += C[j][cnt]
    A.append(ans)
print((max(A)))

n = int(eval(input()))
S = [int(input().replace(" ", ""), 2) for _ in range(n)]
C = [list(map(int, input().split())) for _ in range(n)]
A = []
for i in range(1, 2**10):
    ans = 0
    for j in range(n):
        cnt = bin(S[j] & i).count("1")
        ans += C[j][cnt]
    A.append(ans)
print((max(A)))

-S = [list(map(str, input().split())) for _ in range(n)] +S = [int(input().replace(" ", ""), 2) for _ in range(n)] -    X = format(i, "b").zfill(10) -        cnt = 0 -        for k in range(10): -            if S[j][k] == "1" and X[k] == "1": -                cnt += 1 +        cnt = bin(S[j] & i).count("1")