n = int(eval(input()))

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



res = a[0]

ans = 0

for i in range(1, n):

  if res>=a[i]:

    ans += res-a[i]

  else:

    res = a[i]

    

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

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





res = a[0]

ans = 0

for i in range(1, n):

  if res-a[i]>=0:

    ans += res-a[i]

  else:

    res = a[i]

    

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

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

-    if res >= a[i]: +    if res - a[i] >= 0: