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

ans, idx = 0, 0
for i in range(N):
    tmp = max(P[i][:sum(F[i])+1])
    idx += P[i][:sum(F[i])+1].index(tmp)
    ans += tmp
    m = max(P[i][1:sum(F[i])+1])

if idx == 0:
    ans = m

print(ans)