n = int(eval(input()))

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



base = a[0]

ans = 0

for i in range(1, n):

    base = max(base, a[i])

    ans += base - a[i]

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

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



fllor = a[0]

ans = 0

for i in range(n):

    if fllor > a[i]:

        ans += fllor - a[i]

    else:

        fllor = max(fllor, a[i])

print(ans)
n = int(eval(input()))
a = list(map(int, input().split()))
base = a[0]
ans = 0
for i in range(1, n):
    base = max(base, a[i])
    ans += base - a[i]
print(ans)

n = int(eval(input()))
a = list(map(int, input().split()))
fllor = a[0]
ans = 0
for i in range(n):
    if fllor > a[i]:
        ans += fllor - a[i]
    else:
        fllor = max(fllor, a[i])
print(ans)

-base = a[0] +fllor = a[0] -for i in range(1, n): -    base = max(base, a[i]) -    ans += base - a[i] +for i in range(n): +    if fllor > a[i]: +        ans += fllor - a[i] +    else: +        fllor = max(fllor, a[i])