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 += abs(A[i-1]-A[i])

        A[i] = A[i-1]

    else:

        continue

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()))
ans = 0
for i in range(1, N):
    if A[i - 1] > A[i]:
        ans += abs(A[i - 1] - A[i])
        A[i] = A[i - 1]
    else:
        continue
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)

-        ans += abs(A[i - 1] - A[i]) +        ans += A[i - 1] - A[i] -    else: -        continue