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
nextmax=[]
for i in range(N):
    n=sum(F[i])
    maxP=max(P[i][:n+1])
    nextmax.append(max(P[i][1:n+1]))
    sumP+=maxP
    if P[i][:n+1].index(maxP)!=0:
        zeroshop=1
if zeroshop==0:
    nextn=nextmax.index(max(nextmax))
    sumP=sumP-P[nextn][0]+max(nextmax)
print(sumP)
