Problem:
 Score : 300 points    Problem Statement 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.      Constraints  1 \leq N \leq 2\times 10^5  1 \leq A_i \leq 10^9  All values in input are integers.         Input Input is given from Standard Input in the following format:  N  A_1  \ldots  A_N       Output Print the minimum total height of the stools needed to meet the goal.        Sample Input 1 5
2 1 5 4 3      Sample Output 1 4  If the persons stand on stools of heights 0 , 1 , 0 , 1 , and 2 , respectively, their heights will be 2 , 2 , 5 , 5 , and 5 , satisfying the condition.  We cannot meet the goal with a smaller total height of the stools.       Sample Input 2 5
3 3 3 3 3      Sample Output 2 0  Giving a stool of height 0 to everyone will work.

Solution (Python):
import sys
import numpy as np
from math import ceil as C, floor as F, sqrt
from collections import defaultdict as D, Counter as CNT
from functools import reduce as R
import heapq as HQ

class Heap:
  def __init__(self, data, reverse=False):
    self.reverse = -1 if reverse else 1
    self.data = [self.reverse * d for d in data]
    HQ.heapify(self.data)
  def push(self, x): return HQ.heappush(self.data, self.reverse * x)
  def pop(self): return self.reverse * HQ.heappop(self.data)

ALP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
alp = 'abcdefghijklmnopqrstuvwxyz'
def _X(): return sys.stdin.readline().rstrip().split(' ')
def _S(ss): return tuple(ss) if len(ss) > 1 else ss[0]
def S(): return _S(_X())
def Ss(): return list(S())
def _I(ss): return tuple([int(s) for s in ss]) if isinstance(ss, tuple) else int(ss)
def I(): return _I(S())
def _Is(ss): return list(ss) if isinstance(ss, tuple) else [ss]
def Is(): return _Is(I())

n = I()
xs = Is()

ans = 0
now = xs[0]
for x in xs[1:]:
    if x < now:
        ans += (now - x)
    now = max(x, now)

print(ans)

Solution (Python):
n = int(input())
l = list(map(int,input().split()))
ans = 0

m = l[0]
for i in l:
    if m <=i:
        m = i
    else:
        ans +=m-i
print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

result = 0
tmp = a[0]

for i in range(1, n): 
  if tmp >= a[i]: 
    result += tmp - a[i]
  else: 
    tmp = a[i]

print(result)

Solution (Python):
n = int(input())
arr = [int(x) for x in input().split()]

acm = 0
for i in range(1,n):
    acm += max(-arr[i]+arr[i-1],0)
    arr[i] = max(arr[i],arr[i-1])
    
print(acm)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

step = 0
highest = 0
for a in A:
  if a >= highest:
    highest = a
  else:
    step += highest-a
    
print(step)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
B = [0] * N 
ans = 0
h = 0
for i in range(1,N):
    if A[i] < A[i-1]+B[i-1]:
        h = B[i-1]+A[i-1] - A[i]
    else:
        h = 0
    B[i] = h

for i in range(N):
    ans += B[i]


print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

tmp = a[0]
ans = 0
for i in a:
    if i < tmp:
        ans += tmp-i
    else:
        tmp = i
print(ans)

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
smallest = A[0]
ans = 0
for x in range(len(A)-1):
	if A[x] > A[x+1]:
		ans += A[x] - A[x+1] 
		A[x+1] = A[x]

print(ans)

Solution (Python):
n = int(input())
lis = list(map(int,input().split()))
sum = 0
for i in range(n-1):
  if int(lis[i])>int(lis[i+1]):
    sum += lis[i]-lis[i+1]
    lis[i+1] = lis[i]
  else:
    continue
print(sum)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
ans = 0

m = A[0]
for a in A:
    if m <= a: m = a
    else: ans += m-a

print(ans)

Solution (Python):
N = int(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]
print(ans)

Solution (Python):
N = int(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]
print(ans)

Solution (Python):


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter  
from itertools import combinations as comb  
from itertools import permutations as permutate
from bisect import bisect_left as bl



from bisect import bisect_right as br
from bisect import bisect







BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None


    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)





from types import GeneratorType


def iterative(f, stack=[]):
    def wrapped_func(*args, **kwargs):
        if stack: return f(*args, **kwargs)
        to = f(*args, **kwargs)
        while True:
            if type(to) is GeneratorType:
                stack.append(to)
                to = next(to)
                continue
            stack.pop()
            if not stack: break
            to = stack[-1].send(to)
        return to

    return wrapped_func







mod = 1000000007


def inp(): return sys.stdin.readline().rstrip("\r\n")  

def out(var): sys.stdout.write(str(var))  

def lis(): return list(map(int, inp().split()))

def stringlis(): return list(map(str, inp().split()))

def sep(): return map(int, inp().split())

def strsep(): return map(str, inp().split())


def zerolist(n): return [0] * n

def nextline(): out("\n")  

def testcase(t):
    for p in range(t):
        solve()

def printlist(a):
    for p in range(0, len(a)):
        out(str(a[p]) + ' ')


def solve():
    m=0
    n=int(inp())
    ar=lis()
    ans=0
    for i in range(n):
        if ar[i]<m:
            ans+=(m-ar[i])
        else:
            m=ar[i]
    print(ans)

    
    
    
solve()

Solution (Python):
n = int(input())
A = list(map(int,input().split()))

ans = []
maxim = A[0]
for i in range(1,n):
    if A[i] < maxim:
        ans.append(maxim-A[i])
    else:
        ans.append(0)
        maxim = A[i]
print(sum(ans))

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
s = a[0]
ans = 0
for i in range(1,n):
  ans += max(0,s-a[i])
  s = max(s,a[i])
print(ans)

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]
takasa=0

for i in range(n-1):
    if a[i]>a[i+1]:
        takasa+=a[i]-a[i+1]
        a[i+1]+=a[i]-a[i+1]
print(takasa)

Solution (Python):
n = int(input())
a = [int(x) for x in input().split(" ")]
s = [0]

for x in range(1, n):
    stool = max(a[x - 1] - a[x], 0)
    s.append(stool)
    a[x] += stool
    
print(sum(s))

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
step = 0
for i in range(N - 1):
  step += max(0, A[i] - A[i + 1])
  A[i + 1] += max(0, A[i] - A[i + 1])
print(step)

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]
takasa=0
for i in range(n-1):
    if a[i]>a[i+1]:
        takasa+=a[i]-a[i+1]
        a[i+1]+=a[i]-a[i+1]
print(takasa)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

ans = 0
for i in range(n-1):
    if a[i] > a[i+1]:
        ans += a[i] - a[i+1]
        a[i+1] = a[i]

print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
h=0
ans=0
for i in range(n):
  h=max(h,a[i])
  ans+=h-a[i]
print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
ans = 0
for i in range(n-1):
  s = a[i+1] -a[i] 
  if s < 0:
      ans = ans - s
      a[i+1]=a[i]
print(ans)

Solution (Python):
N = input()
A = list(map(int, input().split()))

s = 0

for i in range(len(A)-1):
  if A[i] > A[i+1]:
    s = s + A[i] - A[i+1]
    A[i+1] = A[i]

print(s)

Solution (Python):
input()
A = list(map(int, input().split()))

sum = 0

for i in range(1, len(A)):
  if A[i] < A[i-1]:
    sum += A[i-1] - A[i]
    A[i] = A[i-1]
    
print(sum)

Solution (Python):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = 0
    h = A[0]
    for i in range(1, N):
        ans += max(0, h - A[i])
        h = max(h, A[i])
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

s = 0


for i in range(1, n):
    if a[i-1] > a[i]:
        s += a[i-1] - a[i]
        a[i] = a[i-1]

print(s)

Solution (Python):
def main():
  N=input()
  arr=list(map(int,input().split()))
  sum=0
  for i in range(1,int(N)):
    if arr[i] < arr[i-1]:
      sum+= (arr[i-1]-arr[i])
      arr[i]=arr[i-1]
  print(sum)

if __name__ == '__main__':
  main()

Solution (Python):
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    A = list(map(int, input().split()))
    CNT = 0
    for i in range(1,N):
        if A[i] <= A[i-1]:
            CNT += A[i-1] - A[i]
            A[i] += A[i-1] - A[i]
    print(CNT)
        

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))


sum_value = 0
for i in range(len(A)-1):
  if A[i] >= A[i+1]:
    x =  A[i] - A[i+1]
    A[i+1] = x + A[i+1]
    sum_value += x

print(sum_value)

Solution (Python):

N = int(input())
A = list(map(int,input().split()))
ans = 0
maxi = 0
for i in A:
    ans += max(0,maxi-i)
    maxi = max(maxi,i)
print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

ans = 0
maxi = 0
for i in range(n):
    if a[i] < maxi:
        ans += (maxi - a[i])
        a[i] = maxi
    maxi = max(maxi, a[i])


print(ans)

Solution (Python):
 
def main():
    N = int(input())
    A = list(map(int,input().split()))

    ans=0
    maximum=0
    
    for a in A:
        ans += max(0,maximum-a)
        maximum=max(maximum,a)

    print(ans)
        
if __name__ == '__main__':
    main()

Solution (Python):
import sys


def resolve(in_):
    N = int(next(in_))
    A = tuple(map(int, next(in_).split()))

    stool = 0
    height = A[0]
    for h in A[1:]:
        if height <= h:
            height = h
        else:
            stool += height - h

    return stool

def main():
    answer = resolve(sys.stdin)
    print(answer)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
l = list(map(int,input().split()))
p=l[0]
s=0
for i in l[1:]:
    s+= max(0,p-i)
    p=max(p,i)
print(s)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
count=0
for num in range(N-1):
    if A[num]>A[num+1]:
        count=count+A[num]-A[num+1]
        A[num+1]=A[num]
    else:
        continue        
print(count)

Solution (Python):
number = int(input())
tall = list(map(int, input().split()))
addition = 0
for each in range(1, number):
    difference = tall[each - 1] - tall[each]
    if difference >= 0:
        addition += difference
        tall[each] += difference
print(addition)

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]
max_height=0
ans=0
for i in a:
  if max_height>i:
    ans+=max_height-i
  else:
    max_height=i
    
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
fumidai = 0
previous = 0
for i in range(N):
    if previous > A[i]:
        fumidai += previous - A[i]
    else:
        previous = A[i]
        continue
print(fumidai)

Solution (Python):
n = int(input())

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

ans = 0
for idx in range(1, n):
    if nums[idx] - nums[idx-1] < 0:
        ans += abs(nums[idx] - nums[idx-1])
        nums[idx] = nums[idx-1]

print(ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
c = 0
for i in range(n-1):

    if a[i] > a[i+1]:
        c += a[i]-a[i+1]
        a[i+1] = a[i]

print(c)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

sum = 0
mx = 0
for i in range(1, n):
  mx = max(a[i-1], mx)
  sum+=max(mx -a[i], 0)
  
print(sum)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
fumidai_list, A_after = [], 0

for count_a in range(len(A)):
    fumidai = 0

    if(A[count_a] >= A_after):
        A_after = A[count_a]
        fumidai_list.append(fumidai)

    elif(A[count_a] < A_after):
        fumidai = A_after - A[count_a]
        fumidai_list.append(fumidai)

print(sum(fumidai_list))

Solution (Python):

n=int(input())
l=list(map(int,input().split()))

x = 0
for a in range(n-1):
    if l[a]>l[a+1] :
        x=l[a] - l[a+1] + x
        l[a+1]=l[a]
    
print(x)

Solution (Python):
N = int(input())
nums = list(map(int,input().split()))

count = 0
current_max = nums[0]
for i in range(len(nums)-1):
    nv = nums[i+1]
    if nv > current_max:
        current_max = nv
    else:
        count += (current_max - nv)

print(count)

Solution (Python):
n = int(input())
arr = list(map(int,input().split()))
last,ans = 0,0
for c in arr:
    if c < last:
        ans += (last-c)
    else:
        last = c
print(ans)

Solution (Python):
class height():

    def __init__(self):
        self.human = 0
        self.step = 0

    def Sum(self):
        return self.human + self.step
N = int(input())
A = [height() for i in range(N)]

s = str(input()).split()

for i,v in enumerate(s):
    A[i].human = int(v)
    

sum, tmp = 0,0
for i in range(len(A)-1):
    if A[i+1].human >= A[i].Sum():
        continue
    tmp = A[i].Sum() - A[i+1].human
    A[i+1].step = tmp
    sum += tmp

print(sum)

Solution (Python):
N = int(input())
height = [int(i) for i in input().split()]
step = 0
for i, h in enumerate(height):
    if i == 0:
        pre = h
    else:
        if h < pre:
            step += (pre - h)
            pre = pre
        else:
            step += 0
            pre = h
print(step)

Solution (Python):

n = int(input())
l = list(map(int,input().split()))
height_stool = 0

temp = [i for i in l]
for i in range(n-1):
    if l[i] > l[i+1]:
        diff = l[i]-l[i+1]
        height_stool += diff
        l[i+1] += diff
print(height_stool)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))



F=0
for i in range(1,N):
    if A[i]<A[i-1]:
        F+=A[i-1]-A[i]
        A[i]+=A[i-1]-A[i]
print(F)

Solution (Python):
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    ma = A[0]
    ans = 0
    for a in A:
        ma = max(ma, a)
        ans += ma - a
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
ans = 0
high = 0
for i in range (1,N):
    if  A[i-1] > high:
        high = A[i-1]
    if high > A[i]:
        ans += high - A[i]
print (ans)

Solution (Python):
n=int(input())

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

ans=0
max=a[0]
for i in range(1,n):
    if max>a[i]:
        ans+=max-a[i]
    else:
        max=a[i]

print(ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))

max_num = a[0]
ans = 0
for i in range(1,n):
    max_num = max(max_num, a[i])
    if max_num != a[i]:
        ans += (max_num - a[i])
print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
ans=0
step=0
for i in range(n-1):
  if a[i]+step<=a[i+1]:
    step=0
  else:
    ans+=a[i]+step-a[i+1]
    step=a[i]+step-a[i+1]
print(ans)

Solution (Python):
N=int(input())
array=[int(x) for x in input().split()]
diff=0
for i in range(1,N):
	if array[i]<array[i-1]:
		diff+=array[i-1]-array[i]
		array[i]+=array[i-1]-array[i]
print(diff)

Solution (Python):
n,*l=map(int,open(0).read().split())
a=t=0
for i in l:
  if i>t: t=i
  a+=t-i
print(a)

Solution (Python):
n,*l=map(int,open(0).read().split())
a=t=0
for i in l:
  if i>t: t=i
  else: a+=t-i
print(a)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
count = 0
i_max = 0
for i in a:
    if i_max > i:
        count += i_max - i
    i_max = max(i_max,i)
print(count)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

ans = 0
cur_max=0

for x in a:
  if cur_max > x:
    ans += cur_max - x
  cur_max = max(cur_max, x)
print(ans)

Solution (Python):
n = int(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)

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
total = 0

min_ = A[0]

for i in range(n):
    if A[i] > min_:
        min_ = A[i]
    else:
        total += (min_ - A[i])
print(total)

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]

c = 0
p = 0
for a in A:
  if p < a:
    p = a
  else:
    c += p - a
    p = max(p, a)
print(c)

Solution (Python):
n = int(input())
a = list(map(int, input().strip().split()))
ans = 0
for i in range(1, n):
    if(a[i-1] > a[i]):
        ans += abs(a[i-1]-a[i])
        a[i] += abs(a[i-1]-a[i])
print(ans)

Solution (Python):
n = int(input())
l = list(map(int,input().split()))
max_height = 0
res = 0
for i in l:
    if i >= max_height:
        max_height = i
    else:
        res += (max_height-i)
print(res)

Solution (Python):
N = int(input())

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

Solution (Python):
n=int(input())
a=[0]*n
a=list(map(int,input().split()))
ans=0
big=0
big=a[0]
for i in range(1,n):
  big=max(big,a[i])
  ans+=big-a[i]
  
  
print(ans)

Solution (Python):
n = int(input())
a_int = list(map(int, input().split()))

height = 0
base = 0
for j in range(0, n - 1):
    if a_int[j] + base > a_int[j + 1] + base:
        base = a_int[j] - a_int[j + 1]
        height += base
        a_int[j + 1] += base
        base = 0
print(height)

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
s = 0
for i in range(1,N):
    if a[i-1] > a[i]:
        s += (a[i-1]-a[i])
        a[i] = a[i-1]
print(s)

Solution (Python):
n=int(input())
alist=list(map(int,input().split()))
height=alist[0]
ans=0

for i in range(1,n):
    if height>alist[i]:
        ans+=height-alist[i]
    
    else:
        height=alist[i]

print(ans)

Solution (Python):
def solve(n,arr):
    maxh = 0
    h = 0
    for i in range(1,n):
        curr = arr[i]
        curh = arr[i-1]
        f = max(curr,curh)
        maxh = max(f,maxh)

        if curr < maxh:
            h += maxh - curr

        
        

    return h
        



n = int(input())
arr = list(map(int, input().strip().split()))

print(solve(n,arr))

Solution (Python):
n=int(input())
heights=list(map(int, input().split()))

std=heights.pop(0)
ans=0
if n==1:
  ans=0
else:
  for height in heights:
    if std>height:
      ans+=std-height
    else:
      std=height
print(ans)

Solution (Python):
from typing import List

def step(n: int, a: List[int])-> int:
  result = 0
  dai = 0
  for i in range(1,n):
    sub = a[i-1] + dai - a[i]
    if sub > 0:
      dai = sub      
      result += sub
      continue
    dai = 0
  return result

if __name__ == "__main__":
  n = int(input())
  a = list(map(int, input().split()))
  print(step(n, a))

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

ans = 0

for i in range(N-1):
    if A[i] < A[i+1]:
        pass
    else:
        ans = ans + (A[i] - A[i+1])
        A[i+1] = A[i+1] + (A[i] - A[i+1])

print(ans)

Solution (Python):
n = input()
a = list(map(int, input().split()))
min = a[0]
ans = 0            
for i in a:
	if min > i:
		ans += min - i
	else:
		min = i

print(ans)

Solution (Python):
n = input()
a = list(map(int, input().split()))
max = 0
step = 0            
for i in a:
	if max > i:
		step += max - i
	else:
		max = i

print(step)

Solution (Python):
n=int(input())

A = list(map(int, input().split()))
l = [0] * len(A)

ans=0
m=A[0]

for i in A:
  if m>i:
    ans = ans +(m-i)
  
  else:
    m=i
  
print(ans)

Solution (Python):
n=int(input())

A = list(map(int, input().split()))
l = [0] * len(A)

ans=0

for i in range(n-1):
  if A[i]>=A[i+1]:
    l[i+1]=A[i]-A[i+1]
    A[i+1]=A[i]
  else:
    l[i+1]=0
  ans=ans+l[i+1]  
print(ans)

Solution (Python):
n = input()
list_height = list(map(int, input().split()))
pre = 0
max_chair = 0
list_chair = list()
for i in list_height:
    if i < pre:
        max_chair = pre - i
        pre = i + max_chair
        list_chair.append(max_chair)
    else:
        pre = i
print(sum(list_chair))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
tmp = a[0]
ans = 0
for i in a:
    diff = tmp - i
    if diff > 0:
        ans += diff
        tmp = i + diff
        continue
    tmp = i
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

s = 0
height = 0
for a in A:
    height = max(height, a)
    s += height - a
print(s)

Solution (Python):
n = int(input())
an = [int(num) for num in input().split()]

sum = 0
for i in range(len(an)-1):
  if an[i] > an[i+1]:
    sum += an[i] - an[i+1]
    an[i+1] += an[i] - an[i+1]
    
print(sum)

Solution (Python):
n = int(input())
s = list(map(int, input().split()))

rate = 0
count = 0
for i, v in enumerate(s):
    if i == 0:
        rate = v
        continue

    if rate > v:
        tmp = rate - v
        count += tmp
    else:
        rate = v

print(count)

Solution (Python):
import sys
import math

lines = sys.stdin.readlines()

n = int(lines[0].rstrip())
heights = [int(x) for x in lines[1].rstrip().split()]

tot = 0
for i in range(n-1):
    if heights[i] <= heights[i+1]:
        continue
    else:
        diff = heights[i] - heights[i+1]
        heights[i+1] += diff
        tot += diff

print(tot)

Solution (Python):
n = int(input())
num_list = [int(i) for i in input().split()]
count = 0

for i in range(1,n):
    if num_list[i] < num_list[i-1]:
        count += (num_list[i-1] - num_list[i])
        num_list[i] = num_list[i-1]

print(count)

Solution (Python):
num = input()
list = input().split()

ans = 0

for i in range(int(num) - 1):
    n1 = int(list[i])
    n2 = int(list[i+1])

    if  n1 > n2 :
        ans += (n1 - n2)
        list[i+1] = list[i]
    else:
        ans += 0

print(ans)

Solution (Python):
N = int(input())
A_ = input().split()
A = [int(i) for i in A_]

S = 0
a = A[0]
for i in range(len(A)-1):
    if a > A[i+1]:
        S += a-A[i+1]
    else:
        a = A[i+1]
print(S)

Solution (Python):
n = input()
a = list(map(int, input().split()))
maxi = 0
ans = 0
for i in range(len(a)):
  maxi = max(a[i],maxi)
  ans += maxi - a[i]
print(ans)

Solution (Python):
N=int(input())
x=list(map(int,input().split()))
sum=0
for i in range(1,N):
    if x[i]<x[i-1]:
        t=x[i-1]-x[i]
        sum+=t
        x[i]=x[i-1]
print(sum)

Solution (Python):
n,*a=map(int,open(0).read().split())
s=a[0]
ans=0
for i in range(1,n):
  if s>a[i]:
    ans+=s-a[i]
  else:
    s=a[i]
print(ans)

Solution (Python):
num = int(input())
arr = map(int, input().split())
tmp = 0
ans = 0
for item in arr:
    if item < tmp:
        ans += tmp - item
    else:
        tmp = item
print(ans)

Solution (Python):
n = int(input())
arr = list(map(int,input().strip().split(" ")))

ans = 0
mx = arr[0]

for i in range(1,n):
    if arr[i]<mx:
        ans += mx-arr[i]
    mx = max(mx, arr[i])

print(ans)

Solution (Python):
N=int(input())
s=[int(x) for x in input().split()]

ans=0
for i in range(N-1):
    if s[i]>s[i+1]:
        ans+=(s[i]-s[i+1])
        s[i+1]=s[i+1]+(s[i]-s[i+1])
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(1, N):
    if A[i] <= A[i-1]:
        ans += A[i-1] - A[i]
        A[i] = A[i-1]
print(ans)

Solution (Python):
n = int(input())
A = list(map(int, input().split()))

M = A[0]
sum = 0
for i in range(n):
    M = max(M, A[i])
    sum += M - A[i]

print(sum)

Solution (Python):
int_n = int(input())
list_a = list(map(int, input().split()))



int_tmp_highet = 0
int_count = 0
for i in list_a:
  if i > int_tmp_highet:
    int_tmp_highet = i
  else:
    int_count = int_count + int_tmp_highet - i
  

print(int_count)

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

Solution (Python):
n = int(input())
a = list(map(int,input().split()))


m = a[0]
f = 0
for i in a[1:]:
    if i < m:
        f += m-i
    else:
        m = i

print(f)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

max = A[0]
cnt = 0

for i in range(N):
  if A[i]>max:
    max = A[i]
  elif A[i] == max:
    continue
  else:
    cnt += max - A[i]

print(cnt)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
s = 0
m = a[0]
for i in range(1, n):
    if a[i] < m:
        s += m- a[i]
    else:
        m = a[i]
print(s)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

tmp = a[0]
ans = 0
for i in a:
    if i < tmp:
        ans += tmp-i
    else:
        tmp = i
print(ans)

Solution (Python):

N=int(input())
A=list(map(int,input().split()))
ans=0
MAX=A[0]
for i in range(1,N):
    if MAX<=A[i]:
        MAX=A[i]
    else:
        ans+=MAX-A[i]

print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

mx = a[0]
ans = 0
for x in a:
  if x > mx:
    mx = x
  ans += mx
print(ans-sum(a))

Solution (Python):
n = input()
a_ar = list(map(int, input().split()))
total = 0
for i in range(len(a_ar) - 1):
    if a_ar[i] > a_ar[i+1]:
        total += a_ar[i] - a_ar[i+1]
        a_ar[i+1] = a_ar[i]
print(total)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

check = A[0]
ans = 0

for i in range(N):
    if check < A[i]:
        check = A[i]
    elif check > A[i]:
        ans += check - A[i]

print(ans)

Solution (Python):
n = int(input())

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

before_max = 0

dai = 0

for i in range(len(data)):
    if(i == 0):
        before_max = data[i]
    else:
        
        if(before_max < data[i]):
            before_max = data[i]
            continue
        
        elif(before_max > data[i]):
            dai += before_max - data[i]

print(dai)

Solution (Python):
num = int(input())
line = list(map(int,input().split()))

mini = line[0]
x = 0
for i in range(1,num):
  if mini > line[i]:
    x += mini - line[i]
  else:
    mini = line[i]
print(x)

Solution (Python):
N = int(input())
ARR = list(map(int, input().split()))

sum_of_Humidai = 0
for i in range(1, len(ARR)):
    diff = (ARR[i - 1] - ARR[i])
    if diff > 0:
        ARR[i] += diff
        sum_of_Humidai += diff
else:
    print(sum_of_Humidai)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
sum = 0
for i in range (N):
    if(i != 0)&(A[i - 1] > A[i]):
        sum += A[i - 1] - A[i]
        A[i] = A[i - 1]
print(sum)

Solution (Python):
n=int(input())
a = list(map(int,input().split()))
b = a[0]
total=0
for i in a:
  if i<b:
    total+=b-i
  else:
    b=i
print(total)

Solution (Python):
n = int(input())
a = map(int, input().split())
m=0
cut=0
for i in a:
    if m<i:
        m=i
    elif m>=i:
        cut+=m-i
print(cut)

Solution (Python):
n =int(input())
a = list(map(int,input().split()))
ans = 0
for m in range(n-1):
    if a[m] > a[m+1]:
        ans = ans + a[m] - a[m+1]
        a[m+1] = a[m]
print(ans)

Solution (Python):
n=int(input())
nowh,stand=0,0
a=list(map(int,input().split()))


for i in range(n):
    if nowh<a[i]:
        nowh=a[i]
    else:
        stand+=nowh-a[i]
        
print(stand)

Solution (Python):
n = input()
x = input().split()
m = 0
cnt = 0
 
for i in x:
    ii = int(i)
    if m < ii:
        m = ii
    elif m > ii:
        cnt += m - ii
 
print(cnt)

Solution (Python):
n = input()
x = input().split()
m = 0
cnt = 0

for i in x:
    ii = int(i)
    if m < ii:
        m = ii
    elif m > ii:
        cnt += m - ii

print(cnt)

Solution (Python):
a = input()
b = input().split()
b = [int(x) for x in b]
X = []
for i in range(len(b) - 1):
    if b[i + 1] <= b[i]:
        X.append(b[i] - b[i + 1])
        b[i + 1] = b[i + 1] + b[i] - b[i + 1]
print(sum(X))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n - 1):
    if a[i] > a[i + 1]:
        step = a[i] - a[i + 1]
        a[i + 1] += step
        ans += step
print(ans)

Solution (Python):
n = input()
a = [int(i) for i in input().split()]
m = a[0]
step = 0
for i in a[1:]:
    if i < m:
        step += abs(m - i)
    m = max(m, i)
print(step)

Solution (Python):

N = int(input())
As = list(map(int, input().split()))

humidai = []

humidai.append(0)
for i in range(len(As))[1::]:
    humidai.append(As[i-1]+humidai[i-1]-As[i] if As[i-1]+humidai[i-1]-As[i] > 0 else 0)

print(sum(humidai))

Solution (Python):
 
def main():
    n = int(input())
    aList = list(map(int,input().split()))
    
    cnt = 0
    for i in range(1,n):
        deff = aList[i-1] - aList[i]
        
        if deff > 0:
            cnt += deff
            aList[i] += deff
        
    print(cnt)

if __name__ == "__main__":
    main()

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
t=0
a=0
for i in A:
    if t<=i:
        t=i
    else:
        a+=t-i
print(a)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
m = 0
ans = 0
for i in range(N):
    if m > A[i]:
       ans += m - A[i]
    else:
        m = A[i]
print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
cnt = 0
pre = a[0]
for i in range(n):
  if a[i] <= pre:
    cnt += (pre - a[i])
  else:
    pre = a[i]
print(cnt)