n = int(input())
f = [list(map(int,input().split())) for _ in range(n)]
p = [list(map(int,input().split())) for _ in range(n)]

p0 = []
maxp = []
for i in range(n):
    p0.append(p[i][0])
    sumf = sum(f[i])
    maxp.append(max(p[i][1:(sumf+1)]))

a = []
for i in range(n):
    a.append(sum(maxp))
    a.append(p0[i] + sum(maxp[:i]) + sum(maxp[i+1:]))
print(max(a))