N = int(eval(input()))

li = list(map(int,input().split()))

humi = li[0]

ans = 0

for l in li[1:]:

    if l <= humi:

        ans += humi - l

    else:

        humi = l

print(ans)
N = int(eval(input()))

li = list(map(int,input().split()))

ans = 0

h = li[0]

for l in li[1:]:

    h = max(h,l)

    ans += h-l

print(ans)
N = int(eval(input()))
li = list(map(int, input().split()))
humi = li[0]
ans = 0
for l in li[1:]:
    if l <= humi:
        ans += humi - l
    else:
        humi = l
print(ans)

N = int(eval(input()))
li = list(map(int, input().split()))
ans = 0
h = li[0]
for l in li[1:]:
    h = max(h, l)
    ans += h - l
print(ans)

-humi = li[0] +h = li[0] -    if l <= humi: -        ans += humi - l -    else: -        humi = l +    h = max(h, l) +    ans += h - l