n = int(eval(input()))

total = 0

h = list(map(int, input().split(" ")))

for i in range(1, n):

    if h[i] < h[i - 1]:

        total += abs(h[i] - h[i-1])

        h[i] = h[i - 1]



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

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

answer = 0

for i in range(1,n):

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

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

        a[i]= a[i - 1]



print(answer)
n = int(eval(input()))
total = 0
h = list(map(int, input().split(" ")))
for i in range(1, n):
    if h[i] < h[i - 1]:
        total += abs(h[i] - h[i - 1])
        h[i] = h[i - 1]
print(total)

n = int(eval(input()))
a = list(map(int, input().split(" ")))
answer = 0
for i in range(1, n):
    if a[i] < a[i - 1]:
        answer += a[i - 1] - a[i]
        a[i] = a[i - 1]
print(answer)

-total = 0 -h = list(map(int, input().split(" "))) +a = list(map(int, input().split(" "))) +answer = 0 -    if h[i] < h[i - 1]: -        total += abs(h[i] - h[i - 1]) -        h[i] = h[i - 1] -print(total) +    if a[i] < a[i - 1]: +        answer += a[i - 1] - a[i] +        a[i] = a[i - 1] +print(answer)