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
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
    A+=a

if FL:
    t=-10**7+1
    f=0
    for i in range(len(P)):
        if t<=P[i][0]:
            f=i        
    A=sum([i[0] for i in P])-P[f][0]+P[f][1]

print(A)