Problem:
 Score : 300 points    Problem Statement In a flower bed, there are N flowers, numbered 1,2,......,N . Initially, the heights of all flowers are 0 .
You are given a sequence h=\{h_1,h_2,h_3,......\} as input. You would like to change the height of Flower k to h_k for all k  (1 \leq  k \leq N) , by repeating the following "watering" operation:   Specify integers l and r . Increase the height of Flower x by 1 for all x such that l \leq x \leq r .   Find the minimum number of watering operations required to satisfy the condition.      Constraints  1 \leq N  \leq 100  0 \leq h_i \leq 100  All values in input are integers.         Input Input is given from Standard Input in the following format:  N  h_1  h_2  h_3  ......  h_N       Output Print the minimum number of watering operations required to satisfy the condition.        Sample Input 1 4
1 2 2 1      Sample Output 1 2  The minimum number of watering operations required is 2 .
One way to achieve it is:   Perform the operation with (l,r)=(1,3) .  Perform the operation with (l,r)=(2,4) .        Sample Input 2 5
3 1 2 3 1      Sample Output 2 5       Sample Input 3 8
4 23 75 0 23 96 50 100      Sample Output 3 221

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
h += [0]
ans = 0

if n<=2:
    print(max(h))
else:
    while True:
        count = 0
        for i in range(n):
            if h[i]!=0 and h[i+1]==0:
                count += 1
        for i in range(n):
            if h[i]!=0:
                h[i] -= 1
        ans += count
        if all([i==0 for i in h]):
            print(ans)
            exit()

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

ans = 0
level = 0
for i in range(len(h)):
    if h[i] >= level:
        level = h[i]
    else:
        ans += level - h[i]
        level = h[i]

ans += level

print(ans)

Solution (Python):
N = int(input())
h = list(map(int,input().split()))
ans = 0
while sum(h) > 0:
    for i in range(N):
        if h[i] > 0:
            l = i
            break
    ans += 1
    for i in range(l,N):
        if h[i] > 0:
            h[i] -= 1
        else:
            break

print(ans)

Solution (Python):
N = int(input())
H = [0] + [int(a) for a in input().split()]


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

print(answer)

Solution (Python):
n= int(input())
h= list(map(int, input().split()))
x=max(h)
ans=0
count=0
for i in range(10009):
    count=0
    if max(h)==0:
        break
    ans+=1
    for j in range(n):
        if h[j]==0 and count==0:
            continue
        elif h[j]>0:
            count=1
            h[j]-=1
        else:
            break



print(ans)

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

def height(ans, loop):
  if loop > max(h):
    print(ans)
    return
  
  i = 0
  for i in range(n):
    if i == 0 and h[i] >= loop:
      ans += 1
    elif h[i] >= loop and h[i-1] < loop:
      ans += 1
      
  height(ans, loop+1)
  
height(0, 1)

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

ans=0

for i in range(max(h)):
  for g in range(1,n+1):
    if h[g-1]!=0 and h[g]==0:
      ans+=1
  for g in range(n+1):
    if h[g]!=0:
      h[g]-=1
      
print(ans)

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
hantei = [0 for _ in range(n)]
hantei.append(1)
result = 0
h.append(10*3)

while any(hantei[i] != 1 for i in range(n)):
    min_h = min(h)
    cost = 0
    for i in range(len(h)):
        if hantei[i]==1:
            result += cost
            cost = 0
            h[i] = 10**3
        else:
            h[i] -= min_h
            if h[i] == 0:
                hantei[i] = 1
            cost = min_h
print(result)

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
cnt = 0
for i in range(n):
    while h[i] > 0:
        for j in range(i, n):
            if h[j] != 0:
                h[j] -= 1
            else:
                cnt += 1
                break
        else:
            cnt += 1
print(cnt)

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

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

ans = 0

while sum(t) != 0:
    for i in range(n):
        if t[i] > 0 and i == n-1:
            ans += 1
            t[i] -= 1
        elif t[i] == 0 and i == n-1:
            continue
        elif t[i] > 0 and t[i+1] == 0:
            ans += 1
            t[i] -= 1
        elif t[i] > 0 and t[i+1] > 0:
            t[i] -=1
    

print(ans)

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

Solution (Python):
n=int(input())
h=list(map(int,input().split()))
count=0
while h!=[0]*n:
	find=0 
	count+=1
	for i in range(n):
		if h[i]==0 and find==1:
			break
		if h[i]!=0:
			h[i]-=1
			find=1	
print(count)

Solution (Python):
n = int(input())
H = [0] + list(map(int, input().split())) + [0]
T = [0 for _ in range(n+2)]
c = 0
while True:
	s0 = 0; t1 = 0
	for i in range(0, n+2):
		if H[i] > 0 and s0 == 1:
			H[i] -= 1
			t1 = 1
		elif H[i] == 0 and t1 == 1:
			c += 1
			t1 = 0
		elif H[i] == 0:
			s0 = 1
	if H == T: break
print(c)

Solution (Python):
n = int(input())
H = list(map(int, input().split()))
T = [0 for _ in range(n)]
c = 0
while True:
  f = False
  S = {0:1}
  for j in range(n):
    if H[j] > 0:
      S[1] = 1
      H[j] -= 1
      f = True
    elif len(S) > 1 and H[j] == 0:
      break
  if f: c += 1
  if H == T: break
print(c)

Solution (Python):
N = int(input())
h = [int(i) for i in input().split()]+[0]

count = 0
for key in range(1, 101):
    flag = False

    for i in range(N+1):
        if h[i] >= key:
            if not flag:
                flag = True
        else:
            if flag:
                flag = False
                count += 1


print(count)

Solution (Python):
n=int(input())
h=list(map(int,input().split()))
a=[0]*n
ans=0
while True:
    flag=0
    for i in range(n):
        if h[i]>a[i]:
            a[i]+=1
            flag=1
        elif h[i]==a[i] and flag:
            break
    if flag:
        ans+=1
    else:
        break
print(ans)

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

A = [[0 for i in range(N)] for j in range(101)]


for i in range(101):
    for j in range(N):
        if H[j] - i > 0:
            A[i][j] = 1 


ans = 0
for i in range(101):
    cnt = 0
    for j in range(N):
        if cnt == 0 and A[i][j] == 1:
            cnt+=1
            ans +=1
        elif A[i][j] == 0:
            cnt = 0
        
print(ans)

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
cnt = 0

while True:
    if max(h) == 0:
        break
    i = 0
    while i < n:
        if h[i] == 0:
            i += 1
        else:
            cnt += 1
            while i < n and h[i] > 0:
                h[i] -= 1
                i += 1
print(cnt)

Solution (Python):
import sys
from io import StringIO
import unittest

def resolve():
    n = int(input().strip())
    hl = list(map(int,input().strip().split()))
    cnt=0
    while 1:
        maxh=max(hl)
        if maxh==0:
            break
        t=-1
        for i in range(n):
            if hl[i]>0:
                hl[i]-=1
                if i==0:
                    cnt+=1
                elif (i-1)==t:
                    cnt+=0
                else:
                    cnt+=1
                t=i
    print(cnt)

    return

resolve()

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

ans = 0
while True:
  if max(h) == 0:
    break
    
  i = 0
  while i < N:
    if h[i] == 0:
      i += 1
    else:
      ans += 1
      while i<N and h[i]>0:
        h[i] -= 1
        i += 1

print(ans)

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

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

Solution (Python):
n=int(input())
h=list(map(int,input().split()))
h_max=max(h)
ans=0
for i in range(1,h_max+1):
    if h[0]>=i:
        ans+=1
    for j in range(n-1):
        if h[j]<i and h[j+1]>=i:
            ans+=1
print(ans)

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

Solution (Python):
def f(h):
    th = [i-1 for i in h]
    ret = 1
    spl = []
    for i in range(len(th)):
        if i == 0 and th[i] != 0:
            spl.append(i)
        elif i != 0 and th[i-1] == 0 and th[i] != 0:
            spl.append(i)
        if i == len(th)-1 and th[i] != 0:
            spl.append(i+1)
        elif i != 0 and th[i-1] != 0 and th[i] == 0:
            spl.append(i)
    for i in range(0,len(spl),2):
        ret += f(th[spl[i]:spl[i+1]])
            
    return ret
    


n = int(input())
h = [int(x)+1 for x in input().split()]

print(f(h)-1)

Solution (Python):
n=int(input())
h=list(map(int,input().split()))
cnt=0
for i in range(100):
    prev = bool(h[0])
    h[0] = h[0] - prev
    for j in range(1,n):
        if bool(h[j]) == prev:
            h[j] = h[j] - prev
            continue
        else:
            cnt += prev
            prev = bool(h[j])
            h[j] = h[j] - prev
    cnt+=prev
print(cnt)

Solution (Python):

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

def search(h):
    if len(h)==0:
        return 0
    else:
        x=min(h)
        h_=[h[i]-x for i in range(len(h))]
        res=x
        if 0 in h_:
            i=h_.index(0)
            res+=search(h_[0:i])+search(h_[i+1:])
        return res

print(search(H))

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

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

ans = 0

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

ans += h[N - 1]

print(ans)

Solution (Python):
_ = input()
input_list = list(map(int, input().split(' ')))

total = input_list[0]
height = input_list[0]
for a in input_list[1:]:
  height = min(height, a)
  total += a - height
  height = a
  
print(total)

Solution (Python):
import numpy as np

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


def f(H):
  if len(H) == 1:
    return H[0]
  elif len(H) == 0:
    return 0
  else:
    idx = np.argmin(H)
    min_h = H[idx]
    Hl = H[:idx] - min_h
    Hr = H[idx+1:] - min_h
    res = f(Hl) + f(Hr) + min_h
    return res

print(f(h))

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

ans = 0
left = 0
for i in h:
    if i > left:
        ans += i-left
    left=i
print(ans)

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

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

def calc(left, right, ans):
    minh = min(h[left: right+1])
    ans += minh
    for i in range(left, right+1):
        h[i] -= minh
    return ans

ans = 0

while h!=[0]*N:
    if h[0]>0:left = 0
    
    if N==1:
        ans = h[0]
        break    
    
    for i in range(1, N):
        if h[i]>0 and h[i-1]==0:
            left=i
            if i==N-1:
                right = N-1
                ans = calc(left, right, ans)
        elif h[i]==0 and h[i-1]>0:
            right=i-1
            ans = calc(left, right, ans)
        elif h[i]>0 and h[i-1]>0 and i==N-1:
            right = N-1
            ans = calc(left, right, ans)
        else:continue


print(ans)

Solution (Python):
N,*h=map(int,open(0).read().split())
ans = 0
left = 0
for i in h:
    if i > left:
        ans += i-left
    left=i
print(ans)

Solution (Python):




n = int(input())
a = list(map(int,input().split()))
def solve(a,n):
    if len(a) == 0: return 0
    if len(a) == 1: return a[0]-n
    idx = a.index(min(a))
    
    return solve(a[:idx],min(a))+ min(a)-n +solve(a[idx+1:],min(a))
print(solve(a,0))

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

res=0
while 1:
    if max(h)==0: break
    i=0
    while i<n:
        if h[i]==0: i+=1
        else:
            res+=1
            while i<n and h[i]>0:
                h[i]-=1
                i+=1
print(res)

Solution (Python):
import numpy as np
n=int(input())
H=list(map(int,input().split()))
H=np.array(H)
cnt=H[0]+np.maximum(H[1:]-H[:-1],0).sum()
print(cnt)

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

w,cnt=0,0
for i in range(n):
  cnt+=max(H[i]-w,0)
  w=H[i]
print(cnt)

Solution (Python):
n = int(input())
*h, = map(int, input().split())
cnt = 0
minh = min(h)

h = [i - minh for i in h]
cnt += minh + h[0]

for i in range(1, n):
  
  if h[i-1] <= h[i]: cnt += h[i] - h[i-1]
print(cnt)

Solution (Python):
n=int(input())
*h,=map(int,input().split())
m=min(h)
h=[i-m for i in h]
cnt=m+h[0]
for i in range(1,n):
	if h[i-1]<=h[i]:
		cnt+=h[i]-h[i-1]
print(cnt)

Solution (Python):
count = 0

def rec(l, r):
    global count
    global h
    global s

    if l >= r:
        return

    zero = list()
    for i in range(l, r):
        if h[i] == 0:
            zero.append(i)

    if len(zero) > 0:
        for i in zero:
            if not (l, i) in s:
                rec(l, i)
                s.add((l, i))
            if not (i+1, r) in s:
                rec(i+1, r)
                s.add((i+1, r))
    else:
        for i in range(l, r):
            h[i] -= 1
        count += 1
        rec(l, r)

n = int(input())
h = list(map(int, input().split()))
s = set()

rec(0, len(h))
print(count)

Solution (Python):
def main():
    N = int(input())
    h = list(map(int, input().split()))
    r = 0
    while sum(h) > 0:
        m = max(h)
        t = 0
        for i in range(len(h)):
            if h[i] == m:
                h[i] -= 1
                if t == 0:
                    r += 1
                    t = 1
            else:
                t = 0
    print(r)
main()

Solution (Python):
def water(flowers, count):
    if len(flowers) is 0:
        return count
    count = count + min(flowers)
    flowers = [int(e-min(flowers)) for e in flowers]
    while 0 in flowers:
        count = water(flowers[:flowers.index(0)], count)
        flowers = flowers[flowers.index(0)+1: ]
    count = water(flowers, count)
    return count

n = int(input())
flowers = [int(e) for e in input().split()]

count = 0
count = water(flowers, count)
print(count)

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

ans = 0
while sum(h) != 0:
  m = max(h)
  f = False
  for i in range(len(h)):
    if h[i] == m:
      h[i] -= 1
      if not f:
        f = True
        ans += 1
    else:
      f = False
print(ans)

Solution (Python):
from itertools import groupby

def sgn(num):
    if num>0:
        return 1
    elif num==0:
        return 0
    else:
        return -1

N=int(input())
h=list(map(int,input().split()))
ans=0
for i in range(1,101):
    sublist=[sgn(h[j]) for j in range(0,N)]
    sublist=groupby(sublist)
    for key,group in sublist:
        if key==1:
            ans+=1
    h=[h[j]-1 for j in range(0,N)]
print(ans)

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

Solution (Python):
import itertools
import math
import sys

n = int(input())
h = list(map(int, input().split()))



























deleted_something = False

ans = 0
while h.count(0) != n:
    deleted_something = False
    for i in range(n):
        if h[i] == 0 and deleted_something:
            break
        if h[i] == 0:
            continue
        h[i] -= 1
        deleted_something = True
    ans += 1
print(ans)

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

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

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

Solution (Python):
n = int(input())
S = input().split(" ")
arr = [int(s) for s in S]
def calculate(n,arr):
    ans = 0
    for i in range(len(arr)):
        if i == 0:
            ans += arr[i]
        else:
            if arr[i] > arr[i-1]:
                ans += (arr[i] - arr[i-1])
    return ans

result = calculate(n,arr)

print(result)

Solution (Python):
n=int(input())
H=list(map(int,input().split()))
delta=[0]*(n-1)
ans=H[0]
for i in range(n-1):
    delta[i]=H[i+1]-H[i]
    if delta[i]>0:
        ans+=delta[i]
print(ans)

Solution (Python):
def parth(h,m):
    hmin=min(h)
    hmax=max(h)
    if hmax<=0:
        return m
    else:
        m=m+hmin
        for i in range(len(h)):
            h[i]=h[i]-hmin

        i=0
        while i<len(h):
            h2=[]
            while i<len(h) and h[i]>0:
                h2.append(h[i])
                i=i+1
            if len(h2)>0:
                m=parth(h2,m)                
            i=i+1    
        return m


n=int(input())
h=list(map(int,input().split()))










m=0
m=parth(h,m)
print(m)

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

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

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

c = 0
i = 0

while sum(h) > 0 :
    if h[i]> 0 :
        j = i
        c = c + 1 
        while j < n and h[j] > 0 :
            h[j] = h[j] - 1
            j = j + 1
    else:
        i = i + 1

print(c)

Solution (Python):
n = int(input())
h = [int(x) for x in input().split()]

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

print(ans)

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

Solution (Python):
n = int(input())
h = list(map(int,input().split()))
h.append(0)
cnt = 0
maxh = max(h)
for i in range(maxh):
    point = -1
    for j in range(n+1):
        if j <= point:
            continue
        
        for k in range(j+1,n+1):
            
            if j <= point:
                continue
            if (h[j] != 0 and h[k] == 0):
                for l in range(j,k):
                    h[l] -= 1
                cnt += 1
                point = k
        
            
            
            
            
            
            
                
                
            
            
            
    

print(cnt)

Solution (Python):
N = input()
K = list(map(int,input().split()))
L = len(K)
dicta = {i:K[i] for i in range(0, L)}
count = 0
start = 0
while True:
    start = 0
    flag = 0
    for i in range(0, L):
        if dicta[i] == 0:
            if start == 0:
                pass
            elif start == 1:
                start = 0
        elif dicta[i] != 0:
            dicta[i] -= 1
            if start == 0:
                start = 1
                flag = 1
                count += 1
    if flag == 0:
        break
print(count)

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

ans = 0

for i in range(N-1):
    dist = h[i+1] - h[i]

    if dist > 0:
        ans += dist

print(ans+h[0])

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
g = [[0 for _ in range(n)]for _ in range(max(l))]
for i in range(1,max(l)+1):
    for j in range(n):
        if l[j]>=i:
            g[i-1][j] = 1
        else:
            g[i-1][j] = 0
ans = 0
for line in g:
    last_h = 0
    for h in line:
        if last_h == 0 and h == 1:
            ans+=1
        last_h = h
print(ans)

Solution (Python):
def up(x):
    return x-1

n = int(input())
h = [int(x) for x in input().split()]

sum = 0

for j in range(max(h)):
    if h[0] <= 0:
        cnt = 0
    else:
        cnt = 1
    flag = 1
    for i in range(n):
        if flag == 1 and h[i] <= 0:
            flag = 0
        elif flag == 0 and h[i] > 0:
            flag = 1
            cnt += 1
    h = list(map(up, h))
    sum = sum + cnt

print(sum)

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

height = H[0]

for i in range(1, N):
    dif = H[i] - H[i - 1]
    
    if (dif > 0):
        height += dif

print(height)

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N = int(input())
    H = list(map(int, input().split()))

    ans = 0
    for i in range(N):
        h = H[i]
        if h == 0:
            continue
        for j in range(h):
            for k in range(i, N):
                if H[k] >= 1:
                    H[k] -= 1
                else:
                    break
            ans += 1
    print(ans)
    
if __name__ == '__main__':
    main()

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

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

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


ans = 0
while True:
    
    if max(h) == 0:
        break

    
    i = 0
    while i < N:
        if h[i] == 0:  
            i += 1
        else:
            ans += 1  
            while i < N and h[i] > 0:
                h[i] -= 1  
                i += 1
print(ans)

Solution (Python):
import numpy as np
n = int(input())
h = np.array([0] + [int(i) for i in input().split()])
cnt = 0
for i in range(max(h), 0, -1):
    hh = h >= i
    cnt += sum([not hh[j] and hh[j + 1] for j in range(n)])
print(cnt)

Solution (Python):
def main():
    N = int(input())
    h = [0] + [int(i) for i in input().split()]
    ans = 0
    for i in range(N):
        ans += max(0, h[i+1] - h[i])
    print(ans)


if __name__ == '__main__':
    main()

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

ans = 0
while sum(h) != 0:
    count = 0
    for i in range(N):
        if h[i] > 0:
            h[i] -= 1
            count += 1
        elif h[i] == 0:
            if count == 0:
                continue
            elif count > 0:
                break
    ans += 1

print(ans)

Solution (Python):
n = int(input())
don = list(map(int, input().split()))
count = 0
while 1:
    if not don:
        break
    for i, k in enumerate(don):
        if k == 0:
            continue
        else:
            num = i
            break
    else:
        num = len(don)
    if num:
        del don[:num]
    for i, k in enumerate(don):
        if k == 0:
            num = i
            break
    else:
        num = len(don)
    for i in range(num):
        don[i] -= 1
    count += 1
print(count-1)

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

ans = 0
for i in range(m):
  ans += (l[0] > i)
  for j in range(1,n):
    if l[j-1] <= i:
      ans += (l[j] > i)
print(ans)

Solution (Python):
N = int(input())
li = list(map(int, input().split()))
count = 0

while(True):
  if max(li) == 0:
    break

  i = 0
  while(i < N):
    if li[i] == 0:
      i += 1
      continue

    count += 1
    while(i < N and li[i] > 0):
      li[i] -= 1
      i += 1

print(count)

Solution (Python):
N=int(input())
H=list(map(int,input().split()))
ans=0

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

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

mizu=0

while True:

    end=True
    for i in range(n):
       if h[i]!=0:
           end=False

    if end:
        break

    for l in range(n):
        if h[l]!=0:
            break

    for r in range(l,n):
        if h[r]==0:
            r-=1
            break

    mizu+=1
    for i in range(l,r+1):
        h[i] -= 1

print(mizu)

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

ans = 0

while True:
    flag = False
    ans_tmp = ans
    for i in range(n):
        if a[i] > 0:
            a[i] -= 1
            if not flag:
                flag = True
                ans += 1
        else:
            flag = False
    if ans_tmp == ans:
        break

print(ans)

Solution (Python):
import numpy as np


def give_water(flower, lr):
    flower_with_water = [x+1 if i>=lr[0] and i<=lr[1] else x for i,x in enumerate(flower)]
    return flower_with_water

def TF_list(flower, h):
    h = np.array(h)
    TF_list_0 = []
    for i in range(len(flower)):
        TF_list_0.append(flower[i] < h[i])
    return TF_list_0


def list_tuple_True(flower, h, N):
    TF_list = (flower < h)
    TF_list = np.insert(TF_list, N, False)
    True_range = []
    
    FLAG = False
    for i, TF in enumerate(TF_list):
        if TF:
            if FLAG:
                
                pass
            else:
                
                start = i
        else:
            if FLAG:
                
                end = i-1
                True_range.append((start, end))
            else:
                
                pass
        FLAG = TF
    return True_range
            
N = int(input())
h = list(map(int, input().split()))

h = np.array(h)
flower = np.zeros(N)

count = 0
while not((h == flower).all()):
    water_range = list_tuple_True(flower, h, N)
    count += len(water_range)
    for lr in water_range:
        flower = give_water(flower, lr)
        
print(count)

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

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

cnt = 0
l = 0
r = n

while max(hs)>0:
    l = 0
    r = n

    for i in range(n):
        if hs[i] > 0:
            l = i
            break
    
    for j in range(l,n):
        if hs[j]== 0:
            r = j
            break
    
    for k in range(l,r):
        hs[k] -= 1

    cnt += 1

print(cnt)

Solution (Python):
n=int(input())
h=[int(x) for x in input().split()]
buf=[0 for i in range(n)]

ans=0

flag=False

for i in range(max(h)):
    for j in range(n):
        if h[j] >= i+1:
            flag=True
        if flag and h[j] <= i:
            ans+=1
            flag=False
    if flag:
        ans+=1
        flag=False

print(ans)

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

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

Solution (Python):
N = int(input())
H = list(map(int,input().split()))
y = 0
z = H[0]
ans = 0
while len(H) != 0:
    z = H[0]
    f = 1
    while z == 0:
        H.pop(0)
        if len(H) != 0:
            z = H[0]
        else:
            break
    for i in range(len(H)):
        x = H[i]
        if x == 0:
            ans += z
            for j in range(i):
                H[j] -= z
            z = H[0]
            f = 0
            break
        z = min(x,z)
    if f == 1:
        ans += z
        for i in range(len(H)):
            H[i] -= z
print(ans)

Solution (Python):
n = int(input())
h = [int(x) for x in input().split()]

ans = 0

def water(h):
   global ans

   if (len(h) == 0):
      return
   if (len(h) == 1):
      ans += h[0]
      return

   m = min(h)
   ans += m
   h = [i - m for i in h]
   while (0 in h):
      water(h[:h.index(0)])
      h = h[h.index(0)+1:]
   water(h)


water(h)
print(ans)

Solution (Python):
cnt = 0

n = int(input())
h = [int(_) for _ in input().split()]

now = [0] * len(h)

while True:
    cnt += 1
    chk = False
    for i in range(n):
        if h[i] == now[i]:
            if chk == True:
                break
        else:
            now[i] += 1
            chk = True
    if chk == False:
        cnt -= 1
        break

print(cnt)

Solution (Python):

N = int(input()) 
h_list = list(map(int, input().split()))
x_list = [0 for _ in range(N)]

ans = 0

for i in range(N):
    while h_list[i] != x_list[i]:
        
        for j in range(i,N):
            if h_list[j] == x_list[j]:
                break
            else:
                x_list[j] += 1
                
        ans += 1


print(ans)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
c = [0] * n
ma = max(a)

ans = 0
while max(c) != ma:
    ing = False
    for i in range(n):
        if a[i] == c[i]:
            ing = False
            continue
        else:
            if not ing:
                ing = True
                ans += 1
            c[i] += 1
print(ans)

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

def zerosplit(l): 
  
  mother = []
  child = []
  for e in l:
    if e != 0:
      child.append(e)
    elif e == 0 and len(child) != 0:
      mother.append(child)
      child = []
  if len(child) !=0:
    mother.append(child)
  return mother

def mizuyari(l): 
  d = [0]*len(l)
  cnt1 = min(l)
  for i in range(len(l)):
    d[i] = l[i] - min(l)
  
  return [d,cnt1]
localcount = []
def mini(h): 
  l = zerosplit(h)
  
  for e in l:
    
    d,c = mizuyari(e)
    localcount.append(c)
    
    if len(d) != 0:
      mini(d)
  return sum(localcount)

print(mini(h))

Solution (Python):
N = int(input())
h = list(map(int, input().split()))
ans = 0

for l in range(N):
    while h[l] != 0:
        r = l+1
        for i in range(r, N):
            if h[i] == 0:
                break
            r += 1
        for i in range(l, r):
            h[i] -= 1
        ans += 1
print(ans)

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

Solution (Python):
def solve(n, H):
    prev_h, base_h = 0, 0
    count = 0
    up = True
    for h in H:
        if up and h < prev_h:
            
            count += prev_h - base_h
            up = False
        elif not up and prev_h < h:
            
            base_h = prev_h
            up = True
        prev_h = h
    if up:
        count += prev_h - base_h
    return count

_n = int(input())
_H = list(map(int, input().split()))
print(solve(_n, _H))

Solution (Python):
n = int(input())
h = [int(i) for i in input().split()]
c = 0
active = 0
for i in h:
    if active < i:
        c += i - active 
    active = i
print(c)

Solution (Python):
n = int(input())
h = [int(i) for i in input().split()]
c = 0
active = 0
for i in h:
    if active >= i:
        active = i 
    else:
        c += i - active 
        active = i
print(c)

Solution (Python):
n=int(input())
h=list(map(int,input().split()))
zero=[0]*n
ans=0
while set(h)!={0}:
    for i in range(n):
        if h[i]==0:
            zero[i]=1

        if i==n-1 and h[i]!=0:
            h[i]+=-1
            ans+=1
        elif h[i]>=1:
            h[i]+=-1
        elif h[i]==0 and zero[i-1]==0 and i!=0:
            zero[i]=1
            ans+=1

print(ans)

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
ans = 0

def hidarihasi(h):
    for i,j in enumerate(h):
        if j!=0:
            return i
def zero(h, start):
    for i,j in enumerate(h[start:]):
        if j==0:
            return i+start
    else:
        return len(h)

def mizuyari(h):
    global ans
    for i in range(hidarihasi(h), zero(h, hidarihasi(h))):
        h[i] = h[i] -1
    ans = ans + 1
    
    
while sum(h)!=0:
    mizuyari(h)
print(ans)

Solution (Python):
import sys

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
LIST = lambda: list(map(int, INPUT().split()))

sys.setrecursionlimit(10 ** 9)


def main():
    N = INT()
    H = LIST()

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

    ans += H[-1] - border
    print(ans)


if __name__ == '__main__':
    main()

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


ans = 0
while True:
  
  if max(H) == 0:
    break
  i = 0
  while i < N:
    if H[i] == 0:
      i += 1
    else:
      ans += 1 
      while i < N and H[i] > 0: 
        H[i] -= 1
        i += 1
print(ans)