N = int(input())

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

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

price = []
for i in range(N):
    time = sum(F[i])
    price.append(max(P[i][1:time+1]))

print(sum(price))