N = int(eval(input()))

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

cnt = 0

for i in range(N-1):

    if A[i+1] < A[i]:

        cnt += A[i]-A[i+1]

        A[i+1] = A[i]

    else:

        pass

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

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

cnt = 0

for i in range(N-1):

    if A[i+1] < A[i]:

        cnt += A[i] - A[i+1]

        A[i+1] = A[i]

print(cnt)
N = int(eval(input()))
A = list(map(int, input().split()))
cnt = 0
for i in range(N - 1):
    if A[i + 1] < A[i]:
        cnt += A[i] - A[i + 1]
        A[i + 1] = A[i]
    else:
        pass
print(cnt)

N = int(eval(input()))
A = list(map(int, input().split()))
cnt = 0
for i in range(N - 1):
    if A[i + 1] < A[i]:
        cnt += A[i] - A[i + 1]
        A[i + 1] = A[i]
print(cnt)

-    else: -        pass