N persons are standing in a row. The height of the i-th person from the front is A_i.  We want to have each person stand on a stool of some heights - at least zero - so that the following condition is satisfied for every person:  Condition: Nobody in front of the person is taller than the person. Here, the height of a person includes the stool.  Find the minimum total height of the stools needed to meet this goal.
n = int(input())
arr = list(map(int,input().split()))
ans = 0
for i in range(1,n):
    if arr[i]<arr[i-1]:
        arr[i] += arr[i-1]-arr[i]
        ans += arr[i-1]-arr[i]
print(ans)
        
n = int(input())
arr = list(map(int,input().split()))
ans = 0
for i in range(1,n):

    if arr[i]<arr[i-1]:
        ans += arr[i-1]-arr[i]
        arr[i] += arr[i-1]-arr[i]
    
print(ans)
        