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] - A[i]

    

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

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

ans = 0

gap = 0

for i in range(1,N):

  if ( A[i-1] + gap ) > A[i]:

    gap = ( A[i-1] + gap ) - A[i]

  else:

    gap = 0

  ans += gap

    

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] - A[i]
print(ans)

N = int(eval(input()))
A = list(map(int, input().split(" ")))
ans = 0
gap = 0
for i in range(1, N):
    if (A[i - 1] + gap) > A[i]:
        gap = (A[i - 1] + gap) - A[i]
    else:
        gap = 0
    ans += gap
print(ans)

+gap = 0 -    if A[i - 1] > A[i]: -        ans += A[i - 1] - A[i] -        A[i] += A[i - 1] - A[i] +    if (A[i - 1] + gap) > A[i]: +        gap = (A[i - 1] + gap) - A[i] +    else: +        gap = 0 +    ans += gap