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(N):
    for j in range(10):
        if F[i][j]==1:
            C[i]+=1

t=0
T=[]

for i in range(N):
    A=int(max(P[i][0:C[i]+1]))
    T.append(A)
    if A==P[i][0]:
        t+=1


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

print(sum(T))
