peterverebics/CodeNet_Python_118 huggingface dataset:
N = int(input())

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

cur_tallest = A[0]

res = 0
for a in A:
    if a <= cur_tallest:
        res += cur_tallest - a
    else:
        cur_tallest = a
        
print(res)
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(1,n):
    if a[i-1]>a[i]:
#        print("i=",i)
        ans+=a[i-1]-a[i]
        a[i]+=a[i-1]-a[i]
print(ans)
n=input()

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

ma=max(l)
mi=min(l)

print(int(ma-mi))
import math
import collections
import fractions
import itertools
import functools
import operator
import bisect

def solve():
    n = int(input())
    a = list(map(int, input().split()))
    mi = 0
    le = len(a)
    cost = 0
    for i in range(le-1):
        if a[i] > a[i+1]:
            mi = max(a[i], mi)
            cost += mi - a[i+1]
    print(cost)
    return 0

if __name__ == "__main__":
    solve()
N = int(input())
A = list(map(int,input().split()))
K = 0
for i in range(0,N-2):
    if A[i+1]-A[i]<0:
        K += A[i]-A[i+1]+K
    else:
        K += 0

print(K)
N = int(input())
A_high_list = list(map(int,input().split()))
Fumidai = 0
s = 0
B_list = []

for n in range(N):
    if n > 0 and A_high_list[n-1] > A_high_list[n]:
        Fumidai += max(B_list) - A_high_list[n]
        B_list.append(A_high_list[n])
    elif n == 0:
        B_list.append(A_high_list[0])
        continue  
    else:
        B_list.append(A_high_list[n])
        continue

print(Fumidai)
n=int(input())

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

s=0
for i in range(len(a)-1):
    if a[i]>=a[+1]:
        continue
    else:
        s+=a[i+1]-a[i]

print(s)
N=int(input())
A=B=list(map(int,input().split()))
s=j=N+1
sum_A=0

if A==sorted(A):
    print(0)
    exit()

for i in range(1,N):
    x=max(B[:s])
    s=B.index(x)
    B[s:j]=[x]*len(B[s:j])
    j=s
    if s==0:
        break
    
print(sum(B)-sum(A))
N = int(input())
pre = 0
ans = 0
for a in input().split():
    a = int(a)
    ans += max(a-pre, 0)
    pre = max(pre, a)
print(ans)
def main():
    N = map(int, input().split())
    A = list(map(int, input().split()))[::-1]
    cont = 0
    ans_val = 0
    for i in range(len(A) - 1):
        if A[i] <= A[i+1]:
            cont += 1
            diff = A[i+1] - A[i]
            ans_val += diff * cont
        else:
            cont = 0
    return ans_val

if __name__ == '__main__':
    print(main())
def step(N, A):
    sum = 0
    for i in range(1, N):
        if A[i-1] < A[i]:
            sum += A[i] - A[i-1]
    return sum
if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    print(step(N, A))
l=list(map(int,input().split()))
ans=0
maxt=0
for i in l:
  if i<maxt:
    ans+=maxt-1
    maxt=max(i,maxt)
print(ans)
N = int(input())
A = list(map(int, input().split()))

ans = 0

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

print(ans)
n = int(input())
a = list(map(int, input().split()))

ans = 0
prev = a[0]
for e in a:
  if e - prev > 0:
    ans += e - prev
  prev = e

print(ans)
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("l[a],x,l[a+1]=", l[a], x, l[a+1])
print(x)
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(len(A)-1):
    a_before = A[i]
    a_after = A[i+1]

    diff = a_before-a_after

    if diff < 0:
        ans += abs(diff)

print(ans)
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+1] - A[i]
print(ans)
n = int(input())
a = list(map(int, input().split()))

ans = 0
x = a[0]
for v in a[1:]:
    if v > x:
        ans += v - x
    x = v
print(ans)
number = int(input())
values = [int(i) for i in input().split()]


max = max(values)
min = min(values)

def answer(values, max, min):
  sum = 0
  if max == min: 
    return 0
  if max < min:
    return min
  average = max / 2
  for index in range(len(values)):
    if max > values[index] > average:
      sum += int(max) - values[index]

  return sum + answer(values,average,min) 

temp = answer(values, max, min)
print(temp)
N = int(input())
A = map(int, input().split())

#current height
now = 0
total = 0

for a in A:
    print("a", a)

    if a >= now:
        now = a
        pass
    else:
        total += now - a
    #print("now", now)
    #print("total", total)

print(total)
N=int(input())
A=[int(_) for _ in input().split(" ")]

ans=0

max=max(A)

for i in range(len(A)):
  if A[i] == max:
    a=i
    break

if a==0:
  total=0
  for i in range(len(A)):
    total=total+max-A[i]
  print(total)
  exit()
  
   
tmp=0
for i in range(a):
  if tmp < A[i]:
    tmp=A[i]

#print("tmp",tmp,"a",a,"A[a]",A[a])
  
total=0
for i in range(a):
  total += tmp - A[i]
  #print("total",total)
  
for i in range(a,len(A)):
  total += max - A[i]
  #print("total",total)

print(total)
n = int(input())
a = list(map(int, input().split()))


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

try:
    for i in range(len(As)):
        if As[i] < As[i + 1]:
            step = As[i + 1] - As[i]
            As[i] += step
            sum += step 
except IndexError:
    pass

print(sum)
A = list(map(int,input().split()))
sm = 0
now = A[0]
for num in A:
    if num < now:
        sm += now-num
    elif num > now:
        now = num
print(sm)
N=int(input())
A = list(map(int, input().split()))
#print(A)
count=0
count2=0
for i in range(len(A)-1):
    if A[i]>A[i+1]:
        count=A[i]-A[i+1]
        print('count',count)
        A[i+1]=A[i]
        count2+=count
print(count2)
n = int(input())
As = list(map(int,input().split()))
sum = 0
step =0

try:
    for i in range(n):
        if As[i] > As[i + 1]:
            step = As[i] - As[i + 1]
            print(step)
            As[i + 1] += step
            print("As["+str(i + 1)+"]:"+str(As[i + 1]))
            sum += step 
except IndexError:
    pass

print(sum)
N = int(input())
A = input().split()
# print(A)
A_list = list(map(float, A))
sa = 0
for i in range(N-1):
    # print(i)
    if A_list[i] > A_list[i+1]:
        sa += A_list[i] - A_list[i+1]
        A_list[i+1] = A_list[i]
print(sa)
n = int(input())
a = list(map(int, input().split()))

ans = 0
i = 0
maxi = a[i]

while True:
    if i == n - 1:
        break
    if a[i + 1] < a[i]:
        ans += (maxi - a[i + 1])
    else:
        maxi = a[i + 1]

    i += 1

print(ans)
n=int(input())
a_list=list(map(int,input().split()))
ans=0
tmp=a_list[0]
for i in range(n-1):
    if a_list[i]>a_list[i+1]:
        print(tmp,ans)
        ans+=tmp-a_list[i+1]
    else:
        tmp=a_list[i+1]
print(ans)
N = int(input())
A = list(map(int, input().split()))
step = max(A)-min(A)
print(step)
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(N):
    if i == 0:
        ans = 0
    else:
        if A[i] > A[i-1]:
            ans = ans + A[i] - A[i-1]
print(ans)
n = int(input())
As = list(map(int, input().split()))
h = 0
for i in range(n - 1):
  d = As[i + 1] - As[i]
  if d > 0:
    h += d
print(h)
n=int(input())
l=list(map(int,input().split()))
mx=l[0]
an=0
for i in range(1,n):
  if l[i]<mx:
    an+=mx-l[i]
  else:
    l[i]=mx
print(an)
N = int(input())
A = [0]*N
A = list(map(int, input().split()))

sum_step = 0

for n in range(1, N):
  max_ = max(A[0:n])
  sum_step += max_ - A[n]
  
print(sum_step)
n = int(input())
a = list(map(int, input().split()))
m = 0
ma = a[0]
for i in range(1, n):
    ma = max(ma, a[i])
    m = max(m, ma-a[i])
print(m)
N=int(input())
A=list(map(int,input().split()))
n=0
for i in range(N-1):    
    if A[i]<A[i-1]:
        n+=A[i-1]-A[i]
        A[i]=A[i-1]
print(n)
a=input()
b=input()
c=b.split()
d=map(int,c)
main=list(d)
sum=0
print(main)
for i in range(len(main)-2):
    stool=main[i]-main[i+1]
    if stool>0:
        main[i+1]+=stool
        sum+=stool

stool=main[len(main)-2]-main[len(main)-1]
if stool>0:
    sum+=stool
    main[len(main)-1]+=stool

print(sum)
##C - Step
N = int(input())
A = list(map(int,input().split()))
ans = 0
for i in range(N):
    print(i,A)
    if not A:
        Idx = A.index(max(A))
        ans += max(A)*(len(A) - Idx) - sum(A[Idx::])
        del A[Idx::]
    else:
        break
print(ans)
n = input()
a_list = list(map(int, input().split()))
score = 0

for i in range(len(a_list) - 1):
  if a_list[i] < a_list[i+1]:
    score += a_list[i+1] - a_list[i]
    
print(score)
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] - A[i-1]
print(ans)
n = int(input())
a = list(map(int, input().split()))

sum = 0
k = a[0]

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

print(sum)
n=int(input())

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

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

print(s)
N=int(input())
A=list(map(int,input().split()))
s=0
for i in range(N-1):
  if A[i]>A[i+1]:
    s+=A[i]-A[i+1]
print(s)
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+1] - a[i]
print(ans)
n = int(input())
a = list(map(int,input().split()))
m = max(a)
s = 0

ind = a.index(m)
for i in range(n):
    if i == n-1:
        break
    else:
        if a[i]>a[i+1] and i < ind:
            s += a[i]-a[i+1]

        else:
            a[i]>a[i+1]
            s += a[ind]-a[i+1]
            
print(s)
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
    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:
            ans += diff
    print(ans)


if __name__ == "__main__":
    main()
n = int(input())
a = list(map(int,input().split()))
mx = max(a)
mn = min(a)
print(mx-mn)
N = int(input())
A = list(map(int,input().split()))

keep = 0
cnt =0
x=0


for a in A:
    if keep > a:
        cnt += keep -a
        x = keep -a
        print(x)
        keep = a + x
    else:
      keep = a
    
    
print(cnt)
inputs = input().split()
A = list(map(int, inputs[1:]))

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)
n = input()
l = [int(i) for i in input().split()]
max = 0
sum = 0
print(l)
for i in range(1,len(l)):

  if l[i-1] > max:
    max = l[i-1]
  if l[i] < max:
    sum += max - l[i]
print(sum)
N = int(input())
A = list(map(int, input().split()))
step = [0] * N
for i, a in enumerate(A[1:], 1):
    step[i] = -min(0, A[i - 1] + step[i - 1] - a)
print(sum(step))
n=int(input())

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

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

print(s)
from sys import stdin, setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
from itertools import combinations
setrecursionlimit(100000)

INF = int(1e10)
MOD = int(1e9 + 7)

def main():
    from builtins import int, map
    N = int(input())
    A = list(map(int, input().split()))
    count = 0
    for i in range(1, N):
        diff = A[i - 1] - A[i]
        if diff < 0:
            count += abs(diff)
    print(count)

if __name__ == '__main__':
    main()
N = int(input())
A = list(map(int, input().split()))
max_num = 0
for num in A:
  if num > max_num:
    max_num = num

border = A.index(max_num)
height = []
before_h = A[0]
for h in A[:border]:
  if before_h <= h:
    height.append(0)
    
  elif before_h > h:
    height.append(before_h-h)
  before_h = h

for h in A[border:]:
  height.append(max_num-h)

print(sum(height))
n=int(input())
listA=list(map(int,input().split()))
listB=[0]

for i in range(len(listA)-1):
  if listA[i+1]>listA[i]:
    listB.append(listA[i+1]-listA[i])

print(sum(listB))
n = int(input())
a = list(map(int, input().split()))
count = 0
for i in range(n-1):
    if a[i+1]-a[i]>0:
        count+=a[i+1]-a[i]
print(count)
n = input()
s = list(map(int, input().split()))
if all(s):
    print(0)
else:
    print(max(s[(s.index(max(s))+1):]))
N=int(input())
A=list(map(int,input().split()))
a=0
for i in range(N-1):
    if (A[i+1]-A[i])>=0:
        a=a+(A[i+1]-A[i])
    else:
        a=a
print(a)
n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(0,n):
  if a[i]>a[i-1]:
    continue
  else:
    b.append(a[i-1]-a[i])
    
print(sum(b))
n,*a=map(int,open(0).read().split())
ma=a[0]
ans=0
for q in a:
  if q>ma:
    ans+=(q-ma)
  ma=max(ma,q)
print(ans)
n = int(input())
list = list(map(int,input().split()))

ans = 0
for i,ele in enumerate(list):
    if i == 0:
        continue
    elif i == len(list)-1:
        continue

    if ele > list[i+1]:
        ans = ans +  ele - list[i+1] + 1

print(ans)
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    N = int(input())
    A = read_list()
    pre = A[0]
    res = 0
    for a in A:
        res += max(0, a - pre)
        pre = a
    print(res)


if __name__ == "__main__":
    main()
n = int(input())

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


highest = 0
diff = 0

a = a[::-1]

for i in a:
    if i > highest:
        highest = i
    diff = max(highest - i, diff)

print(diff)
N=input()
list=[int(x) for x in input().split()]
i=0
kei=0
k=0
while(i!=len(list)-1):
    if(list[i]>list[i+1]):
        kei+=list[i]-list[i+1]
        list[i+1]=list[i]
        print(kei)
    i+=1
print(kei)
n=int(input())
l=list(map(int,input().split()))
u=max(l)
d=0
i=0
while l[i]!=u:
  if l[i]>l[i+1]:
    d=d+abs(l[i+1]-l[i])
  i=i+1
r=i
for b in range(r,n):
    d=d+(u-l[b])
print(d)
n=int(input())
a_list=list(map(int,input().split()))
b_list=[]
for i in range(n-1):
  d=a_list[i]-a_list[i+1]
  if(d>=0):
    b_list.append(d)
    a_list[i+1]+=d
    
ans=sum(b_list)
print(b_list)
print(ans)
N = int(input())
A = list(map(int, input().split()))
step = 0
for i in range(N - 1):
  step += max(0, A[i + 1] - A[i])
  A[i + 1] += max(0, A[i + 1] - A[i])
print(step)
n = int(input())
a = sorted(map(int,input().split()))
b = []
for i in range(n-1):
    b.append(a[i+1]-a[i])
print(sum(b))
N = int(input())
A = list(map(int, input().split()))
S = 0
n = A[0]
for i in A[1:]:
    if n < i:
        S += i - n
        n = i
    elif n == i:
        continue
    else:
        n = i
print(S)
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]
    print(sub)
    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))
a=int(input())
b=list(map(int,input().split()))
c=0
if a==0:
  print(0)
else:
  for i in range(a-1):
    if b[i]>b[i+1]:
      b[i+1]=b[i+1]+1
      c=c+1
  print(c)
def main():
  x = 0
  n = int(input())
  a = list(map(int,(input().split())))
  for i in range(n):
#    print(i)
    if a[i:i+1] < a[i+1:i+2]:
#      print(a[i:i+1],a[i+1:i+2])
      a1 = a[i:i+1][0]
      a2 = a[i+1:i+2][0]
      x +=(a2-a1)
  print(x)
  
if __name__ == '__main__':
  main()
n=int(input())
a = list(map(int,input().split()))
b = a[0]
total=0
for i in a:
  if i<b:
    total+=b-i
  b=i
print(total)
n=int(input())
a=list(map(int,input().split()))

an =0
ki=a[0]
for i in range(n-1):
    wk=a[i]-a[i+1]
    if wk<0:
        an+=abs(wk)
        ki-=wk
print(an)
n = int(input())
a_L = list(map(int,input().split()))


if len(a_L) == 1:
    print(0)
    exit()

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

if a_L[-1] > a_L[-2]:
    ans += abs(a_L[-1]-a_L[-2])
print(ans)
N = int(input())
A = list(map(int, input().split()))
sum=0
for i in range(N-1):
    if A[i+1]>A[i]:
        sum+=A[i+1]-A[i]
print(sum)
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]
print(F)
n = int(input())
l = list(map(int, input().split()))
l.reverse()
count = 0
for i in range(len(l) - 1):
    if l[i] > l[i + 1]:
        count += abs(l[i] - l[i + 1])
print(count)
N=int(input())
A=list(map(int,input().split()))
a=0
s=[]
for i in A:
  if i<a:
    s.append(a-i)
    a=i
  else:
    a=i
print(sum(s))
N = int(input())
A = list(map(int,input().split()))
K = 0
for i in range(0,N-1):
    if A[i+1]-A[i]<0:
        K += A[i+1]-A[i]
    else:
        K += 0

print(K)
N = int(input())
A = list(map(int, input().split()))
s = 0
if N==1:
  print(0)
  exit()

for i,a in enumerate(A):
  if i==0:
    continue
  
  s+=(a<A[i-1])*a

print(s)
N = int(input())
A = map(int, input().split())

curr = 0
ans = 0
for a in A:
  if curr < a:
    curr = a
    ans += a-curr
print(ans)
n = int(input())
a = input()
a = a.split()
count = 0

boo = False

for i in a:
    if int(i) >= n:
        boo = True

if(boo):
    print(n - 1)
else:
    print(0)
n = int(input())
a = list(map(int,input().split()))

res = 0
for i in range (1, n):
    cur = a[i] - a[i - 1]
    if cur > 0:
        res += cur
print(res)
N = int(input())
A_high_list = list(map(int,input().split()))
B_list = [A_high_list[0]]
Fumidai = 0
s = 0

for n, m in enumerate(A_high_list):
    if B_list[n] > A_high_list[n]:
        s = max(B_list) - int(A_high_list[n])
        Fumidai += s
        B_list.append(A_high_list[n])
    else:
        B_list.append(A_high_list[n])
        continue

print(Fumidai)
n=int(input())
l=[int(i) for i in input().split()]
m=l[0]
c=0
for i in range(1,n):
    if(l[i]<m):
        c=max(c,m-l[i])
    m=max(l[i],m)
print(c)
num = int(input())
item = input().split()
res = 0

for i in range(num):
  if i == 0:
    continue
  b = int(item[i - 1])
  t = int(item[i])
  
  if b > t:
    res += (b - t)
      
print(res)
def Step():
    
    num = int(input())

    data = list(map(int,input().split()))
        
    print(max(data) - min(data))
        
if __name__ == '__main__':
    Step()
n = int(input())
a = list(map(int, input().split()))
max = a[0]
sum = 0
count = 0
result = 0

for i in range(0,n):
  if max > a[i]:
    count+=1
    sum+=a[i]
    if i == n-1:
      result += max*count-sum
  else:
    result += max*count-sum
    
print(result)
n=int(input())
k=map(int,input().split())
p=sorted(k)
print(p[-1]-p[0])
n = int(input())
inputs = list(map(int,input().split()))
As = []
sum = 0
step =0
for i in inputs:
    As.append(int(i))
try:
    for i in range(len(As)):
        if As[i] < As[i + 1]:
            step = As[i + 1] - As[i]
            sum += step 
except:
    pass

print(sum)
n = int(input())
wa = 0
m = 0
l = list(map(int, input().split()))
for i in range(1, n):
    m = max(l[i], m)
    if m >= l[i]:
        wa += m - l[i]
print(wa)
#ABC177 C
N = int(input())
A = list(map(int,input().split()))
max = A[0]
F = [0]

for i in range(1,N):
  if max > A[i]:
    F.append(max - A[i])
  else:
    max = A[i]
    F.append(0)

print(F)
print(sum(F))
N=int(input())
a_list = list(map(int,input().split()))
ans = 0
min = a_list[0]
for i in range(1,N):
  if min > a_list[i]:
    ans += a_list[i]-min
  else:
    min = a_list[i]
print(ans)
n = int(input())
a = list(map(int, input().split()))
ans = 0
maxh = 0
for i in range(len(a)-1):
    if a[i] > a[i+1]:
        if maxh < a[i]:
            maxh = a[i]
        ans += maxh - a[i+1]


print(ans)
n = int(input())
a = list(map(int,input().split()))
MAX = max(a)
ans = 0
maxflg = False
minflg = False
for i in range(n):
    if a[i] == MAX:
        maxflg = True
        if i == 0:
            index = i + 1
        else:
            index = i
        leftMAX = max(a[:index])
    if maxflg:
        ans += MAX - a[i]

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

ans = 0

for i in range(N - 1):
  ans += max(0, A[i - 1] - A[i])
  A[i] += max(0, A[i - 1] - A[i])
  
print(ans)
total = int(input())
tall = list(map(int, input().split()))
dif = 0
for i in range(total - 1):
    if tall[i+1] > tall[i]:
        var = tall[i+1] - tall[i]
        tall[i] += var
        dif += var
    else:
        pass
print(dif)
n = int(input())
a = [int(i) for i in input().split()]
print(a)
ans=0
for i in range(n-1):
  d = a[i-1] - a[i]
  if d<0:
    ans+= d+1
    a[i]=a[i]+d+1
  else:
    continue
    
print(abs(ans))
n = int(input())
a = list(map(int,input().split()))

max_n = max(a)
min_n = min(a)

result = max_n - min_n 

print(result)
n = int(input())
a = sorted(map(int,input().split()))
b = []
for i in range(n-1):
    c = a[i+1]-a[i]
    if c >= 0:
        b.append(c)
print(sum(b))
from sys import stdin
input = stdin.readline

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

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

print(ans)
n=int(input())
a=list(map(int,input().split()))

ans=0

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

print(ans)
#中身の数
n = int(input())
#リスト
a = list(map(int,input().split()))
#過去最大
p = 0
#前が使った土
q = 0

for i in range(n-1):
  #前の人との差
  e = a[i+1]-a[i]-q
  if e>0:
    if e>q:
      q = 0
    else:
      q -= e
  else:
    if p < q-e:
      p = q-e
      q = p
    else:
      q = q-e
    
  
print(p)
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))
stool = 0
for i in range(N):
    for j in range(i+1,i+2):
        if j >= N:
            break
        if A[i] > A[j]:
            stool += A[i] - A[j]
            A[j] += 1
            continue


print(stool)
n = int(input())
a = list(map(int, input().split()))
Max = a[0]
ans = 0
for i in range(n-1):
    if a[i] < a[i+1]:
        Max = a[i+1]
    else:
        ans += Max-a[i+1]
print(ans)
N = int(input())
lst = list(map(int, input().split()))
lst2 = sorted(lst, reverse=True)

l_count = N
count = 0

for i in lst2:
    k_index = lst.index(i)
    count += (l_count - k_index) * i
    l_count = k_index

for x in lst:
    count -=x
        
print(count)
n = int(input())
a = list(map(int,input().split()))
s = a[0]
ans = 0
for i in range(1,n):
  ans += max(0,a[i]-s)
  s = max(s,a[i])
print(ans)
def main():
    n = int(input())
    a = list(map(int, input().split()))
    cnt = 0
    for i in range(0, n-1):
        if a[i] < a[i+1]:
            step = a[i+1] - a[i]
            cnt = cnt+step
               
    print(cnt)
main()
N = int(input())
L = list(map(int, input().split()))
sum = 0
for i in range(N):
    if L[i-1]>L[i]:
        sum += L[i-1] - L[i]
        L[i] = L[i-1]
print(sum)
N = int(input())
A = list(map(int,input().split()))
ans = 0
for i in range(N):
  if(i == 0):
    pass
  else:
    if(A[i] - A[i-1] <= 0):
      pass
    else:
      tmp = A[i] - A[i-1]
      ans += tmp
      A[i] += tmp
print(ans)
N=int(input())
A=[int(_) for _ in input().split(" ")]

ans=0

max=max(A)

a=A.index(max)
tmp=0

for i in range(a):
  if tmp < i:
    tmp=i

  
total=0
for i in range(a):
  total += a - A[i]
  
for i in range(a,len(A)):
  total += max -A[i]


print(total)
n=int(input())
a_list=list(map(int,input().split()))
ans=0
tmp=a_list[0]
for i in range(n-1):
    if a_list[i]>=a_list[i+1]:
        #print(tmp,ans)
        ans+=tmp-a_list[i+1]
    else:
        tmp=a_list[i+1]
print(ans)
N = int(input())
lst = list(map(int, input().split()))

l_count = N
count = 0

for i in lst:
    k_index = lst.index(i)
    
    if k_index < l_count:
        count += (l_count - k_index) * i
        l_count = k_index

for x in lst:
    count -=x
        
print(count)
N = int(input())
A = [int(z) for y, z in enumerate(input().split()) if y < N and z.isdigit()]
a = min(A)
b = max(A)
c = b - a
print(c)