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

A=0
FL=1
mx=-10**7-1
mp=(-1,-1)
for i in range(N):
    s=sum(F[i])
    a=P[i][0]
    for j in range(1,s+1):
        if a<=P[i][j]:
            a=P[i][j]
            FL=0
        if mx<=P[i][j]:
            mp=(P[i][0],P[i][j])
    A+=a

if FL:
    A=sum([i[0] for i in P])-mp[0]+mp[1]

print(A)