N=int(input())

F=[]
for i in range(N):
    f=list(map(int, input().split()))
    F.append(f)

P=[]
for i in range(N):
    p=list(map(int, input().split()))
    P.append(p)

C=[0]*N
for i in range(10):
    for j in range(N):
        if F[j][i]==1:
            C[j]+=1

t=0
T=[-(10**7)]*N
for i in range(N):
    for j in range(C[i]+1):
        if P[i][C[i]-j] > T[i]:
            T[i] = P[i][C[i]-j]
            if j==C[i]:
                t+=1

S=[]
if t==N:
    for i in range(N):
        S.append(P[i][1])
    T.append(max(S))

print(sum(T))
