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.



Sample input:
5
2 1 5 4 3


Sample output:
4

Submission status: Runtime Error

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

x = A[0]
ans = abs(A[0] - A[1])
y = 0

for i in range(2,N):
    B = A[0:i]
    y = max(B)
    if A[i] < y:
        ans += y - A[i]
    

print(ans)

Submission status: Runtime Error

Solution code:
n = input()
a = list(map(int, input().split()))
max_a_list = [0]*n
max_a_list[0] = a[0]

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

Submission status: Runtime Error

Solution code:
n = input()
a = list(map(int, input().split()))
max_a_list = [0]*n
max_a_list[0] = a[0]

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

Submission status: Runtime Error

Solution code:
'''
Problem Link - https://atcoder.jp/contests/abc176/tasks/abc176_c
'''
from sys import stdin,stdout
from math import *
from collections import *

mod = 1000000007

def gcd(a,b):
	while b:
		a,b = b,a%b
	return a

def lcm(a,b): return (a*b) // gcd(a,b)

def set_bits(X):
	c = 0
	while X:
		X &= (X-1);c += 1
	return c

def compute_MOD(N,M): return (N%M + M) % M

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

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

def get_input(): return stdin.readline().strip()

def main():
    tc = get_int()
    # while(tc):
	arr = get_array()
	ans = 0
	Max = arr[0]
	for i in arr[1:]:
		Max = max(Max,i)
		ans += Max-i
	stdout.write(str(ans)+'\n')
    	# tc-=1

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
'''
Problem Link - https://atcoder.jp/contests/abc176/tasks/abc176_c
'''
from sys import stdin,stdout
from math import *
from collections import *

mod = 1000000007

def gcd(a,b):
	while b:
		a,b = b,a%b
	return a

def lcm(a,b): return (a*b) // gcd(a,b)

def set_bits(X):
	c = 0
	while X:
		X &= (X-1);c += 1
	return c

def compute_MOD(N,M): return (N%M + M) % M

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

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

def get_input(): return stdin.readline().strip()

def main():
    tc = get_int()
    while(tc):
    	arr = get_array()
    	ans = 0
    	Max = arr[0]
    	for i in arr[1:]:
    		Max = max(Max,i)
    		ans += Max-i
    	stdout.write(str(ans)+'\n')
    	tc-=1

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
a=int(input())
b=list(map(int,input().split()))
c=0
for i in range(a):
  if b[i]>b[i+1]:
    b[i+1]=b[i+1]+1
    c=c+1
print(c)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
inputs = input().split()
N = int(inputs[0])
A = list(map(int, inputs[1:]))

sum = 0

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

Submission status: Runtime Error

Solution code:
inputs = input().split()
N = int(inputs[0])
A = list(map(int, input[1:]))

sum = 0

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

Submission status: Runtime Error

Solution code:
inputs = input().split()
N = int(inputs[0])
A = list(map(int, input[1:]))

sum = 0

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
MOD=10**9+7
c=0
for i in range(len(A)):
  c+=A[i]*(pow(sum(A)-A[i],-1,MOD)
print(c//2%MOD)

Submission status: Runtime Error

Solution code:
n=int(input())

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

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

print(s)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

print(ans)

Submission status: Runtime Error

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

print(ans)

Submission status: Runtime Error

Solution code:
pre = 0
max_chair = 0
list_chair = []
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))

Submission status: Runtime Error

Solution code:
N=int(input())
A=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)

Submission status: Runtime Error

Solution code:
N=int(input())
A=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

print(sum)

Submission status: Runtime Error

Solution code:
n = int(input())
a_list = list(map(int, input().split()))
result = [0]
for i in range(n - 1):
    if a_list[i] + result[i] > a_list[i + 1]:
        result.append(a_list[i] + result[i] - a_list[i + 1])
print(sum(result))

Submission status: Runtime Error

Solution code:
n=int(input)
string=input()
count=0;
ls=string.split();
for i in range(len(ls)):
  ls[i]=int(ls[i])
for j in range(len(ls)-1):
  if ls[j]>ls[j+1]:
    count+=1
printf(count)

Submission status: Runtime Error

Solution code:
ans = 0

for i in range(N - 1):
    if As[i] >As[i+1]:
        diff = As[i] - As[i+1]
        As[i +1] = As[i]
        ans += diff
    else:
        pass
    
print(ans)

Submission status: Runtime Error

Solution code:
N = input()
A = list(map(int,input().split()))
Sum = 0

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

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
Sum = 0

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

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
Sum = 0

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

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input.split()))
Sum = 0

for i in range(N-1):
  Sum += A[i+1] - A[i]
 
print(Sum)

Submission status: Runtime Error

Solution code:
 = int(input())
list1 = list(map(int, input().split()))
h,c = 0,0
for i in list1:
    if i < h:
        c += h - i
    else:
        h = i
print(c)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input()))

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)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input()))

ans=0

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

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    count = 0
    max_height = 0

    for height in A:
        if max_height < height:
            max_height = height
        else:
            count += max_height - height
    print(count)


if __name__ == '__

Submission status: Runtime Error

Solution code:
    k = input()
    l = list(map(int,input().split(' ')))
    c = 0
    for i in range(len(l)-1):
      x = l[i+1]-lis[i]
      if x<0:
        l[i+1]+=abs(x)
      	c+=abs(x)
    print(c)

Submission status: Runtime Error

Solution code:
k = input()
l = list(map(int,input()))
c = 0
for i in range(len(l)-1):
  x = l[i+1]-lis[i]
  if x<0:
    l[i+1]+=abs(x)
  	c+=abs(x)
print(c)

Submission status: Runtime Error

Solution code:
N = int(input())
heights = list(map(int, input().split()))
before = 0
answer = 0

for h in heights:
  if h < before:
    answwer += before - h
  else:
    before = h
print(answer)

Submission status: Runtime Error

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

sum = 0
for n in range(N-1):
  if a[n]>a[n+1]:
    dif=a[n]-a[n+1]
    a[n+1]=a[n+1]+dif
    sum+=dif
print(sum)

Submission status: Runtime Error

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

sum = 0
for n in range(N-1):
  if a[n]>a[n+1]:
    dif=a[n]-a[n+1]
	a[n+1]=a[n+1]+dif
	sum=sum+dif
print(sum)

Submission status: Runtime Error

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

sum = 0
for n in range(N-1):
	if a[n]>a[n+1]:
		dif=a[n]-a[n+1]
		a[n+1]=a[n+1]+dif
		sum=sum+dif
print(sum)

Submission status: Runtime Error

Solution code:
N = input()
A = list(map(int, input().split()))
c = 0

a = A.index(max(A))

while a != 0:
  for n in A[a+1:]:
    c += (max(A) - n)
    del A[a:]
    a = A.index(max(A))
    
print(c)

Submission status: Runtime Error

Solution code:
N=int(input())
A = list(map(int, input().split()))
i = 0
sum = 0
while i<N:
  if A[i]<=A[i+1]:
    f=0
  else:
    f=A[i]-A[i+1]
  A[i+1]+=f
  sum+=f
  i+=1
print(sum)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input()))
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)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
max_a = max(a)
max_b = max(b)
ans = max_a - max_b
print(ans)

Submission status: Runtime Error

Solution code:
from sys import exit
n = int(input())
a = list(map(int, input().split()))
if n==1: print(0); exit()
al = [0 for _ in range(n)]
for index in range(n-1):
	person = a[index]
	person_behind = a[index+1]
	if person_behind < person:
		k = person - person_behind
		a[index+1] += k
		al[person_behind] = k
print(sum(al))

Submission status: Runtime Error

Solution code:
from sys import exit
n = int(input())
if n==1: print(0); exit()
a = list(map(int, input().split()))
al = [0 for _ in range(n)]
for index in range(n-1):
	person = a[index]
	person_behind = a[index+1]
	if person_behind < person:
		k = person - person_behind
		a[index+1] += k
		al[person_behind] = k
print(sum(al))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
s = [input() for i in range(N)]
t = [0]*(N-1)
 
for n in range(N-1):
  t[n] = s[n] - s[n+1]
  if t[n] <= 0: 
    continue
  else:
    s[n+1] += t[n]
 
print(min(t))

Submission status: Runtime Error

Solution code:
N = int(input())
s = [input() for i in range(N)]
t = [0]*(N-1)

for n in range(N-1):
  t[n] = s[n] - s[n+1]
  if t[n] <= 0: 
    continue
  else:
    s[n+1] += t[n]

print(min(t))

Submission status: Runtime Error

Solution code:
N = int(input())
s = [input() for i in range(N)]

print(N, s)

Submission status: Runtime Error

Solution code:
n = int(input())
a = [map(int,input().split())]
 
total = 0
m = 0
 
for x in a:
  if m > x:
    total += m - x
  m =max(m,x)
  
print(total)

Submission status: Runtime Error

Solution code:
n = int(input())
a = [map(int,input().split())]

total = 0
m = a[0]

for x in a:
  if m > x:
    total += m - x
  m =max(m,x)
  
print(total)

Submission status: Runtime Error

Solution code:
n=int(input())
l=map(int,input().spliut())
max=l[0]
c=0
for x in l:
    if max <x:
        max=x
    else:
        c+=(max-x)
print(c)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
n = int(readline())
a = list(map(int, readline().split()))
max_l = max(a)
ans = 0
for i in range(n):
    if i == 0 and max_l:
        continue
    elif i < max_l:
        ans += 1
    else:
        ans = 0
print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**9)

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


def func(a, cnt=0):
    global count
    for i in range(len(a)-1):
        if a[i] > a[i+1]:
            a[i+1] += 1
            cnt += 1
            count = max(cnt, count)
            func(a, cnt)
        else:
            continue
    return count


COUNT = func(A)
print(COUNT)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
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]
print(ans)

Submission status: Runtime Error

Solution code:
s = 0
now = As[0]
for a in As:
    if a<now:
        s += now - a
    else:
        now = a
        
print(s)

Submission status: Runtime Error

Solution code:
N=input()
A=list(int,input().split())
total=0

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

Submission status: Runtime Error

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

dai=[0, 0, 0, 0, 0]
for i, l in enumerate(B):
  if i==0:
    continue
  if B[i-1]-B[i]>0:
    dai[i]=B[i-1]-B[i]
    B[i]+=B[i-1]-B[i]

print(sum(dai))

Submission status: Runtime Error

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

dai=[0, 0, 0, 0, 0]
for i, l in enumerate(B):
  if i==0:
    continue
  if B[i-1]-B[i]>0:
    dai[i]=B[i-1]-B[i]
    
print(sum(dai))

Submission status: Runtime Error

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

dai=[0, 0, 0, 0, 0]
for i, l in enumerate(B):
  if i==0:
    continue
  if B[i-1]-B[i]>0:
    dai[i]=B[i-1]-B[i]
    #B[i]+=B[i-1]-B[i]
    
print(sum(dai))

Submission status: Runtime Error

Solution code:
if __name__=="__main__":
  N=int(input())
  x=[int(i) for i in input().split()]
  ans+=0
  for i in range(1,len(x)):
    if x[i]<x[i-1]:
      ans+=(x[i-1]-x[i])
      x[i]+=ans
  print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
A = list(map(int, input().split()))
#print(A)
count=0
count2=0
for i in range(len(A)-1):
    #print(A[i])
    if A[i]>A[i+1]:
        count=A[i]-A[i+1]
        #print(count)
        A[i+1]=A[i]
        count2+=count

count2+=A[-2]-A[-1]
print(count2)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input()))

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

print(ans)

Submission status: Runtime Error

Solution code:
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 A[i] < hihg:
    ans += high - A[i]
    
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

a = []

for i in range(n):
    a.append(list(map(int,input().split())))

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

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input().rstrip())

a = []

for i in range(n):
    a.append(list(map(int,input().split())))

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

print(ans)

Submission status: Runtime Error

Solution code:
item = input().split()
fumidai_sum = 0

for i in range(int(item[0])):
  b = int(item[i])
  t = int(item[i + 1])
  
  if b > t:
    fumidai_sum += (b - t)
      
print(fumidai_sum)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
A = list(map(int,input().split()))
ans = 0

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

print(ans)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
# AtCoder Beginner Contest 176
# C - Step

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

ans=0

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

Submission status: Runtime Error

Solution code:
N = input()
A = map(int, input().split())
sum = 0
pre = 0
for ai in A:
  if pre > ai:
    sum += pre - ai
  else:
    pre = ai
print(sum

Submission status: Runtime Error

Solution code:
# AtCoder Beginner Contest 176
# C - Step

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

ans=0

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

Submission status: Runtime Error

Solution code:
N = int(input())
an = list(map(int,input().split()))
solve = []

ans = 0
maxnum = 0

for i in range(1,N):
    if maxnum < an[i]:
        ans += max(an[maxnum:i+1]) - an[i]
        maxnum = an[i]
    if maxnum >= an[i]:
        ans += maxnum - an[i]
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = map(int,input().split())
a = list(set(a)).sort()
max = 0
for i in range(len(a)-1):
  if (a[i]-a[i-1]>max):
    max = a[i]=a[i-1]
print(max)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
a=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)

Submission status: Runtime Error

Solution code:
N = int(input())
an = list(map(int,input().split()))
solve = []

ans = 0
maxnum = 0

for i in range(N):
    if maxnum < an[i]:
        ans += max(an[maxnum:i+1]) - an[i]
        maxnum = an[i]
    if maxnum >= an[i]:
        ans += maxnum - an[i]
print(ans)

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
	}

	long long ans = 0;
	int MaxNum = 0;
	for (int i = 0; i < N-1; i++)
	{
      if(A[i]>=A[i+1])
		ans += A[i]-A[i+1];
      A[i+1]=A[i]
	}

	cout << ans << endl;
}

Submission status: Runtime Error

Solution code:
N = int(input())
an = list(map(int,input().split()))
solve = []

ans = 0
maxnum = 0

for i in range(1,N):
    print(str(maxnum)+'is maxnum' +str(i))
    if maxnum < an[i]:
        ans += max(an[maxnum:i+1]) - an[i]
        maxnum = an[i]
    if maxnum >= an[i]:
        ans += maxnum - an[i]
    print(str(ans) + 'is ans'+str(i))
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a_L = list(map(int,input().split()))


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)

Submission status: Runtime Error

Solution code:
N = input()
tmp = 0
while N > 0:
    tmp += (N % 10)
    N /= 10
if tmp % 9 == 0:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
n = int(input())
a = lsit(map(int,input().split()))

stack = [a[0]]
s = 0
for i in range(1,n):
    if a[i]<stack[-1]:
        s = s + abs(a[i] - stack[-1])
    else:
        stack.append(a[i])
print(s)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math

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

print(cnt)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> v(N);
  for(int i = 0;i < N; i++){
    cin >> v[i];}
  long long ans = 0;
  int Max = 0;
  for(int i=0; i<N; i++){
	Max = max(Max,v[i]);
    int Bi = Max;
    ans += Bi - v[i];
  }
  cout << ans << endl; 
}

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> v(N);
  for(int i = 0;i < N; i++){
    cin >> v.at(i);}
  long long ans = 0;
  int Max = 0;
  for(int i=0; i<N; i++){
	Max = max(Max,v.at(i));
    int Bi = Max;
    ans += Bi - v.at(i);
  }
  cout << ans << endl; 
}

Submission status: Runtime Error

Solution code:
import math

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

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

Print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = input().split()
count = 0
for i in range(N-1):
  if A[i] > A[i+1]:
    count += A[i+1] - A[i]
    A[i+1] = A[i]

print(count)

Submission status: Runtime Error

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

stage_hight = []
for i, ai in enumerate(A):
	if not i and ai < A[i-1]:
		stage_hight.append(A[i-1] - ai)
		A[i] = A[i-1]
print(sum(stage_hight))

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
t = 0

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

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
t = 0

for i in range(n):
  if i ==n-1:
    break
  else:
  	if a[i] <= a[i + 1]:
    	path
  	else:
    	t += a[i] - a[i + 1]
    	a[i] = a[i + 1]
    
print(t)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
t = 0

for i in range(n):
  if i ==n-1:
    break
  else:
  	if a[i] <= a[i + 1]:
    	continue
  	else:
    	t += a[i] - a[i + 1]
    	a[i] = a[i + 1]
    
print(t)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
t = 0

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

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
t = 0

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

Submission status: Runtime Error

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

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

print(ans)

Submission status: Runtime Error

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

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

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
heights = map(int, input())

current_highest = heights[0]
steps_sum = 0
for h in heights[1:]:
  if h > current_highest:
    current_highest = h
  else:
    steps_sum += h - current_highest

print(steps_sum)

Submission status: Runtime Error

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

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

print(x)

Submission status: Runtime Error

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

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

print(x)

Submission status: Runtime Error

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

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

print(x)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
A = list(map(int,input().split()))
min = 0
for i in range(N):
    if(i > 0) :
        if np.max(A[:i]) - A[i] > 0:
            min = min + np.max(A[:i]) - A[i]
print(min)

Submission status: Runtime Error

Solution code:
import numpy as np

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

s = 0

def step(a, s):
    am = np.argmax(a)
    s = s + np.max(a)*a[am+1:].shape[0] - np.sum(a[am+1:])

    if am == 0:
        return s
    else:
        return step(a[:am], s)

print(step(A, s))

Submission status: Runtime Error

Solution code:
N,*A=map(int,input().split())
m=max(A)
s=sum([m-a for a in A])
print(s)

Submission status: Runtime Error

Solution code:
n=int(input())

sum==0

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

for i in range(a):
  if int(i) > int(i+1):
    sum+=int(i)-int(i+1)
  else:
    sum+=0
 
 print(sum)

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(input()) for i in range(1, n+1)]
b = 0

if a[i-1]>a[i]:
  b += a[i-1]-a[i]
  a[i] = a[i-1]
else:
  b += 0

print(b)

Submission status: Runtime Error

Solution code:
_ = input()
li = list(map(int,input().split()))
ans=0
 
while li!=[] and li!=sorted(li):
    maxValue = max(li)
    maxLocation = li.index(maxValue)
    li_removed = li[maxLocation:]
    li_removed.sort()
    li = li[:maxLocation]
    maxLocation2 = li_removed.index(maxValue)
    li_calculate = li_removed[:maxLocation2]
    
    for i in li_calculate:
        ans = ans + (maxValue - i)
        
    j = len(li)    
    while len(li)>0 and lis[j-1]>=lis[j-2]:
        li = li[0:j-2]
        j-=1
        
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())

sum=0

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

for i in range(a):
  if int(i) > int(i+1):
    sum+=int(i)-int(i+1)
  else:
    sum+=0
 
 print(sum)

Submission status: Runtime Error

Solution code:
N=int(input())
A=input()
count=0
Ai=[]
for i in range(N):
  Ai.append(int(A[2*i]))
  if i>=1 and Ai[i]<Ai[i-1]:
    while Ai[i]<Ai[i-1]:
      Ai[i]+=1
      count+=1
print(count)

Submission status: Runtime Error

Solution code:
N = int(input().rstrip())
line = input().rstrip().split(" ")
aimae = line[0] #比較用Ai-1
counter = 0

#counterlistに数字を入れる
for i in range(N - 1):
  ai = int(line[i + 1]) #Ai
  while ai < aimae:
    ai += 1
    counter += 1
  aimae = ai

print(counter)

Submission status: Runtime Error

Solution code:
n=int(input())

sum=0

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

for i in range(a):
  if i > i+1:
    sum+=i-i+1
  else:
    sum+=0
 
 print(sum)

Submission status: Runtime Error

Solution code:
from numpy import max
from array import array
def main():
  n = int(input())
  As = list(map(int, input().split()))
  r = 0
  max_a = max(array('L', As))
  for i in range(n-1, 0, -1):
    if i == 0:
      break
    if As[i] < As[i-1]:
      if(max_a not in As[0:i-1]):
        max_a = As[i-1]
      r += max_a - As[i]
  print(r)

main()