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 copy
import math
import time
import statistics
import math
import itertools
import bisect
import sys
from decimal import *
from collections import deque


def get_int():
    return int(input())

def get_string():
    return input()

def get_int_list():
    return [int(x) for x in input().split()]

def get_string_list():
    return input().split()

def get_int_multi():
    return map(int, input().split())

def get_string_char_list():
    return list(str(input()))



sys.setrecursionlimit(10 ** 6)

def main():
    start = time.time()

    n = get_int()
    a = get_int_list()

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






    print(ans)

    


if __name__ == '__main__':
    main()

Solution (Python):


n = int(input())
aList = list(map(int, input().split()))
hList = aList.copy()
header = aList[0]
for index, item in enumerate(aList[1:]):
    if header > item:
        hList[index+1] = header
    else:
        header = item
dif = 0
for i in range(n):
    dif += hList[i] - aList[i]
print(dif)

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]:
        h = A[i-1] - A[i]
        A[i] += h
        ans += h

print(ans)

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

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]:
        tmp=a[i-1]-a[i]
        a[i]+=tmp
        ans+=tmp
print(ans)

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

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

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

for l in ll:
  if l < temp:
    ans +=  temp - l
  elif l >= temp:
    temp = l

print(ans)

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

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

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

A.insert(0, 0)
ans = 0
for i in range(1, N+1):
    if A[i-1] > A[i]:
        dai = A[i-1] - A[i]
        ans += dai
        A[i] += dai
print(ans)

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
ssum = 0
pr = 0
for i in A:
    dai = max(0, pr - i)
    ssum += dai
    pr = i + dai
print(ssum)

Solution (Python):
input()
b=list(map(int,input().split()))
ans=0
tall=0
for i in b:
  if tall>i:
    ans+=tall-i
  else:
    tall=i
print(ans)

Solution (Python):
N = int(input())
A = [int(a) for a in 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):
import sys,bisect

from sys  import stdin,stdout

from bisect import bisect_left,bisect_right,bisect,insort,insort_left,insort_right

from math import gcd,ceil,floor,sqrt

from collections import Counter,defaultdict,deque,OrderedDict

from queue import Queue,PriorityQueue

from string import ascii_lowercase

sys.setrecursionlimit(10**6)
INF = float('inf')
MOD = 998244353
mod = 10**9+7

def isPrime(n):
    
    if (n <= 1) :return False
    if (n <= 3) :return True
    if (n%2 == 0 or n%3 == 0):return False
    for i in range(5,ceil(sqrt(n))+1,6):
        if (n%i==0 or n%(i+2)==0):
            return False
    return True


def st():
    return list(stdin.readline().strip())

def inp():
    return int(stdin.readline())

def li():
    return list(map(int,stdin.readline().split()))

def mp():
    return map(int,stdin.readline().split())

def pr(n):
    stdout.write(str(n)+"\n")
    
def DFS(dictionary,vertex,visited):
    visited[vertex]=True
    stack=[vertex]
    print(vertex)
    while stack:
        a=stack.pop()
        for i in dictionary[a]:
            if not visited[i]:
                print(i)
                visited[i]=True
                stack.append(i)


def BFS(dictionary, vertex,visited):
    visited[vertex]=True
    q=deque()
    q.append(vertex)
    while q:
        a=q.popleft()
        for i in dictionary[a]:
            if not visited[i]:
                visited[i]=True
                q.append(i)
                print(i)

                


def soe(limit):
    l=[1]*(limit+1)
    l[0]=0
    l[1]=0
    prime=[]
    for i in range(2,limit+1):
        if l[i]:
            for j in range(i*i,limit+1,i):
                l[j]=0
    
    for i in range(2,limit+1):
        if l[i]:
            prime.append(i)
    return prime

def segsoe(low,high):
    limit=int(high**0.5)+1
    prime=soe(limit)
    n=high-low+1
    l=[0]*(n+1)
    for i in range(len(prime)):
        lowlimit=(low//prime[i])*prime[i]
        if lowlimit<low:
            lowlimit+=prime[i]
        if lowlimit==prime[i]:
            lowlimit+=prime[i]
        for j in range(lowlimit,high+1,prime[i]):
            l[j-low]=1
    for i in range(low,high+1):
        if not l[i-low]:
            if i!=1:
                print(i)
                
def gcd(a,b):
    while b:
        a=a%b
        b,a=a,b
    return a

def power(a,n):
    r=1
    while n:
        if n&1:
            r=(r*a)
        a*=a
        n=n>>1
    return r
    
def solve():
    n=inp()
    l=li()
    ans=0
    for i in range(1,n):
        if l[i-1]>l[i]:
            v=l[i-1]-l[i]
            ans+=v
            l[i]+=v
    pr(ans)
    




for _ in range(1):
    solve()

Solution (Python):
N = int(input())
a = [int(x) for x in input().split()]
ans = 0
l = 0
for i in range(N):
    if a[i]<l:
        ans += l-a[i]
    else:
        l = a[i]
print(ans)

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

max = A[0]
ans = 0
for a in A:
    if (m := max - a) > 0:
        ans += m
    else:
        max = a
print(ans)

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

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

a = L[0]
cnt = 0
for i in range(1,n):
    if a > L[i]:
        cnt += a - L[i]
    elif a < L[i]:
        a = L[i]

print(cnt)

Solution (Python):
from collections import deque
import sys, copy, itertools
input = sys.stdin.readline

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

ans = 0
x = 0

for i in range(1,n):
  if A[i-1] > A[i]:
    x = A[i-1] - A[i]
    A[i] = A[i] + x
    ans += x


print(ans)

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

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 += abs(a[i]-max)
print(ans)

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

step_sum=0
h=line[0]

for i in line:
    if i<h:
        step_sum+=h-i
    elif i>h:
        h=i
print(step_sum)

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

print(cnt)

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

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

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

count = 0
tmp = 0
for idx, i in enumerate(A):
  if idx == 0:
    tmp = i
    continue
  if tmp > i: 
    count += tmp - i
  else:
    tmp = i
print(count)

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

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

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

A=list(map(int,input().split()))
ans=0
tmp=A[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()))

count=0
for i in range(N-1):
    if A[i] <= A[i+1]:
        continue
    else:
        count+=abs(A[i+1]-A[i])
        A[i+1]=A[i]
print(count)

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

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

    print(ans)

main()

Solution (Python):
import sys
si = sys.stdin.readline


def main():
    n = int(si())
    l = [int(e) for e in si().split()]
    prv, ans = l[0], 0
    for e in l:
        if prv > e:
            ans += prv-e
        else:
            prv = e
    print(ans)


if __name__ == '__main__':
    main()

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

fumidai_total = 0
now_max = 0
for i in range(N):
    now_max = max(A[i], now_max)
    fumidai_total += now_max - A[i]

print(fumidai_total)

Solution (Python):

n=int(input())
ans=0
v=list(map(int,input().split()))

for i in range(1,n):
    if v[i]<v[i-1]:
        ans+=(v[i-1]-v[i])
        v[i]=v[i-1]
        
print(ans)

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

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

mini = A[0]
ans = 0

for i in range(len(A) - 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()))

pre=0
count=0
for i in range(n):
    if a[i]>=pre:
        pre=a[i]
    else:
        count+=(pre-a[i])

print(count)

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):
def main():
    n, *a = map(int, open(0).read().split())
    ans = 0
    t = 0
    for p, q in zip(a, a[1:]):
        p += t
        if p > q:
            ans += (p - q)
            t = (p - q)
        else:
            t = 0
    print(ans)


if __name__ == '__main__':
    main()

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

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

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

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

ans = []
diff = 0
for i in range(N-1):
  if A[i] > A[i+1]:
    diff = A[i]-A[i+1]
    A[i+1] = A[i+1] + diff
    ans.append(diff)
    diff = 0
  else:
    ans.append(diff)

print(sum(ans))

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

Solution (Python):
n = int(input())
A = list( int(x) for x  in input().split() )

fumidai = 0
great = A[0]

for i in range(n):
    if great > A[i]:
        fumidai += great - A[i]
    else:
        great = A[i]

print(fumidai)

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

ans = 0
now = a[0]

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

print(ans)

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

ans = 0
for i in range(1, N):
    if A[i - 1] >= A[i]:
        difference = A[i - 1] - A[i]
        A[i] += difference
        ans += difference

print(ans)

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

rev, bef = 0, None
for n in A:
    if bef is None:
        bef = n
        continue

    if n < bef:    
        rev += (bef - n)
    else:
        bef = n
    
print(rev)

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(N-1):
    if A[i] <= A[i+1]:
        pass
    else:
        plus = A[i]-A[i+1]
        
        ans += plus
        A[i+1] = A[i]
print(ans)

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

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

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

count = 0

for i in range(len(A)):
    if i > 0:
        buf = max(A[i-1] - A[i], 0)
        count += buf
        A[i] += buf
        
print(count)

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

max_a = 0
n_steps = 0
for a in A:
    max_a = max(a, max_a)
    n_steps += max(max_a - a, 0)
print(n_steps)

Solution (Python):


def main():
    n = int(input())
    a_array = list(map(int, input().split()))
    ans = 0
    for i in range(1, n):
        tmp = a_array[i-1] - a_array[i]
        if tmp > 0:
            ans += tmp
            a_array[i] += tmp
    print(ans)
main()

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
h = A[0]
res = 0 
for i in range(N):
    if A[i] >= h:
        h = A[i]
    else:
        res += h - A[i]
        
print(res)

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

print(fumidaisum)

Solution (Python):
import math
import numpy as np
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


N = I()
A = LI()

b = 0
ans = 0
for a in A:
    
    if b > a:
        ans += b - a
        a = b
    b = a

print(ans)

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

Solution (Python):
N = int(input())
A = map(int, input().split())
ans = 0
c_max = 0
for a in A:
  if a > c_max:
    c_max = a
  ans += c_max - a
print(ans)

Solution (Python):
n=int(input())
 
l=list(map(int,input().split()))
 
t=l[0]
x=0
 
for i in range(n):
    if t>l[i]:
        x+=t-l[i]
    else:
        t=l[i]
    
print(x)

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

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

s = 0

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

print(s)

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

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

sum = 0
for i in range(1, n, 1):
    if heights[i] < heights[i-1]:
        sum += (heights[i-1] - heights[i])
        heights[i] += (heights[i-1] - heights[i])

print(sum)

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

print(ct)

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

ans = 0
maximum = 0
for a in A:
    if maximum <= a:
        maximum = a
    else:
        ans = ans + (maximum - 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]:
        pass
    else:
        ans = 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):
    h = max(0, A[i-1] - A[i])
    A[i] += h
    ans += h
print(ans)

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

maxt = 0
res = 0
for i in range(N):
    maxt = max(maxt, A[i])
    res += maxt - A[i]
print(res)

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

step_sum = 0
height_front = A_list[0]
for idx in range(1, len(A_list)):
    A = A_list[idx]
    if A < height_front:
        step_sum += height_front - A
    else:
        height_front = A

print(step_sum)

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):


import math
import sys
import itertools
import numpy as np

n =int(input())

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

now = 0
answer = 0
for i in range(n):
    if now > a[i]:
        answer += now - a[i] 
    else:
        now = a[i]

print(answer)

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

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

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

sum = 0 
for i in range(N-1):
  if A[i] > A[i+1]:
    diff = A[i] - A[i+1]
    sum += diff
    A[i+1] = A[i]

print(str(sum))

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

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
h = a[0]
ans = 0
for x in a:
  if h > x:
    ans = ans + (h - x)
  elif h<= x:
    h = x
print(ans)

Solution (Python):
n = int(input())
a = [int(i) for i in 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] - a[i]
    
print(ans)

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

N_list = list(map(int,input().split()))
max_n = 0
cnt = 0
for i in range(len(N_list)-1):
  if max_n < N_list[i]:
    max_n = N_list[i]
  if max_n > N_list[i+1]:
    cnt += max_n - N_list[i+1]
    
print(cnt)

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

def main(n,a):
    sum=0
    h=a[0]
    for i in range(1,n):
        if h>a[i]:
            sum+=h-a[i]
        else:
            h=a[i]
    return sum

if __name__=='__main__':
    n,a=readinput()
    ans=main(n,a)
    print(ans)

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

Solution (Python):
n = int(input())
la = [int(w) for w in input().split()]

ans = 0
h = la[0]

for a in la[1:]:
    if a <= h:
        ans += h-a
    else:
        h = a

print(ans)

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

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

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

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

if __name__ == "__main__":
    main()

Solution (Python):
import sys
from itertools import accumulate
input = sys.stdin.readline

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

M=list(accumulate(L,max))
ans = 0
for i in range(n):
    ans+=abs(M[i]-L[i])
print(ans)

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

s = 0
f = ass[0]
for a in ass:
  if f > a:
    s += f-a
  else:
    f = a

print(s)

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

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

Solution (Python):
N = int(input())
l = [int(x) for x in input().split()]
m = 0
ans = 0
for i in range(len(l)):
    if m < l[i]:
        m = l[i]
    else:
        ans += m-l[i]
print(ans)

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

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

summ=0
mini=0
for i in range(n):
    if a[i]>=mini:
        mini=a[i]
    else:
        summ += mini-a[i]
print(summ)

Solution (Python):
import sys
input =sys.stdin.readline

N=int(input().rstrip('\n'))
As = [int(x) for x in input().rstrip('\n').split()]
now = As[0]
res = 0
for i in As:
  if i < now:
    res += now - i
  else:
    now = i
print(res)

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]
    else:
        pass

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):
import sys
import bisect as bi
import math
from collections import defaultdict as dd
import heapq
import itertools
input=sys.stdin.readline


mo=10**9+7
def cin():
    return map(int,sin().split())
def ain():            
    return list(map(int,sin().split()))
def sin():
    return input()
def inin():
    return int(input())








for _ in range(1):
    n=inin()
    l=ain()
    ans=0
    curr=l[0]
    for i in range(1,n):
        if(l[i]<curr):
            ans+=curr-l[i]
        curr=max(curr,l[i])
    print(ans)

Solution (Python):
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N = int(input())
A = input().split()

nowTall = int(A[0])
ans = 0

for i in range(N):
    if i == 0:
        continue

    if int(A[i]) < nowTall:
        ans+= nowTall - int(A[i])

    nowTall = max(nowTall, int(A[i]))

print(ans)

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

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

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):


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


if __name__ == "__main__":
    main()

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


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]-a[i]

print(ans)

Solution (Python):
lens = int(input())
arrs = [int(x) for x in input().split()]
need = 0
for i in range(1, lens):
    if arrs[i] < arrs[i-1]:
        more =  (arrs[i-1] - arrs[i])
        arrs[i] += more
        need += more
print(need)

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

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

Solution (Python):

import sys


def solve(N: int, A: "List[int]"):
    s = 0
    for i, a in enumerate(A):
        if i==0:
            continue
        
        if A[i-1] > A[i]:
            h = A[i-1] - A[i]
            A[i] += h
            s+=h
    print(s)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    A = [int(next(tokens)) for _ in range(N)]  
    solve(N, A)

if __name__ == '__main__':
    main()

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

ans = 0
p = 0
for a in A:
    if p > a:
        ans = ans + (p - a)
    p = max(p, a)
    
print(ans)

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

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

curr_max = 0
for a in A:
    if a > curr_max:
        curr_max = a
    else:
        rslt += curr_max - a

print(rslt)

Solution (Python):
import sys

sys.setrecursionlimit(10**6)
input = sys.stdin.readline


def main():
    N = int(input())
    A = list(map(int, input().split()))
    cost = 0

    for i in range(1, N):
        a_left, a_right = A[i-1], A[i]
        if a_left > a_right:
            cost += a_left - a_right
            A[i] = a_left
    print(cost)


if __name__ == "__main__":
    main()

Solution (Python):
import sys
import math
import bisect
from sys import stdin,stdout
from math import gcd,floor,sqrt,log
from collections import defaultdict as dd
from bisect import bisect_left as bl,bisect_right as br

sys.setrecursionlimit(100000000)

ii     =lambda: int(input())
si     =lambda: input()
jn     =lambda x,l: x.join(map(str,l))
sl     =lambda: list(map(str,input().strip()))
mi     =lambda: map(int,input().split())
mif    =lambda: map(float,input().split())
lii    =lambda: list(map(int,input().split()))

ceil   =lambda x: int(x) if(x==int(x)) else int(x)+1
ceildiv=lambda x,d: x//d if(x%d==0) else x//d+1

flush  =lambda: stdout.flush()
ssi =lambda: stdin.readline()
sii =lambda: int(stdin.readline())
sp  =lambda x: stdout.write(str(x))

mod=1000000007



n=ii()
arr=lii()
count=0
for i in range(1,n):
    if arr[i]<arr[i-1]:
        count+=arr[i-1]-arr[i]
        arr[i]=arr[i-1]
print(count)

Solution (Python):



def main():
    n = int(input())
    li = list(map(int, input().split()))
    max = 0
    total = 0
    for i in li:
        if max < i:
            max = i
            continue
        elif max == i:
            continue
        else:
            total += max - i
    print(total)


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
result = 0
max_a = 0
for x in a:
    if x > max_a:
        max_a = x
    result += max_a - x
print(result)

Solution (Python):
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()
A = LI()

height = 0

for i in range(1,N):
    if A[i-1] > A[i]:
        height += A[i-1] - A[i]
        A[i] = A[i-1]

print(height)

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

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

print(sum(a)-sum(a_2))

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

print(sum)

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

if __name__ == '__main__':
	main()

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