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

high_sum = 0

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

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(200000)
def f(i,ans,l,t):
  if (i+1) == (len(l)-1):
    if (ans+l[i]) > l[i+1]:
      ans = ans + l[i]-l[i+1]
      return t+ans
    else:
      return t
  else:
    if (ans+l[i]) > l[i+1]:
      ans = ans + l[i]-l[i+1]
      return f(i+1,ans,l,t+ans)
    else:
      return f(i+1,0,l,t)
n = input("")
an = input("").split(" ")
ani = [int(a) for a in an]
if len(ani) == 1:
  print("0")
else:
  print(str(f(0,0,ani,0)))

Submission status: Runtime Error

Solution code:
n = int(input())
num_list = list(map(int, input().split()))
a = 0
x = 0
y = 1
b = num_list[x]
c = num_list[y]
for _ in num_list:
    d = c - b
    if d < 0:
        a += abs(d)
    x += 1
    y += 1
    b = num_list[x]
    c = num_list[y]
    b += abs(d)
    if y == n - 1:
        break
if a == 0:
    print(a)
else:
    print(a - 1)

Submission status: Runtime Error

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

high_sum = 0

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())

sum=0
i=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 = []
for i in range(n):
    a[i] = int(input())
    
b = []
for j in range(n-1):
    b[j] = a[j+1]

count = 0
for k in range(n-1):
    if b[k] - a[k] < 0:
        count = abs(b[k] - a[k])

print(count)

Submission status: Runtime Error

Solution code:
n = int(input())
num_list = list(map(int, input().split()))
a = 0
x = 0
y = 1
b = num_list[x]
c = num_list[y]
for _ in num_list:
    d = c - b
    if d < 0:
        a += abs(d)
    x += 1
    y += 1
    b = num_list[x]
    c = num_list[y]
    b += abs(d)
    if y == n - 1:
        break
print(a)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())

sum=0
i=0

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

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

Submission status: Runtime Error

Solution code:
def f(i,ans,l,t):
  if (i+1) == (len(l)-1):
    if (ans+l[i]) > l[i+1]:
      ans = ans + l[i]-l[i+1]
      return t+ans
    else:
      return t
  else:
    if (ans+l[i]) > l[i+1]:
      ans = ans + l[i]-l[i+1]
      return f(i+1,ans,l,t+ans)
    else:
      return f(i+1,0,l,t)
n = input("")
an = input("").split(" ")
ani = [int(a) for a in an]
if len(ani) == 1:
  print("0")
else:
  print(str(f(0,0,ani,0)))

Submission status: Runtime Error

Solution code:
from sys import stdin


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

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

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

input = lambda: sys.stdin.readline().rstrip()

def solve(a):
    # a_max = max(a)
    # idx_max = a.index(a_max)
    idx_max = a.argmax()
    a_max = a[idx_max]
    return ((len(a) - 1 - idx_max) * a_max) - sum(a[idx_max + 1:]), idx_max

def solve2(a):
    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]:
            # return ((i - 1) * a[0]) - sum_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
    return ans

def main():
    n = int(input())
    a = np.array(list(map(int, input().split())))
    ans = 0
    # while(1):
    #     k, idx_max = solve2(a)
    #     ans += k
    #     if idx_max == len(a):
    #         break
    #     a = a[idx_max:]
    ans = solve2(a)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(x) for x in raw_input().split()[:N]]
temp = 0
overall = 0
# for i in range(N):
#     S = int(input())
#     A.append(S)
for i in range(0, len(A) -1 ):
    if A[i] > A[i+1]:
        temp = A[i] - A[i+1]
        A[i + 1] += 1
        overall += temp
print(overall)

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

x = 0
for i in range(n):
  while True:
    if a[i] > a[i + 1]:
      a[i + 1] += 1
      x += 1
    if a[i] <= a[i + 1]:
      break

print(x)

Submission status: Runtime Error

Solution code:
n=int(input())

sum=0
i=0

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

while i<n:
  if a[i] > a[i+1]:
    sum+=int(a[i]-a[i+1])
  else:
    sum+=0
  i+=1
 
 print(sum)

Submission status: Runtime Error

Solution code:
N = int(input())
A = map(int, raw_input().split())
temp = 0
overall = 0
# for i in range(N):
#     S = int(input())
#     A.append(S)
for i in range(0, len(A) -1 ):
    if A[i] > A[i+1]:
        temp = A[i] - A[i+1]
        A[i + 1] += 1
        overall += temp
print(overall)

Submission status: Runtime Error

Solution code:
n=int(input())
lst=[]
for i in range(n):
	lst.append(int(input()))
    if i>=1:
		if lst[i]<lst[i-1]:
			x=lst[i-1]-lst[i]
            count=count+x
            lst[i]=lst[i]+x
print(count)

Submission status: Runtime Error

Solution code:
n=int(input())

sum=0
i=0

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

while i<n:
  if a[i] < a[i+1]:
    sum+=int(a[i+1]-a[i])
  else:
    sum+=0
  i+=1
 
 print(sum)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list()
temp = 0
overall = 0
for i in range(N):
    S = int(input())
    A.append(S)
for i in range(0, len(A) -1 ):
    if A[i] > A[i+1]:
        temp = A[i] - A[i+1]
        A[i + 1] += 1
        overall += temp
print(overall)

Submission status: Runtime Error

Solution code:
def f(i,ans,l,t):
  if (i+1) == (len(l)-1):
    if (ans+l[i]) > l[i+1]:
      ans = ans + l[i]-l[i+1]
      return t+ans
    else:
      return t
  else:
    if (ans+l[i]) > l[i+1]:
      ans = ans + l[i]-l[i+1]
      return f(i+1,ans,l,t+ans)
    else:
      return f(i+1,0,l,t)
n = input("")
an = input("").split(" ")
ani = []
for b in an:
  if b != "" and b != " ":
    ani.append(int(b))
if len(ani) == 1:
  print("0")
else:
  print(f(0,0,ani,0))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

def solve(a):
    # a_max = max(a)
    # idx_max = a.index(a_max)
    idx_max = a.argmax()
    a_max = a[idx_max]
    return ((len(a) - 1 - idx_max) * a_max) - sum(a[idx_max + 1:]), idx_max

def solve2(a):
    sum_a = 0
    len_a = len(a)
    for i in range(1, len_a):
        if a[0] < a[i]:
            return ((i - 1) * a[0]) - sum_a, i
        else:
            sum_a += a[i]
            if i == len_a - 1:
                return (i * a[0]) - sum_a, i + 1

def main():
    n = int(input())
    a = list(map(int, input().split()))
    ans = 0
    while(1):
        k, idx_max = solve2(a)
        ans += k
        if idx_max == len(a):
            break
        a = a[idx_max:]
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

x = 0
for i in range(n):
  while Ture:
    if a[i] > a[i + 1]:
      a[i + 1] += 1
      x += 1
    if a[i] <= a[i + 1]:
      break

print(x)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

input = lambda: sys.stdin.readline().rstrip()

def solve(a):
    # a_max = max(a)
    # idx_max = a.index(a_max)
    idx_max = a.argmax()
    a_max = a[idx_max]
    return ((len(a) - 1 - idx_max) * a_max) - sum(a[idx_max + 1:]), idx_max

def solve2(a):
    idx_min = 0
    sum_a = 0
    len_a = len(a)
    for i in range(1, len_a):
        if a[0] < a[i]:
            return ((i - 1) * a[0]) - sum_a, i
        else:
            sum_a += a[i]
            if i == len_a - 1:
                return (i * a[0]) - sum_a, i + 1

def main():
    n = int(input())
    a = np.array(list(map(int, input().split())))
    ans = 0
    while(1):
        k, idx_max = solve2(a)
        ans += k
        if idx_max == len(a):
            break
        a = a[idx_max:]
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import random
N=input()
for n in range(1,N+1):
  A(n)=random.randint(1,N)

sum=0
for n in range(1,N+1):
  while A(n)>A(n+1):
    A(n+1)+=1
    sum+=1
    
print(sum)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
typedef pair<ii ,ii> iii;
typedef long long ll;
int main()
{
  ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        ll n;
        cin>>n;
        vector<ll>v(n);
        for(ll i=0;i<n;i++)cin>>v[i];
       long long  int mx=v[0];
        long long int sum=0;
        for(ll i=1;i<n;i++)
        {
            if(mx>v[i])
                {
                sum+=(mx-v[i]);
                }
            else
            {
                mx=v[i];

            }
        }
        cout<<sum;



}

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
typedef pair<ii ,ii> iii;
typedef long long ll;
int main()
{
  ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        ll n;
        cin>>n;
        vector<ll>v(n);
        for(int i=0;i<n;i++)cin>>v[i];
        int mx=v[0];
        int sum=0;
        for(int i=1;i<n;i++)
        {
            if(mx>v[i])
                {
                sum+=(mx-v[i]);
                }
            else
            {
                mx=v[i];

            }
        }
        cout<<sum;



}

Submission status: Runtime Error

Solution code:
def f(i,ans,l,t):
  if (i+1) == (len(l)-1):
    if (ans+l[i]) > l[i+1]:
      ans = ans + l[i]-l[i+1]
      return t+ans
    else:
      return t
  else:
    if (ans+l[i]) > l[i+1]:
      ans = ans + l[i]-l[i+1]
      return f(i+1,ans,l,t+ans)
    else:
      return f(i+1,0,l,t)
n = input("")
an = input("").split(" ")
ani = [int(a) for a in an]
if len(ani) == 1:
  print("0")
else:
  print(f(0,0,ani,0))

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
for i in range(N-1):
  if A[i] > A[i+1]:
    S = A[i] - A[i+1]
    K = A[i+1] + abs(S)
  else:
    S = A[i] - A[i+1]
    K = abs(S)
print(K)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

print(sum(ans))

Submission status: Runtime Error

Solution code:
def f(i,ans,l,t):
  if (i+1) == (len(l)-1):
    if (ans+l[i]) > l[i+1]:
      ans = ans + l[i]-l[i+1]
      return t+ans
    else:
      return t
  else:
    if (ans+l[i]) > l[i+1]:
      ans = ans + l[i]-l[i+1]
      return f(i+1,ans,l,t+ans)
    else:
      return f(i+1,0,l,t)
n = input("")
an = input("").split(" ")
ani = [int(a) for a in an]
print(f(0,0,ani,0))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
# atcoder 
# Türkler var mı?
# Herkese memnün oldum
import sys

readline = sys.stdin.buffer.readline
iimr = lambda: map(int, sys.stdin.buffer.readline().rstrip().split())
#sys.setrecursionlimit(10 ** 8)

def debug(*x):
    print(*x, file=sys.stderr)


class atcoder():
    def __init__(self):
        pass

    def çözmek(self):
        N = int(input())
        A = list(map(int, sys.stdin.buffer.readline().split()))
        res = []
        res.append(self.関数(N, A))
        print(*res, "")	
    
    def 関数(self, n, Aliste):
        res = 0
        for i in range(1, n):
            if Aliste[i - 1] > Aliste[i]:
                res += Aliste[i - 1] - Aliste[i]
                Aliste[i] = Aliste[i - 1]

        return res

if __name__ == "__main__":
    ima = atcoder()
    ima.çözmek()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
# atcoder 
# Türkler var mı?
# Herkese memnün oldum
import sys

readline = sys.stdin.buffer.readline
iimr = lambda: map(int, sys.stdin.buffer.readline().rstrip().split())
#sys.setrecursionlimit(10 ** 8)

def debug(*x):
    print(*x, file=sys.stderr)


class atcoder():
    def __init__(self):
        pass

    def çözmek(self):
        N = int(input())
        A = list(map(int, sys.stdin.buffer.readline().split()))
        res = []
        res.append(self.関数(N, A))
        print(*res, "\n")	
    
    def 関数(self, n, Aliste):
        res = 0
        for i in range(1, n):
            if Aliste[i - 1] > Aliste[i]:
                res += Aliste[i - 1] - Aliste[i]
                Aliste[i] = Aliste[i - 1]

        return res

if __name__ == "__main__":
    ima = atcoder()
    ima.çözmek()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
# atcoder 
# Türkler var mı?
# Herkese memnün oldum
import sys

readline = sys.stdin.buffer.readline
iimr = lambda: map(int, sys.stdin.buffer.readline().rstrip().split())
#sys.setrecursionlimit(10 ** 8)

def debug(*x):
    print(*x, file=sys.stderr)


class atcoder():
    def __init__(self):
        pass

    def çözmek(self):
        N = int(input())
        A = list(map(int, sys.stdin.buffer.readline().split()))
        debug(A)
        res = []
        res.append(self.関数(N, A))
        print(*res, "\n")	
    
    def 関数(self, n, Aliste):
        res = 0
        for i in range(1, n):
            if Aliste[i - 1] > Aliste[i]:
                res += Aliste[i - 1] - Aliste[i]
                Aliste[i] = Aliste[i - 1]

        return res

if __name__ == "__main__":
    ima = atcoder()
    ima.çözmek()

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
    return step(a[:am], s)

print(step(A, s))

Submission status: Runtime Error

Solution code:
N=int(input())
a = list(map(int,input().strip().split()))[:N]
ans=[]
for i in range(1,len(a)):
    if a[i]>=a[i-1]:
        ans.append(a[i]-a[i-1])

print(min(ans))

Submission status: Runtime Error

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

ans = 0
maxV = max(list)
maxI = list.index(maxV)

sumV = sum(list[maxI+1, len(list)])
maxM = maxV * (len(list)-1-maxI)
ans += maxM - sumV

if maxI != 0:
    for i in range(0,maxI):
        if i != maxI:
            x = list[i] - list[i+1]
            if x > 0:
                ans += x


print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = map(int, [input() for i in range(n)])

x = 0
while True:
  data = map(lambda a: a + x, a)
  data1 = data.sort()
  if len(data1) == len(set(data1)):
    break:
  else:
    x += 1

print(x * n)

Submission status: Runtime Error

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

def solve(a):
    a_max = max(a)
    idx_max = a.index(a_max)
    return ((len(a) - 1 - idx_max) * a_max) - sum(a[idx_max + 1:]), idx_max

def solve2(a):
    idx_min = 0
    sum_a = 0
    for i in range(1, len(a)):
        if a[0] < a[i]:
            return ((i - 1) * a[0]) - sum_a, i
        else:
            sum_a += a[i]
            if i == len(a) - 1:
                return (i * a[0]) - sum_a, i + 1

def main():
    n = int(input())
    a = list(map(int, input().split()))
    ans = 0
    while(1):
        k, idx_max = solve2(a)
        ans += k
        if idx_max == len(a):
            break
        a = a[idx_max:]
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def main():
    N = input()
    if int(N) < 1 or int(N) >= 2*10**5:
        raise ValueError
    A = []
    for i in input().split():
        if int(i) < 1 or int(i) >= 10**9:
            raise ValueError
        A.append(int(i))
    temp = A[0]
    su = 0
    for i in A:
        if i >= temp:
            height = 0
        else:
            height = temp-i
        temp = i + height
        su += height
    print(su)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
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])
    l[i+1]=l[i] 
  i=i+1
r=i
for b in range(r,n):
    d=d+(u-l[b])
print(d)

Submission status: Runtime Error

Solution code:
N=int(input())
a = list(map(int,input().strip().split()))[:N]
ans=[]
for i in range(1,len(a)):
    if a[i]>a[i-1]:
        ans.append(a[i]-a[i-1])

print(min(ans))

Submission status: Runtime Error

Solution code:
import numpy as np
import sys

sys.setrecursionlimit(10**6)

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

acopy = a.copy()

'''
後ろからみて最高点より後ろは全て最高点と同じに
最高点より前でもう一度最高点を探す
'''

x = set([i for i in range(3*1000)])

a_log = np.array([])
for i in x:
    h_v = np.max(a)
    h_i = np.argmax(a)

    if h_i == len(a):
      break

    a[h_i:] = np.array([h_v]*(len(a)-h_i))

    #記録
    a_log = np.concatenate([a[h_i:],a_log])

    #書き換え
    a = a[:h_i]



    if h_i == 0:
      break

print(int(np.sum(a_log - acopy)))

Submission status: Runtime Error

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

print(min(ans))

Submission status: Runtime Error

Solution code:
def f(i,ans,l):
  if (i+1) == (len(l)-1):
    return max(ans,l[i+1]-l[i])
  else:
    return f(i+1,max(ans,l[i+1]-l[i]),l)
n = input("")
an = input("").split(" ")
ani = [int(a) for a in an]
print(str(f(0,0,ani)))

Submission status: Runtime Error

Solution code:
import numpy as np
import sys

sys.setrecursionlimit(10**6)

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

acopy = a.copy()

'''
後ろからみて最高点より後ろは全て最高点と同じに
最高点より前でもう一度最高点を探す
'''

x = 5*10**3

a_log = np.array([])
for i in range(x):
    h_v = np.max(a)
    h_i = np.argmax(a)

    if h_i == len(a):
      break

    a[h_i:] = np.array([h_v]*(len(a)-h_i))

    #記録
    a_log = np.concatenate([a[h_i:],a_log])

    #書き換え
    a = a[:h_i]



    if h_i == 0:
      break

print(int(np.sum(a_log - acopy)))

Submission status: Runtime Error

Solution code:
import io
import sys
import math
import itertools
N = int(input())
A = list(map(int, input().split()))

Springboard = []
for i in range(1,len(A)):
  # 自分より前に自分より身長が高い人がいないとき
  if max(A[:i+1]) == A[i]:
    Springboard.append(0)
    # 自分より前に自分より身長が高い人がいるとき
    else:
      Springboard.append(max(A[:i]) - A[i])

print(sum(Springboard))

Submission status: Runtime Error

Solution code:
import numpy as np

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

acopy = a.copy()

'''
後ろからみて最高点より後ろは全て最高点と同じに
最高点より前でもう一度最高点を探す
'''

x = 6*10**3

a_log = np.array([])
for i in range(x):
    h_v = np.max(a)
    h_i = np.argmax(a)

    if h_i == len(a):
      break

    a[h_i:] = np.array([h_v]*(len(a)-h_i))

    #記録
    a_log = np.concatenate([a[h_i:],a_log])

    #書き換え
    a = a[:h_i]



    if h_i == 0:
      break

print(int(np.sum(a_log - acopy)))

Submission status: Runtime Error

Solution code:
import numpy as np

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

acopy = a.copy()

'''
後ろからみて最高点より後ろは全て最高点と同じに
最高点より前でもう一度最高点を探す
'''

x = 5*10**3

a_log = np.array([])
for i in range(x):
    h_v = np.max(a)
    h_i = np.argmax(a)

    if h_i == len(a):
      break

    a[h_i:] = np.array([h_v]*(len(a)-h_i))

    #記録
    a_log = np.concatenate([a[h_i:],a_log])

    #書き換え
    a = a[:h_i]



    if h_i == 0:
      break

print(int(np.sum(a_log - acopy)))

Submission status: Runtime Error

Solution code:
import numpy as np

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

acopy = a.copy()

'''
後ろからみて最高点より後ろは全て最高点と同じに
最高点より前でもう一度最高点を探す
'''

x = 3*10**3

a_log = np.array([])
for i in range(x):
    h_v = np.max(a)
    h_i = np.argmax(a)

    if h_i == len(a):
      break

    a[h_i:] = np.array([h_v]*(len(a)-h_i))

    #記録
    a_log = np.concatenate([a[h_i:],a_log])

    #書き換え
    a = a[:h_i]



    if h_i == 0:
      break

print(int(np.sum(a_log - acopy)))

Submission status: Runtime Error

Solution code:
import numpy as np

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

acopy = a.copy()

'''
後ろからみて最高点より後ろは全て最高点と同じに
最高点より前でもう一度最高点を探す
'''

x = 2*10**3

a_log = np.array([])
for i in range(x):
    h_v = np.max(a)
    h_i = np.argmax(a)

    if h_i == len(a):
      break

    a[h_i:] = np.array([h_v]*(len(a)-h_i))

    #記録
    a_log = np.concatenate([a[h_i:],a_log])

    #書き換え
    a = a[:h_i]



    if h_i == 0:
      break

print(int(np.sum(a_log - acopy)))

Submission status: Runtime Error

Solution code:
n=int(input())

a=list(map(int,input().split()))
  
b=[]
if n>1:
  for j in range (n-1):
    c=a[j]-a[j+1]
    if c>-1:
      b.append(c)
      a[j+1]=a[j+1]+c
      
   
  if max(b)>-1:
    print(sum(b))
  else:
    print(0)
    
else:
  print(0)

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:
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
else:
  for b in range(r,len(l)):
    d=d+(u-l[b])
print(d)

Submission status: Runtime Error

Solution code:
l=list(map(int,input().split()))
u=max(l)
d=0
i=0
while l[i]!max:
  if l[i]>l[i+1]:
    d=d+abs(l[i+1]-l[i])
  i=i+1
r=i
else:
  for b in range(r,len(l)):
    d=d+(u-l[b])
print(d)

Submission status: Runtime Error

Solution code:
import numpy as np

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

acopy = a.copy()

'''
後ろからみて最高点より後ろは全て最高点と同じに
最高点より前でもう一度最高点を探す
'''


a_log = []
for i in range(10**3):
    h_v = np.max(a)
    h_i = np.argmax(a)

    if h_i == len(a):
      break

    a[h_i:] = np.array([h_v]*(len(a)-h_i))

    #記録
    a_log = np.concatenate([a[h_i:],a_log])

    #書き換え
    a = a[:h_i]



    if h_i == 0:
      break

print(int(np.sum(a_log - acopy)))

Submission status: Runtime Error

Solution code:
import numpy as np

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

acopy = a.copy()

'''
後ろからみて最高点より後ろは全て最高点と同じに
最高点より前でもう一度最高点を探す
'''


a_log = []
for i in range(10**3):
    h_v = np.max(a)
    h_i = np.argmax(a)

    if h_i == len(a):
      break

    a[h_i:] = np.array([h_v]*(len(a)-h_i))

    #記録
    a_log = np.concatenate([a[h_i:],a_log])

    #書き換え
    a = a[:h_i]



    if h_i == 0:
      break

print(np.sum(a_log - acopy))

Submission status: Runtime Error

Solution code:
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]
  if e > 0:
    q = 0
  else:
    if p-q > e:
      q -= e
    else:
      q -= e
      e = q
print(s)

Submission status: Runtime Error

Solution code:
l=list(map(int,input().split()))
u=max(l)
d=0
i=0
while l[i]!max:
  if l[i]<l[i+1]:
    pass
  else:
    d=d+abs(l[i+1]-l[i])
  i=i+1
r=i
else:
  for b in range(r,len(l)):
    d=d+(u-l[b])
print(d)

Submission status: Runtime Error

Solution code:
n = input()
m = input()
m = list(m)
m = [int(i) for i in m]
mx = max(m)
ind = m.index(mx)

c = 0
j = len(m)
for i in reversed(m[ind:]):
    if i < mx:
        d = mx - i
        c += d
ind_i = 0
for i in m[1:ind]:
    if m[ind_i] > i:
        num = m[ind_i] - i
        c+= num
    ind_i += 1
    
print(c)

Submission status: Runtime Error

Solution code:
l=list(map(int,input().split()))
u=max(l)
d=0
while l[i]!max:
  if l[i]<l[i+1]:
    pass
  else:
    d=d+abs(l[i+1]-l[i])
  i=i+1
r=i
else:
  for b in range(r,len(l)):
    d=d+(u-l[b])
print(d)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np

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

acopy = a.copy()

'''
後ろからみて最高点より後ろは全て最高点と同じに
最高点より前でもう一度最高点を探す
'''

def highest(n,a):
  a_log = []
  for i in range(10**4):
      h_v = np.max(a)
      h_i = np.argmax(a)

      if h_i == len(a):
        break

      a[h_i:] = np.array([h_v]*(len(a)-h_i))

      #記録
      a_log = np.concatenate([a[h_i:],a_log])

      #書き換え
      a = a[:h_i]


      if h_i == 0:
        break

      return a_log


  


print(int(np.sum(highest(n,a) - acopy)))

Submission status: Runtime Error

Solution code:
def main(lines):
	line = lines  

if __name__ == '__main__':
    lines = []
    for l in sys.stdin:
        lines.append(l.rstrip('\r\n'))
    main(lines)

Submission status: Runtime Error

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

print(sum(A) - b)

Submission status: Runtime Error

Solution code:
x = int(input())
lst = list(map(int, input().split()))
i = 1
cnt = 0
a = lst[0]
while True:
    b = lst[i]
    if b < a:
        cnt += abs(b - a)
        a = a
    else:
        a = b
    if i == x - 1:
        break
    i += 1
print(cnt)

Submission status: Runtime Error

Solution code:
import numpy as np

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

acopy = a.copy()

'''
後ろからみて最高点より後ろは全て最高点と同じに
最高点より前でもう一度最高点を探す
'''

a_log = []
for i in range(10**3):
    h_v = np.max(a)
    h_i = np.argmax(a)

    if h_i == len(a):
      break

    a[h_i:] = np.array([h_v]*(len(a)-h_i))

    #記録
    a_log = np.concatenate([a[h_i:],a_log])

    #書き換え
    a = a[:h_i]


    if h_i == 0:
      break
  


  


print(int(np.sum(a_log - acopy)))

Submission status: Runtime Error

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

print(sum(m))

Submission status: Runtime Error

Solution code:
vfrom sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math
###############################################################################\
n=int(input())
A=INPUT()
B=[A[0]]

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

Submission status: Runtime Error

Solution code:
import numpy as np

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

acopy = a.copy()

'''
後ろからみて最高点より後ろは全て最高点と同じに
最高点より前でもう一度最高点を探す
'''

a_log = []
for i in range(10**3):
    h_v = np.max(a)
    h_i = np.argmax(a)

    if h_i == len(a):
      break

    a[h_i:] = np.array([h_v]*(len(a)-h_i))

    #記録
    a_log = np.concatenate([a[h_i:],a_log])

    #書き換え
    a = a[:h_i]


    if h_i == 0:
      break
  


  


print(np.sum(a_log - acopy))

Submission status: Runtime Error

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

print(sum(m))

Submission status: Runtime Error

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

h =[]

if a[0] > a[1]:
    h.append(a[0] - a[1])
    a[1] = a[0]
else:
    h.append(0)
    
for i in range(2,n):
    if a[i-1] > a[i]:
        h.append(a[i-1]- a[i])
        a[i] = a[i-1]
    else:
        h.append(0)
        
print(sum(h))

Submission status: Runtime Error

Solution code:
n=int(input())
lst=list(map(int,input().split()))
lst1=[]
for i in range(n):
	if lst[i+1]<lst[i]:
    	count=lst[i]-lst[i+1]
        lst1.append(count)
        lst[i+1]=lst[i+1]+count
	else:
      	x=0
sum=0
for i in lst1:
	sum+=i
    print(sum)