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 numpy as np

N = int(input().rstrip())
A = [int(i) for i in input().rstrip().split()]
B = A.copy()

for i in range(N-1):
  if B[i+1] < B[i]:
    B[i+1] = B[i]
    
A = np.array(A)
B = np.array(B)
C = B - A

print(np.sum(C))

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

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

if __name__ == "__main__":
  resolve()

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


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

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

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

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

res = 0
old_h = 0
for i, h in enumerate(A):
    if (diff:=h-old_h) < 0: 
        res -= diff
    else:
        old_h = h

print(res)

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


h=0
pre=0
for a in alist:
    if pre>0 and pre>a:
        h+=(pre-a)

    if a > pre:
        pre=a

print(h)

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

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

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

for i in range(n-1):
    if l[i] >= a[i+1]:
        l.append(l[i])
    else:
        l.append(a[i+1])

print(sum(l) -sum(a))

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

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]:
        count+=A[i]-A[i+1]
        A[i+1]=A[i]
        
print(count)

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

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

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

Solution (Python):
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

n = i()
a = intl()

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())
L = list(map(int, input().split()))

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

print(ans)

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

Solution (Python):
import sys
import math

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

Max = 0
dai = 0
dai_sum = 0

for a in A:

    if Max > a:
        dai = Max - a
        dai_sum += dai

    if Max < a:
        Max = a

print(dai_sum)

Solution (Python):

"""



def main2():
    stdin = open('/dev/stdin')
    stdin.readline()
    ans = 0
    b = 0
    for x in stdin.readline().split():
        a = int(x)
        if a > b:
            b = a
        else:
            ans += b - a
    print(ans)
"""
import os, sys
p = os.path.dirname(__file__)
pymain = os.path.join(p, "a.out")
if len(sys.argv) == 1:
    import subprocess
    if p == "":
        pymain = "./" + pymain
    subprocess.call(pymain)
else:
    import gzip, base64, stat
    gz = b'H4sIADsNQV8C/+19C3hTVbb/SZ/h1QRELI/BgAFaHm1DebTIYEobONEUOhSQGYGQpinNmCY1OSnFYRRt658YcJgZR/Exc7n3fuN4HUedueog40CRRxmdBzjqoKAiCqSEly/AF7lr7b1Pus9pDhTk//9/9/s4SnfW7+y99tprr7324+xz9t02x6w0nU6QrzRhhoBU1RAroa0M33hvMgpgJUIv+Hu9MFzIAjqDi2cVrIrwHGMth3oWL52lK0mjdEmaVREOY/HkUMeFmQJ/WRXhskpBEQqCKZkOZc1bTNG8xcsU4WrG9LksZbo0li62hKKxJcsUoZAmKEK5fBns33yGz2flksMKFq+Ci49X1WGpFn/niUxO0aoI17J4a1XpvgfpsoSeX0YWzpPz09DLvnRBEcr1UOjz1kyZVOirneDz+sPNE5pLpkyYMqkgFCiYSGQysriz5yxI1ncaJ/NAhuF99+SHX/tjPO23LRP/Wt5r26N/feNQv7l4r5ClyYZ/rTnGZX3ze6VhytV9BR3eK4Z/U+HfUz+d/srj7j/v7H3Peud/Hyh+c/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FOg/lQQfulIf8G/lgVsCSCOhq8LohfUAif2j+NC/oEoQCmJ3gVO4K7W8Zyp6tyOt38r6GEgYM09gnlXweICjPIpT3P8xngKnbsyrlZVGll/dJSAwwXyQ9vu93JpEIyOnl/RQbGLBYfo6r2k+VfL7C9kalqfZPnWPAGpYwi5Vdr9rHtJDtWUpT7cdarVfuv9LS31K290lOL+/jmMcWQptU8qepwtvZXiqZlvd77Gbp24Uu+dNTlP9OptM01f6tNf2V+7fU+pPL38rSz1TtB2seoNw/lsnSqNM/wHSSpdo/d26Qcp+ZVv1HVOnl/ShGltCYroxvVIUPqtLL+xdMbEPegNGp08vXo6r08nOxSVblvjct+Teq2p/8PFJ+vBZT2Y+6/p5UpZef9+aJlF57kfxfVKWX99VsYukXpV84/3ZVennfidFB6SrdhfN/XaDndKar9kfmLU6tb70qfE+g53mmq/ZPlixOLa86/TEmv5xeft5sZemfVMmv9mdnubbF7xeMLVE21CxVvkbOIfD5y/uIYs6elT9TlT75PJ4FG3QXTp+jSi8/x9vgunD+ArcvR8+ll58bPsnS515Ef4NZ/kVqu2bpq3qwTzfVe8TnZPnZIbB4oGFlCv/TS1Cel5ssZyN7/tj/wv67v0b65nvY/g/dhdP/DyhnXvlgigAA'
    bin = gzip.decompress(base64.b64decode(gz))
    with open(pymain, "wb") as f:
        f.write(bin)
    os.chmod(pymain, 0o775)

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



if __name__ == '__main__':
    main()

Solution (Python):
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    max_height = A[0]
    step_sum = 0
    for Ai in A:
        if Ai>=max_height:
            max_height = Ai
        else:
            step_sum = step_sum + (max_height - Ai)
    print(step_sum)
resolve()

Solution (Python):
a = int(input())
b = list(map(int,input().split()))
bmax = 0
ans = 0
for i in range(a):
    if i == 0:
        bmax = b[i]
    else:
        if bmax < b[i]:
            bmax = b[i]
        elif bmax > b[i]:
            ans += bmax - b[i]
print(str(ans))

Solution (Python):

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

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

Solution (Python):
n = int(input())
height = [int(i) for i in  input().split()]
max_height = height[0]
step = 0
for i in range(n):
    if height[i] <= max_height:
        step += max_height - height[i]
    else:
        max_height = height[i]
print(step)

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

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

print(ans)

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

pro = 0
board = 0

for i in range(N):
  if(pro>A[i]):
    board = board + (pro - A[i])
    A[i] = pro
  
  pro = A[i]
print(board)

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

Solution (Python):
def main():
  N = int(input())
  A = list(map(int, input().split()))
  A_copy = A.copy()
  d_sum = 0
  
  for i in range(N - 1):
    a_dif = A[i+1] - A[i]
    if A[i+1] < A[i]:
      A[i+1] = A[i]
  
  for i in range(N):
    d_sum += A[i] - A_copy[i]
  
  print(d_sum)
  
if __name__ == "__main__":
  main()

Solution (Python):
N, *A = map(int, open(0).read().split())

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

print(sum(ans))

Solution (Python):
n=int(input())
a=list(map(int,input().split(' ')))
b=[]
for i in range(1,n):
	if a[i]<a[i-1]:
		b.append(a[i-1]-a[i])
		a[i]=a[i-1]
print(sum(b))

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

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

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    n, *a = map(int, read().split())
    r = 0
    st = a[0]
    for ae in a[1:]:
        if st > ae:
            r += st - ae
        else:
            st = ae
    print(r)


if __name__ == '__main__':
    main()

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
step = 0
for i in range(1, n):
    if a[i] < a[i-1]:
        humidai = a[i-1] - a[i]
        step += humidai
        a[i] = a[i] + humidai
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] < 0:
        ans += abs(a[i+1] - a[i])
        a[i+1] = a[i]
        
print(ans)

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

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

Solution (Python):
n = int(input())
lst = list(map(int, input().split()))
count = 0
t = 0
for i in range(n):
    if i == 0:
        continue
    if lst[i] < lst[i-1]:
        t = lst[i-1] - lst[i]
        count += t
        lst[i] += t
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]:
    diff = a[i] - a[i + 1]
    ans += diff
    a[i + 1] += diff

print(ans)

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

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

res = 0
base = l[0]

for i in range(1,n):
  if base < l[i]:
    base =l[i]
  elif base > l[i]:
    res += base - l[i]
    
print(res)

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

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

Solution (Python):

n = int(input())
a = list(map(int, input().split()))
tmp = 0
ans = 0
for i in a:
    if tmp > i:
        ans += tmp - i
    else:
        tmp = i
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] < 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(' ')))

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

print(sum(ans))

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

main()

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

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
ans=0
ma=A[0]
for i in range(1,n):
  if ma<A[i]:
    ma=A[i]
  else:
    ans+=(ma-A[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]:
    count += a[i] - a[i+1]
    a[i+1] += a[i] - a[i+1]
print(count)

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

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

print(ans)

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

print(ans)

Solution (Python):
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy


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

if __name__ == '__main__':
	main()

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

biggest = 0
humidai = 0


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

    if A[iter-1] > A[iter]:
        biggest = A[iter-1]
        humidai += A[iter-1] - A[iter]
        A[iter] += A[iter-1] - A[iter]
        


    if A[iter-1] < A[iter]:
        biggest = A[iter]


print(humidai)

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

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

aMax = max(a)

answer = 0
countOld = 0

for i,v in enumerate(a):
    if i != 0:
        count = 0
        count = a[i-1] + countOld - v
        if count < 0:
            count = 0
        answer += count
        countOld = count

print(answer)

Solution (Python):



n = int(input())

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

ans = 0
max = 0
for i in range(n):
    if i == 0:
        max = a[i]
        continue

    if a[i] < max:
        ans += max - a[i]
    else:
        max = a[i]


print("{}".format(ans))

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

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

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

print(ans)

Solution (Python):
n = int(input())
A = [*map(int, input().split())]
s = 0
pre = A[0]
for now in A[1:]:
    if pre > now:
        s += pre-now
    else:
        pre = now
print(s)

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

ans = 0

m = l[0]
for li in l[1:]:
  if li < m:
    ans +=m-li
  else:
    m = li

print(ans)

Solution (Python):
a = int(input())
b = list(map(int, input().split()))
c = b[0]
ans = 0
for i in range(a):
  if c >= b[i]:
    ans += c - b[i]
  else:
    c = b[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-1] > a[i]:
    alpha = a[i-1] - a[i]
    a[i] = a[i] + alpha
    count = count + alpha 
  
print(count)

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

step=0
max_temp=0
for i in range(len(l)-1):
    max_temp=max(max_temp,l[i])
    if max_temp>l[i+1]:
        step+=(max_temp-l[i+1])
print(step)

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