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, m = 0, 0, 0
r = -float("INF")
for i in range(N):
    tmp = max(P[i][:sum(F[i])+1])
    idx += P[i][:sum(F[i])+1].index(tmp)
    ans += tmp

    if r < P[i][0] - max(P[i][1:sum(F[i])+1]):
        r = P[i][0] - max(P[i][1:sum(F[i])+1])

if idx == 0:
    ans -= r

print(ans)