n = int(eval(input()))

A = [*list(map(int, input().split()))]

s = maxA = 0

for a in A:

    maxA = max(maxA, a)

    s += maxA - a

print(s)

_ = int(eval(input()))

s = h = 0

for a in map(int, input().split()):

    h = max(h, a)

    s += h - a

print(s)

n = int(eval(input()))
A = [*list(map(int, input().split()))]
s = maxA = 0
for a in A:
    maxA = max(maxA, a)
    s += maxA - a
print(s)

_ = int(eval(input()))
s = h = 0
for a in map(int, input().split()):
    h = max(h, a)
    s += h - a
print(s)

-n = int(eval(input())) -A = [*list(map(int, input().split()))] -s = maxA = 0 -for a in A: -    maxA = max(maxA, a) -    s += maxA - a +_ = int(eval(input())) +s = h = 0 +for a in map(int, input().split()): +    h = max(h, a) +    s += h - a