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

c = [[P[i][j] for j in range(sum(f_)+1)][1:] for i, f_ in enumerate(F)]
maxv = max(-1000000, max(c[0]))

for p_ in c[1:]:
    tmp = max(p_)
    if tmp < 0 and maxv >= tmp:
        maxv = tmp
    else:
        maxv += tmp
print(maxv)
