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

sumP=0
zeroshop=0
for i in range(N):
    n=sum(F[i])
    maxP=max(P[i][:n+1])
    if zeroshop==0 and P[i][:n+1].index(maxP)==0 :
        zeroshop=1
        sumP+=max(P[i][1:n+1])
    else:
        sumP+=max(P[i][:n+1])
print(sumP)
