N=int(input())
L=[0]*N;P=[0]*N;ans=0
for i in range(N):
    a=list(map(int,input().split()))
    for m in range(10):
        L[i]+=a[m]
for k in range(N):
    P[k]=list(map(int,input().split()))
for l in range(N):
    ans+=max(P[l][0:L[l]+1])
print(ans)