n = int(eval(input()))

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

x = 0

M = a[0]

if n != 1:

    for i in range(n - 1):

        if M > a[i + 1]:

            x += (M - a[i + 1])

        else:

            M = a[i + 1]

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

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

x = 0

h = a[0]

for i in range(n):

    if a[i] > h:

        h = a[i]

    else:

        x += (h - a[i])

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

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

-M = a[0] -if n != 1: -    for i in range(n - 1): -        if M > a[i + 1]: -            x += M - a[i + 1] -        else: -            M = a[i + 1] +h = a[0] +for i in range(n): +    if a[i] > h: +        h = a[i] +    else: +        x += h - a[i]