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):
import sys
import math
import itertools
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

N = i()
h = l()
ans = 0
start = 0
Flag = 0
for i in range(N-1):
    if h[i] > h[i+1]:
        Flag = 1
    if h[i] < h[i+1] and Flag == 1:
        kukan = h[start:i+1]
        ans -= h[i]
        ans += max(kukan)
        start = i+1
        Flag = 0
kukan = h[start:N]
ans += max(kukan)
print(ans)

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

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
l = [0]
l.extend(h)
l.append(0)
n += 2
ans = 0
while sum(l) != 0:
    for i in range(1, n):
        if (l[i] == 0) and (l[i-1] != 0):
            ans += 1
    for i in range(1, n):
        if l[i] != 0:
            l[i] -= 1
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] > h[i - 1]:
    ans += h[i] - h[i - 1]
print(ans)

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

kaisu=0

while max(h_ls)>0:
	M=h_ls.index(max(h_ls))
	takasa=h_ls[M]
	i=0
	while M+i<N and h_ls[min(M+i,N-1)]==takasa:
		h_ls[M+i]+=(-1)
		i+=1
	
	kaisu+=1

print(kaisu)

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

searchmin=10**4
pos=0
start=0
end=0
lenS=len(S)
count=0

def startendsearch():
    atta=False
    start=0
    end=0
    for i in range(lenS):
        if S[i]!=0 and atta==False:
            start=i
            atta=True
        if S[i]!=0 and atta==True:
            end=i
        if S[i]==0 and atta==True:
            break
    
    if atta==True:
        return start,end
    else:
        return 200,200
while sum(S)>0:
    s,e= startendsearch()
    
    
    for i in range(s,e+1):
        S[i]-=1
        
    
    count+=1
print(count)

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




count = 0
while True:
    if (n == 0):
        break
    p = 0
    check = 0
    for i in range(n):
        if (i == 0 and h_list[i] == 0):
            h_list.pop(i)
            
            check += 1
            n -= 1
            break
        elif (h_list[i] != 0):
            if (h_list[i] > 0):
                h_list[i] -= 1

        elif (i != 0 and h_list[i] == 0):
            break

    p += 1
    count += p
    count -= check

print(count)

Solution (Python):
n = int(input())
h_list = list(map(int,input().split()))
count = 0
for i in range(1,max(h_list) + 1):
  p = 0
  check = False
  for j in range(n):
    if i > h_list[j]:
      if check == True:
        p += 1
      check = False
      
    else:
      if j == n-1:
        p += 1
      check = True
  count += p
  
print(count)

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

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

base = min(h)
count = 0
already_zero = 0
more = 0

while 1:
  if max(H) == 0:
    break
  else:
    for i in range(N):
      if H[i] == 0 and more == 1:
        count += 1
        more = 0
        if i == N - 1:
          break
      else:
        if H[i] != 0:
          H[i] -= 1
          if more == 0:
            more = 1
      
      if more == 0 and i == N - 1:
        break
      
    else:
      count += 1
      more = 0
      already_zero = 0
      
print(count)

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

A = [[0]*N for _ in range(101)]

for i in range(101):
    for j in range(N):
        if H[j] > 0:
            A[i][j]=1
            H[j]-=1
        else:
            H[j] = 0
ans = 0
for i in range(101):
    flag = False
    for j in range(N):
        if A[i][j] == 1 and flag == False:
            flag = True
        elif A[i][j] == 0 and flag == True:
            ans += 1
            flag = False
    if flag:
        ans+=1
print(ans)

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

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

ans = lis[0]

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

Solution (Python):
num = int(input())
input_line = list(map(int,input().split(' ')))
flower = [0 for i in range(num)]
cnt = 0
while(True):
    flg = 0
    for n in range(num):
        if(flower[n] != input_line[n]):
            flower[n] += 1
            flg = 1
        elif(flg):
            flg = 0
            cnt += 1
        if(flg and (n==(num-1))):
            cnt += 1
    if(sum(flower) == sum(input_line)):
        break
print(cnt)

Solution (Python):


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


ans = 0
for num in reversed(range(1, max(h)+1)):
    
    
    count = 0
    for j in range(0, n-1):
        if h[j] == num and h[j+1] < num:
            count += 1
        if h[j] == num:
            h[j] = num-1
    if h[-1] == num:
        count += 1
        h[-1] = num-1
    ans += count

print(ans)

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

ans = 0
pre = 0
for i in h:
    if pre < i:
        ans += i-pre

    pre = i

print(ans)

Solution (Python):
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    
    ans = 0
    pre = 0
    for i in A:
        if pre < i:
            ans += i-pre
        pre = i
    
    return ans

print(solve())

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

    ans = 0
    pre = 0
    for i in H:
        if pre < i:
            ans += i-pre

        pre = i

    print(ans)


resolve()

Solution (Python):
n = int(input())
hh = tuple(map(int, input().split()))
h = [0] * n

prev = 0
ans = 0
while True:
    x = 0
    y = 0
    while x < n:
        if h[x] == hh[x]:
            x += 1
            continue

        ansadd = hh[x] - h[x]
        y = x + 1
        while y < n and h[y] < hh[y]:
            ansadd = min(ansadd, hh[y] - h[y])
            y += 1
        for i in range(x, y):
            h[i] += ansadd
        ans += ansadd

    if ans == prev:
        break
    prev = ans
print(ans)

Solution (Python):
n=int(input())
h=list(map(int,input().split()))
l=-1
r=-1
i=0
ans=0
while sum(h)!=0:
	if l==-1 and h[i]!=0:
		l=i
	if l!=-1 and h[i]==0:
		r=i-1
	elif r==-1 and i==n-1:
		r=i
	if l!=-1 and r!=-1:
		tmp=min(h[l:r+1])
		ans+=tmp
		for j in range(l,r+1):
			h[j]-=tmp
		l=-1
		r=-1
		i=-1
	i+=1
print(ans)

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
ans = 0
flag = 0
for i in range(102):
    flag = 0
    for j in range(n):
        if flag == 0 and h[j] != 0:
            ans += 1
            flag = 1
            h[j] -= 1
        elif flag == 1 and h[j] != 0:
            h[j] -= 1
        elif flag == 1 and h[j] == 0:
            flag = 0
    if sum(h) <= 0:
        print(ans)
        break

Solution (Python):
N=int(input())
H=list(map(int,input().split()))
h=min(H)
count=min(H)
flag=False
while max(H)>=h:
    for i in range(N):
        if flag and H[i]<=h:
            flag=False
            count+=1
        elif flag==False and H[i]>h:
            flag=True
        if i==N-1 and flag:
            count+=1
            flag=False
    h+=1
print(count)

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
ans=0
f=1
m=max(l)
for j in range(m):
    for i in range(n):
        if l[i]==0:
            f=1
        elif f==0:
            l[i]-=1
        else:
            ans+=1
            l[i]-=1
            f=0
    f=1
print(ans)

Solution (Python):
def main():
    n = int(input())
    h = list(map(int, input().split()))
    x = [0] * n
    ans = 0
    
    for _ in range(110):
        pre  = False
        for i in range(n):
            if x[i] < h[i]:
                x[i] += 1
                if pre == False:
                    ans += 1
                    pre = True
            else:
                pre = False 
            
    print(ans)
    
    
if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
H=list(map(int, input().split()))
ans=now=0
for h in H:
  if now<h:
    ans+=h-now
  now=h
print(ans)

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

res = 0
while max(h) > 0:
    i = 0
    while i < n:
        if h[i] == 0:
            i += 1
            continue

        res += 1
        while i < n and h[i] > 0:
            h[i] -= 1
            i += 1

print(res)

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

res = 0
while max(h) > 0:
    first_flag = True
    for i in range(n):
        if h[i] == 0:
            first_flag = True
            continue

        if first_flag:
            res += 1
            first_flag = False
        h[i] -= 1

print(res)

Solution (Python):
n = int(input())
goal = list(map(int,input().split()))
now = [0]*n
ans = 0

while goal != now:
    x = 0
    for i in range(n):
        if x == 0 and now[i] != goal[i]:
            x = 1
            now[i] += 1
        elif x == 1 and now[i] != goal[i]:
            now[i] += 1
        elif x == 1 and now[i] == goal[i]:
            break
    ans += 1

print(ans)

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

sumh = h[0]
for x in range(N):
    if x != N - 1:
        if h[x + 1] > h[x]:
            sumh += h[x + 1] - h[x]
print(sumh)

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

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

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

ans = 0
while sum(H) > 0:
    pre = 0
    for i in range(N):
        if pre > 0 and H[i] == 0:
            break
        if H[i] != 0:
            H[i] -= 1
            pre = H[i] + 1
    ans += 1

print(ans)

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

ans=active=0
for i in range(n):
    if active>=h[i]:
        active=h[i]
    else:
        ans+=h[i]-active
        active=h[i]
print(ans)

Solution (Python):
def main():
    N = int(input())
    h = list(map(int, input().split())) + [0]
    ans = 0; conti = False
    for line in range(1, 101):
        for i in range(N+1):
            if h[i] >= line and conti:
                continue
            elif h[i] >= line and not conti:
                conti = True
                ans += 1
            elif h[i] < line and conti:
                conti = False
            elif h[i] < line and not conti:
                continue
            else:
                pass

    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
import sys

input = sys.stdin.readline
INF = float("inf")


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

    h += [0]
    N += 1
    ans = 0
    while True:
        l = 0
        min_h = INF
        for r in range(N):
            if h[r] == 0:
                if min_h == INF:
                    l += 1
                else:
                    for i in range(l, r):
                        h[i] -= min_h
                    ans += min_h
                    l = r + 1
                    min_h = INF
            else:
                if h[r] < min_h:
                    min_h = h[r]
        if sum(h) == 0:
            break

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
from collections import deque

N = int(input())
h = list(input().split())
flower = deque([int(h[i]) for i in range(N)])
goal = [0 for i in range(N)]
count = 0

flower.append(0)

while flower != deque([]):
    for i in range(len(flower)):
        if flower[0] == 0:
            flower.popleft()
        else:
            break
    
    for i in range(len(flower)-1):
        if flower[i] == 0 and flower[i+1] != 0:
            count += 1
        elif flower[i] == 0:
            continue
        elif i == len(flower) - 1:
            count += 1
            flower[i] -= 1
        else:
            flower[i] -= 1
    count += 1

print(count-1)

Solution (Python):
n=int(input())
hs=list(map(int,input().split()))
c=0
m=max(hs)
while not m==0:
    b=0
    for i,h in enumerate(hs):
        if h==m:
            if not b==m:
                c+=1
            hs[i]-=1
        b=h
    m=max(hs)
print(c)

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

while sum_h != sum_now:
    for i in range(n):
        if h[i] != 0:
            start = i
            break
     
    goal = n
    
    for i in range(n-start):
        if h[start+i] == 0:
            goal = start + i
            break
            
        if start + i == n-1:
            goal == n
        
    water = min(h[start:goal])
    
    for i in range(start,goal):
        h[i] -= water
        
    ans += water
    sum_now += water * (goal-start)
        
print(ans)

Solution (Python):
import fractions
import sys
from functools import reduce
import math

input = sys.stdin.readline


def main():
    n = int(input())
    h = input_list()
    count = 0
    while list(set(h)) != [0]:
        count += 1
        flag = False
        for i, v in enumerate(h):
            if v != 0:
                flag = True
                h[i] -= 1
            else:
                if flag:
                    break
    print(count)

def divide_two(n):
    c = 0
    while True:
        if c >= 2:
            break
        if n % 2 != 0:
            break
        n //= 2
        c += 1
    return c

def get_camulative(l):
    import itertools
    
    return [0] + list(itertools.accumulate(l))

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def input_list():
    return list(map(int, input().split()))


def input_list_str():
    return list(map(str, input().split()))


def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


def gcd(*numbers):
    return reduce(fractions.gcd, numbers)


def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)


if __name__ == "__main__":
    main()

Solution (Python):
import math

import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit


ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    h = [int(i) for i in ipt().split()]
    ans = 0
    f = True
    mih = min(h)
    for i,hi in enumerate(h):
        if hi == mih:
            f = False
        elif f:
            ans += max(0,hi-h[i+1])
        else:
            ans += max(0,hi-h[i-1])
    print(ans+mih)
    return

if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
Tree_List=list(map(int,input().split()))
ct =0
for i in range(n):
    while Tree_List[i] != 0:
        k = i + 1
        while k < n and Tree_List[k] != 0: 
            k+=1
        Tree_List[i:k]=map(lambda x:x-1,Tree_List[i:k])
        ct += 1
        
print(ct)

Solution (Python):
n=int(input())
Tree_List=list(map(int,input().split()))
ct =0
for i in range(n):
    while Tree_List[i] != 0:
        k = i
        while k + 1 < n and Tree_List[k + 1] != 0: 
            k+=1
        Tree_List[i:k + 1]=map(lambda x:x-1,Tree_List[i:k + 1])
        ct += 1
        
print(ct)

Solution (Python):
n=int(input())
Tree_List=list(map(int,input().split()))
ct =0
for i in range(n):
    while Tree_List[i] != 0:
        k = i
        while Tree_List[k] != 0: 
            k+=1
            if k == n:
                break
        Tree_List[i:k]=map(lambda x:x-1,Tree_List[i:k])
        ct += 1
        
print(ct)

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

while any(h for h in H):
	count += 1
	flag = False
	for i, h in enumerate(H):
		if h:
			flag = True
			H[i] -= 1
		else:
			if flag == True:
				break
print(count)

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

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

Solution (Python):
import numpy as np
n=int(input())
h=list(map(int,input().split()))
h.insert(0,0)
h.append(0)
p=max(h)
arr=np.array(h)
cnt=0
for i in range(p,0,-1):
    x=np.copy(arr)
    x[x!=i]=0
    x[x==i]=1
    temp=np.arange(len(x))
    temp[x>0]=0
    np.maximum.accumulate(temp,out=temp)
    left=temp
    x_reversed=x[::-1]
    temp=np.arange(len(x))
    temp[x_reversed>0]=0
    np.maximum.accumulate(temp,out=temp)
    right=len(x)-1-temp[::-1]
    y=right-left-1
    y[x==0]=0  
    z=np.nonzero(np.diff(np.nonzero(x==0)[0])-1)
    cnt+=len(z[0])
    arr=arr-x
print(cnt)

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

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

p=max(h)
cnt=[]
ct=0


for i in range(p):
    ct=0
    for j in range(len(h)-1):
        if h[j]==p-i:
            if h[j]==h[j+1]:
                h[j]-=1
                if j==len(h)-2:
                    ct+=1
                    h[j+1]-=1
            else:
                ct+=1
                h[j]-=1
        if j==(len(h)-2):
            if h[j]!=p-i and h[j+1]==p-i:
                h[j+1]-=1
                ct+=1
    cnt.append(ct)
    


k=sum(cnt)
if len(h)==1:
    print(h[0])
else:
    print(k)

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

for i in range(N):
    if h[n]<=h[n+1]:
        m=h[n+1]-h[n]
        Answer=Answer+m
    else :
        pass
    n=n+1
print(Answer)

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

for i in range(N):
    if h[n]<=h[n+1]:
        m=h[n+1]-h[n]
        Answer=Answer+m
    else :
        pass
    n=n+1
print(Answer)

Solution (Python):
from itertools import groupby
n = int(input())
h = list(map(int,input().split()))
max_h = max(h)
for i in range(n):
    h[i] = [h[i],0]
ans = 0
for i in range(max_h):
    for is_more,group in groupby(h, key=lambda a:bool(a[0] > a[1])):
        group = list(group)
        if is_more:
            ans += 1
    for hs in h:
        hs[1] += 1
print(ans)

Solution (Python):
n=int(input())
h=list(map(int, input().split()))
count = 0
def mizu(h):
    global count
    if len(h) == 0:
        return
    if len(h) == 1:
        count += h[0]
        return
    m = min(h)
    count += m
    for i in range(len(h)):
        h[i] -= m
    while 0 in h: 
        mizu(h[:h.index(0)])
        h = h[h.index(0)+1:]
    mizu(h)

mizu(h)
print(count)

Solution (Python):
import sys


if __name__ == "__main__":
    n = int(input())
    h = list(map(int,input().split()))
    cnt = 0
    ans = 0
    while True:
        if sum(h) == 0:
            break
        koho = []
        p = []
        for i in range(n):
            if h[i] != 0:
                koho.append(h[i])
            else:
                p.append(koho)
                p.append([0])
                koho = []
        if len(koho)>0:
            p.append(koho)
        for i in range(len(p)):
            if len(p[i]) == 0:
                continue
            d = min(p[i])
            ans += d
            for j in range(len(p[i])):
                p[i][j] -= d
        h = []
        for i in range(len(p)):
            for j in range(len(p[i])):
                h.append(p[i][j])
        cnt += 1
    print(ans)

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

ans = 0
for i in range(1, max(lh)+1):
    if lh[0] >= i:
        cnt = 1
    else:
        cnt = 0
    j = 1
    while j < n:
        if lh[j-1] < i and lh[j] >= i:
            cnt += 1
        j += 1
    ans += cnt

print(ans)

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
cnt = int()
for i in reversed(range(1, max(h)+1)):
    tmp = list()
    for j in h:
        if i <= j:
            tmp.append(1)
        else:
            tmp.append(0)
    
    if tmp[0]==1:
        cnt += 1
    for j in range(1, n):
        if tmp[j]-tmp[j-1] == 1:
            cnt += 1

print(cnt)

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

ans = 0
cnt = 0

for i in range(1, max(h) + 1)[::-1]:
    cnt = 0
    for j in range(n):
        if h[j] == i:
            h[j] -= 1
            cnt += 1
            if h[j + 1] == i:
                cnt -= 1
    ans += cnt

print(ans)

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

ans = 0
cnt = 0

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

print(ans)

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

while l!=h:
    x=0
    for i in range(n):
        if x==0:
            if i!=n-1:
                if l[i]!=h[i]:
                    l[i]+=1
                    x=1
            else:
                if l[i]!=h[i]:
                    l[i]+=1
                    x=1
                    ans+=1
        elif i!=n-1:
            if l[i]!=h[i]:
                l[i]+=1
            else:
                ans+=1
                break
        else:
            if l[i]!=h[i]:
                l[i]+=1
                ans+=1
            else:
                ans+=1
    
print(ans)

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

print(sum([h[i] - h[i - 1] for i in range(1, n) if h[i] > h[i - 1]]) + h[0])

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

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

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

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

Solution (Python):
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction



mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]






def solve(A):
    if(len(A)==0):
        return 0
    if(max(A)==min(A)):
        return min(A)
    if(0 not in A):
        x=min(A)
        A=[A[i]-x for i in range(len(A))]
        ans=x
        i=0
        while(i<len(A)):
            while(i<len(A) and A[i]==0):
                i+=1
            k=0
            while(i+k<len(A) and A[i+k]!=0):
                k+=1
            ans+=solve(A[i:i+k])
            i+=k
        return ans
    ans=0
    i=0
    while(i<len(A)):
        while(i<len(A) and A[i]==0):
            i+=1
        k=0
        while(i+k<len(A) and A[i+k]!=0):
            k+=1
        ans+=solve(A[i:i+k])
        i+=k
    return ans





n=l()
h=l()
ans=solve(h)
print(ans)

Solution (Python):
import sys
import math
import itertools

n = int(input())
h=list(map(int,input().split()))
isStarted = False
fin = False
flowers = [0] * len(h)
all = 0
for i in h:
    all += i
done = False
ans=0
while (not done):
    tmp = 0
    isStarted=False
    for i in range(len(flowers)):
        if (flowers[i] == h[i] and isStarted):
            ans+=1
            isStarted = False
            break
        if (flowers[i] < h[i] and not isStarted):
            isStarted = True
        if (isStarted):
            flowers[i] += 1
        tmp += flowers[i]
        if (all == tmp):
            done = True
        if (isStarted and i == len(flowers) - 1):
            ans+=1
            isStarted = False
            break
print(ans)

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

Solution (Python):
N = int(input())
hlist = list(map(int, input().split()))
hlist.insert(0, 0)
hlist.append(0)

water = 0
ceros = hlist.count(0)

while ceros!= len(hlist):
  Hlist = []
  cerolist = []
  for i in range(len(hlist)):
    Hlist.append(hlist[i])

  for j in range(ceros):
    p = Hlist.index(0)
    cerolist.append(p)
    Hlist[p] = 'None'

  for k in range(ceros- 1):
    p = cerolist[k]
    q = cerolist[k+ 1]
    if(q- p!= 1): 
      m = min(hlist[p+ 1: q])
      water+= m
      for l in range(p+ 1, q):
        hlist[l]-= m
      
  ceros = hlist.count(0)
print(water)

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

def dac(hs):
  if not hs:
    return 0
  result = min(hs)
  hs = [h-result for h in hs]
  start = 0
  for i in range(len(hs)):
    if hs[i] == 0:
      result += dac(hs[start:i])
      start = i+1
  if start < len(hs):
    result += dac(hs[start:])
  
  return result
    
print(dac(hs))

Solution (Python):

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

ct =0
for i in range(n):
    while Tree_List[i] != 0:
        
        if i == n-1:
            Tree_List[i] -= 1
        
        else:
            
            k = i + 1
            while Tree_List[k] != 0: 
                k+=1
                if k == n:
                    break
            Tree_List[i:k]=map(lambda x:x-1,Tree_List[i:k])
        
        ct += 1
        
print(ct)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7


N = INT()
h = LIST()
h.insert(0, 0)
 
ans = 0
for i in range(1, max(h)+1):
	for j in range(1, len(h)):
		if h[j-1] < i and i <= h[j]:
			ans += 1
 
print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7


N = INT()
h = LIST()
ans = 0
while sum(h) > 0:
	flg = False
	for i in range(N):
		if flg and h[i] == 0:
			flg = False
			ans += 1
		elif h[i] != 0:
			flg = True
			h[i] -= 1
	if flg:
		ans += 1
print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7


N = INT()
S = LIST()
S.insert(0, 0)

ans = 0
for i in range(1, max(S)+1):
	for j in range(1, len(S)):
		if S[j-1] < i and i <= S[j]:
			ans += 1

print(ans)

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
ok = [False for _ in range(n)]
ans = 0
while not all(ok):
    l = ok.index(False)
    for i in range(l, n):
        if ok[i] == True:
            break
        else:
            r = i
    m = min(h[l:r+1])
    ans += m
    for i in range(l, r + 1):
        h[i] -= m
        if h[i] == 0:
            ok[i] = True
print(ans)