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: Wrong Answer

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

Submission status: Wrong Answer

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(sum(s))

Submission status: Wrong Answer

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(sum(s))

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
S=0
i=N
while i>1:
    saidai=max(A[0:i])
    S +=(i-A.index(saidai))*saidai
    i=A.index(saidai)
print(S-sum(A))

Submission status: Wrong Answer

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

tmax = A[0]
humidai = 0
humidai_sum = 0

for a in A :
  print("tmax:"+str(tmax)+"_a:"+str(a))
  if tmax > a:
    humidai = tmax - a
    humidai_sum += humidai
    tmax = humidai + a
  else :
    tmax = a
    
print(humidai_sum)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
m=max(a)
cnt=0
for i in range(n):
	if a[i]!=m:
		cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
def main():
  N = int(input())
  A = list(map(int, input().split()))
  
  i = A[0]
  T = 0
  
  for n in A:
    if n > i:
      T += n -i
    if n < i:
      T = i
  
  print(T)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
x=list(map(int, input().split()))
length=len(x)
count=0
sum1=0
sum2=0
for i in range(0,len(x)-1):
    if(x[i] == x[i+1]):
        count=0
    elif(x[i]>x[i+1]):
        diffrence=x[i]-x[i+1]
        sum1+=diffrence
        count+=1
    elif(x[i]<x[i+1]):
        diffrence=x[i]-x[i+1]
        sum2+=diffrence
        count-=1
if(count==0):
    print(0)

elif(count>1):
    print(sum1)
elif(count<1):
    print(sum2)

Submission status: Wrong Answer

Solution code:
n=int(input())
x=list(map(int, input().split()))
length=len(x)
count=0
sum1=0
sum2=0
for i in range(0,len(x)-1):
    if(x[i] == x[i+1]):
        count=0
    elif(x[i]>x[i+1]):
        diffrence=x[i]-x[i+1]
        sum1+=diffrence
        count+=1
    elif(x[i]<x[i+1]):
        diffrence=x[i]-x[i+1]
        sum2+=diffrence
        count-=1
if(count==0):
    print(0)

elif(count>1):
    print(sum1+1)
elif(count<1):
    print(sum2+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split( )))
front = 0
step = 0
for height in a :
    x = 0
    if front > height :
        x = front - height
        step += x
    print(front, height, x)
    if front < height:
        front = height
print(step)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i, h in enumerate(a):
    if i == 0:
        continue
    ans += max(0, a[i - 1] - h)
print(ans)

Submission status: Wrong Answer

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

for i in range(1, len(A)):
  if A[i] < h:
    S += (h - A[i])
    h = A[i-1]
  else:
    h = A[i]

print(S)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/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()

Submission status: Wrong Answer

Solution code:
n=int(input())
l=map(int,input().split())
ans=0
maxt=0
for i in l:
  if i<maxt:
    ans+=maxt-i
    maxt=max(i,maxt)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
ans=0
maxt=0
for i in l:
  if i<maxt:
    ans+=maxt-i
    maxt=max(i,maxt)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=map(int,input().split())
ans=0
maxt=0
for i in l:
  if i<maxt:
    ans+=maxt-1
    maxt=max(i,maxt)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
ans=0
maxt=0
for i in l:
  if i<maxt:
    ans+=matx-1
    maxt=max(i,maxt)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
l=list(map(int,input().split()))
ans=0
max=0
for i in l:
  if i<max:
    ans+=max-1
    max=max(i,max)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

steps = []
step_ttl = 0
step = 0
for i, a in enumerate(a_list):
  if i == 0:
    steps.append(step)
    continue
  if a_list[i-1] + step < a:
    step = 0
    steps.append(step)
    continue
  if a < step + a_list[i-1]:
    step = (step + a_list[i-1]) - a
  step_ttl += step
  steps.append(step)

print(step_ttl)
print(steps)

Submission status: Wrong Answer

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

step_ttl = 0
step = 0
for i, a in enumerate(a_list):
  if i == 0:
    continue
  if a_list[i-1] < a:
    step = 0
    continue
  if a < step + a_list[i-1]:
    step = (step + a_list[i-1]) - a
  step_ttl += step
  

print(step_ttl)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))

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

Submission status: Wrong Answer

Solution code:
max_tool=0
n=int(input())
arr=list(map(int,input().split()))
maxi=arr[0]
for i in range(1,len(arr)):
  if arr[i]<maxi:
    max_tool=max(max_tool,maxi-arr[i])
  else:
    maxi=arr[i]
print (max_tool)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
A = list(map(int, input().split()))
#print(A)
count=0
count2=0

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

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: Wrong Answer

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] < high:
        high += high - A[i]

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

#current height
now = 0
total = 0

for a in A:
    print(type(a))
    if a >= now:
        now = a
        pass
    else:
        total += now - a

print(total)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

item = input().split()
total_num = item[0]
fumidai_sum = 0
before_tall = 0

for idx, tall in enumerate(item[1:]):
  tall = int(tall)
  
  if idx == 0:
    before_tall = tall
    continue
  else:
    if before_tall > tall:
      fumidai_sum += (before_tall - tall)
    else:
      before_tall = tall
      
print(fumidai_sum)

Submission status: Wrong Answer

Solution code:
n = input()
print(n)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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+= abs(max(Als[0:i])-Als[i])

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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: Wrong Answer

Solution code:
N = int(input())
array = list(map(int,input().split()))
new_array = [0] * N


for i in range(N-1):
    if array[i] > array[i+1]:
        new_array[i+1] = array[i]
print(sum(array) - sum(new_array))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(A[N - 1] - A[0])

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

Solution code:

N = int(input())#整数
A = list(map(int, input().split()))#配列Int型

ans = 0
max_val = A[0]

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

Submission status: Wrong Answer

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

h_sum  = 0

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

print(h_sum)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(ans)

if a_L[-2] > a_L[-1]:
    ans += abs(a_L[-1]-a_L[-2])
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

tall = a_L[0]
ans = 0
diff = 0
for i in range(1,len(a_L)):
    if tall < a_L[i]:
        diff = abs(tall - a_L[i])
        tall = a_L[i]
    else:
        tall = a_L[i]
        diff = 0
    ans += diff
print(ans)

Submission status: Wrong Answer

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

ans = 0
maxnum = 0

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,*a=map(int,open(0).read().split())
ma=a[0]
ans=0
for q in a:
  if q>ma:
    ans+=(q-ma)
  ma=q
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
k=map(int,input().split())
p=sorted(k)
print(p[-1]-p[0])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
row = list(map(float, input().split()))
ans = 0
for index in range(1,n):
  if row[index] < row[index - 1]:
    ans += row[index - 1] - row[index]
    row[index] = row[index - 1]
print(ans)

Submission status: Wrong Answer

Solution code:
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]:
        B_list.append(A_high_list[n-1])
        s = max(B_list) - A_high_list[n]
        Fumidai += s
    else:
        continue

print(Fumidai)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)


def solve(N: int, A: "List[int]"):
    ret = 0
    for i in range(1, N):
        tmp = max(0, A[i] - A[i - 1])
        A[i] += tmp
        ret += tmp
    print(ret)
    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))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

sum = 0
step =0


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


for i in range(len(As)):
    print(As[i],end=" ")
else:
    print("")
print(sum)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
count = 0
i = 1
for i in range(N-1):
  if a[i-1] <= a[i]:
    continue
  elif a[i-1] > a[i]:
    diff = a[i-1] - a[i]
    count = count + diff
    a[i] = a[i-1]
print(count)

Submission status: Wrong Answer

Solution code:
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]
            As[i + 1] += step
            sum += step 
except IndexError:
    pass


for i in range(len(As)):
    print(As[i],end=" ")
else:
    print("")
print(sum)

Submission status: Wrong Answer

Solution code:
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]
            a[i] = a[i] + step
            cnt = cnt+step

    print(cnt)
main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
height = list(map(int,input().split()))
ans = 0

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

Submission status: Wrong Answer

Solution code:


if __name__ == "__main__":
    n = int(input())
    x =list((int(x) for x in input().split()))
    print(x)
    
    tmp1 = 0
    tmp2 = x[0]
    for i in range(1,n):
        if tmp2 > x[i]:
            tmp3 = tmp2 - x[i]
            tmp1 += tmp3

            x[i] = x[i] + tmp3
            tmp2 = x[i]
        else:
            tmp1 += 0
            tmp2 = x[i]

    print(tmp1)

Submission status: Wrong Answer

Solution code:
N = int(input())
height = list(map(int,input().split()))
ans = 0

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

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    n = int(input())
    x =list((int(x) for x in input().split()))
    print(x)
    
    tmp1 = 0
    tmp2 = x[0]
    for i in range(1,n):
        if tmp2 > x[i]:
            tmp3 = tmp2 - x[i]
            tmp1 += tmp3

            x[i] = x[i] + tmp3
            tmp2 = x[i]
        else:
            tmp1 += 0

    print(tmp1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
count=0
for i in range(1,len(A)):
  for j in range(i,0):
    if(a[j]<a[i]):
      count+=(abs(a[i]-a[j]))
    else:
      pass
print(count)

Submission status: Wrong Answer

Solution code:
total = int(input())
tall = list(map(int, input().split()))
dif = 0
for i in range(total - 1):
    if tall[i] > tall[i+1]:
        var = tall[i] - tall[i+1]
        tall[i+1] += var
        dif += var
    else:
        pass
print(dif)
print(tall)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

print(sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import stdin


length = int(stdin.readline())
heights = stdin.readline().split(" ")

stool = 0
for i in range(1, length):
  if heights[i-1] > heights[i]:
    stool += (int(heights[i-1]) - int(heights[i]))
    heights[i] = heights[i-1]
print(int(stool))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a= int(input())
mod = a%9
if mod==0:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    n = int(input())
    x =list((int(x) for x in input().split()))
    print(x)
    
    tmp1 = 0
    tmp2 = x[0]
    for i in range(1,n):
        if tmp2 > x[i]:
            tmp3 = tmp2 - x[i]
            tmp1 += tmp3

            x[i] = x[i] + tmp3

    print(tmp1)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n = int(input())
    a = list(map(int, input().split()))
    idx_start = 0
    sum_a = 0
    ans = 0
    len_a = len(a)

    for i in range(1, len_a):
        if a[idx_start] < a[i]:
            ans += ((i - idx_start) * a[idx_start]) - sum_a
            idx_start = i
            sum_a = 0
        else:
            sum_a += a[i]
            if i == len_a - 1:
                ans += ((i - idx_start) * a[idx_start]) - sum_a
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n = int(input())
    a = list(map(int, input().split()))
    idx_start = 0
    sum_a = 0
    ans = 0
    len_a = len(a)
    for i in range(1, len_a):
        if a[idx_start] < a[i]:
            ans += ((i - 1) * a[idx_start]) - sum_a
            idx_start = i
            sum_a = 0
        else:
            sum_a += a[i]
            if i == len_a - 1:
                ans += ((i - idx_start) * a[idx_start]) - sum_a
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import stdin


length = int(stdin.readline())
heights = list(stdin.readline().replace(" ", ""))

stool = 0
for i in range(1, length):
  if heights[i-1] > heights[i]:
    stool += (int(heights[i-1]) - int(heights[i]))
    heights[i] = heights[i-1]
print(int(stool))

Submission status: Wrong Answer

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

high_sum = 0

for x in range(int(N)):
    if lists[x - 1] < lists[x]:
        a = lists[x] - lists[x - 1]
        high_sum += a
    else:
        continue
        
print(high_sum)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int,input().split()))
smaller = min(l)
smaller_index=l.index(smaller)
taller = max(l)
taller_index = l.index(taller)
largesmall = l[0]
stool=0
if(all(elem == l[0] for elem in l)):
    print(0)
else:
    for i in range(smaller_index+1):
        if(largesmall<l[i]):
            largesmall=l[i]
    for j in range(smaller_index+1):
        m=largesmall-smaller
        if(largesmall!=l[j]):
            l[j]+=m
            stool+=1
    for k in range(taller_index+1,len(l)):
        b=taller-l[k]
        l[k]+=b
        stool+=b
    print(stool)

Submission status: Wrong Answer

Solution code:
N = int(input())
A_high_list = list(map(int,input().split()))
B_list = [A_high_list[0]]
Fumidai = 0
s = 0

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

print(Fumidai)

Submission status: Wrong Answer

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

high_sum = 0

for x in range(int(N)):
    if lists[x - 1] < lists[x]:
        a = lists[x] - lists[x - 1]
        high_sum += a
    else:
        continue
        
print(high_sum)

Submission status: Wrong Answer

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

h_list = [0]*(n+10)

for i in range(1,len(a_list)):
    if a_list[i] < a_list[i-1]:
        h_list[i] = a_list[i-1] + h_list[i-1] - a_list[i] 
    elif a_list[i] >= a_list[i-1]:
        h_list[i] = 0
        
print(sum(h_list))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(input().split())
An = [int(num) for num in A]
print(An)

sum = 0

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

Submission status: Wrong Answer

Solution code:
n = input()
s = list(map(int, input().split()))
if all(s):
    print(0)
else:
    print(max(s[(s.index(max(s))+1):]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
lst = []
count = 0
n = int(input())
lst = list(map(int, input().split(' ')[:n]))
for j in range(len(lst)-1):
    if lst[j]<lst[j+1]:
        count = count + (lst[j+1]-lst[j])
    else:
        count = count - (lst[j+1]-lst[j])
print(count)

Submission status: Wrong Answer

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