n=int(eval(input()))

a=[int(x) for x in input().split()]

b=0

for i in range(1,n):

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

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

    a[i]=a[i-1]

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

a=[int(x) for x in input().split()]

b=a[0]

c=0

for i in range(1,n):

  if a[i]<b:

    c+=b-a[i]

  else:

    b=a[i]

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

n = int(eval(input()))
a = [int(x) for x in input().split()]
b = a[0]
c = 0
for i in range(1, n):
    if a[i] < b:
        c += b - a[i]
    else:
        b = a[i]
print(c)

-b = 0 +b = a[0] +c = 0 -    if a[i - 1] > a[i]: -        b += a[i - 1] - a[i] -        a[i] = a[i - 1] -print(b) +    if a[i] < b: +        c += b - a[i] +    else: +        b = a[i] +print(c)