n = int(eval(input()))

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



ans = 0

for i in range(1, n):

    if a[i-1] > a[i]:

        ans += a[i-1] - a[i]

        a[i] = a[i-1]

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

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



tmp = a[0]

ans = 0

for i in a:

    if i < tmp:

        ans += tmp-i

    else:

        tmp = i

print(ans)

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

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

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