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 numpy as np
n = int(input())
h = np.array(list(map(int, input().split())))
ans = 0
while (any(h > 0)):
  count = 0
  for i in range(n-1):
    if h[i] > 0 and h[i + 1] <= 0:
      count += 1
  if h[n-1] > 0:
    count += 1
  ans += count
  h -= 1
print(ans)

Solution (Python):
n = int(input())
flower = [int(i) for i in input().split()]

ans = 0
for i in range(n):
    left = -1
    for j in range(n):
        if flower[j]:
            left = j
            break
    if left == -1:
        break

    MIN = flower[left]
    for k in range(left, n):
        if flower[k] == 0:
            right = k
            break
        else:
            MIN = min(MIN, flower[k])
    else:
        right = n
    for l in range(left, right):
        flower[l] -= MIN
    ans += MIN
print(ans)

Solution (Python):
n = int(input())
h = list(map(int,input().split(" ")))
k=0
for i in range(1,max(h)+1):
    c=0
    for j in h:
        if j >= i:
            if c==0:
                k+=1
                c=1
        else:
            c=0
print(k)

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

water = 0
ans = 0
for hi in h:
    if water < hi:
        ans += hi - water
    water = hi
print(ans)

Solution (Python):
if True:
    n= int(input())
    hn= list(map(int, input().split()))
else:
    import sys
    args = sys.argv
    set_flg = False
    if len(args) == 2:
        set_flg = True
        if args[1] == "2":
            n=5
            hn=[3,1,2,3,1]
        elif args[1] == "3":
            n=8
            hn=[4,23,75,0,23,96,50,100]
        else:
            set_flg = False

    if set_flg == False:
        n=4
        hn=[1,2,2,1]





water = 0
target_idx = 0

for i in range(0,len(hn)):
    while hn[i] > 0:
        if hn[i] == 0:
            break

        for j in range(i+1,len(hn)):
            
            if hn[j] > 0:
                hn[j] -=1
            else:
                break
        hn[i] -= 1
        water += 1

print(water)

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

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

print(ans)

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

base = [0]*(n+1)
base[0] = 1
h_max = max(h)
count = 0

for i in range(h_max):
  for j in range(1,n+1):
    if i == h[j-1]:
      base[j] = 1

    if (base[j-1] == 1) and (base[j] == 0):
      count = count + 1
    
print(count)

Solution (Python):
import sys
input = sys.stdin.readline
n = int(input()) 

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

ans = 0
start = 0
end = 0

ans = 0
while True:
    left = -1
    for i in range(n):
        if h[i]:
            left = i
            break
    if left == - 1:
        break

    right = n
    for i in range(left, n):
        if h[i] == 0:
            right = i
            break

    right_min = min(h[left:right])
    ans += right_min
    for i in range(left, right):
        h[i] -= right_min

print(ans)

Solution (Python):
mod = 10 ** 9 + 7
mod2 = 2 ** 61 + 1
from collections import deque
import heapq
from bisect import bisect_left, insort_left, bisect_right

_NUMINT_ALL = list(range(10))


def main():
    ans = solve()
    if ans is not None:
        print(ans)


def solve():
    N = iip(False)
    H = iip(True)
    h = [0 for i in range(N)]

    ans = 0
    while True:
        st = False
        for i in range(N):
            if not st:
                if h[i] != H[i]:
                    st = True
                    h[i] += 1
                    ans += 1
                elif i == N-1:
                    return ans
            elif st is True:
                if h[i] != H[i]:
                    h[i] += 1
                else:
                    break



def iip(listed=True, num_only=True):  
    if num_only:
        ret = [int(i) for i in input().split()]
    else:
        ret = [int(i) if i in _NUMINT_ALL else i for i in input().split()]

    if len(ret) == 1 and not listed:
        return ret[0]
    return ret


def saidai_kouyakusuu(A):  
    l = len(A)
    while True:
        m = min(A)
        mx = max(A)
        if m == mx:
            return m

        for i in range(l):
            if A[i] % m == 0:
                A[i] = m
            else:
                A[i] %= m


def sort_tuples(l, index):  
    if isinstance(l, list):
        l.sort(key=lambda x: x[index])
        return l
    else:
        l = list(l)
        return sorted(l, key=lambda x: x[index])


def count_elements(l):  
    d = {}
    for i in l:
        if i in d:
            d[i] += 1
        else:
            d[i] = 1
    return d


def safeget(l, index, default="exception"):  
    if index >= len(l):                      
        if default == "exception":
            raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。配列の長さは", len(l), "です"]))
        else:
            return default
    elif index < 0:
        if default == "exception":
            raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。負の値は許可されていません"]))
        else:
            return default
    else:
        return l[index]


def iipt(l, listed=False, num_only=True):  
    ret = []
    for i in range(l):
        ret.append(iip(listed=listed, num_only=num_only))
    return ret


def sortstr(s):  
    return "".join(sorted(s))


def iip_ord(startcode="a"):  
    if isinstance(startcode, str):
        startcode = ord(startcode)
    return [ord(i) - startcode for i in input()]


def YesNo(s):  
    if s:
        print("Yes")
    else:
        print("No")


def fprint(s):  
    for i in s:
        print(i)


def bitall(N):  
    ret = []
    for i in range(2 ** N):
        a = []
        for j in range(N):
            a.append(i % 2)
            i //= 2
        ret.append(a)
    return ret

def split_print_space(s):  
    print(" ".join([str(i) for i in s]))


def split_print_enter(s):  
    print("\n".join([str(i) for i in s]))


def soinsuu_bunkai(n):  
    ret = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):  
    if n <= 0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n - r + 1, n + 1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r + 1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        
        pass
    return ret


def inv(n, mod):  
    return power(n, mod - 2)


def power(n, p, mod_=mod):  
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p // 2, mod_) ** 2) % mod_
    if p % 2 == 1:
        return (n * power(n, p - 1, mod_)) % mod_


if __name__ == "__main__":
    main()

Solution (Python):
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect



import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7

def main():
  N = int(readline())
  H = np.array(readline().split(), dtype = np.int32)
  
  def F(L,R):
    if R<L:
      return 0
    idx = L + H[L:R+1].argmin()
    x = H[idx]
    H[L:R+1] -= x
    return x + F(L, idx-1) + F(idx+1,R)
  
  answer = F(0,N-1)
  print(answer)
  
  
  
if __name__ == '__main__':
  main()

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate, groupby
    
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    

    
    

    n = int(input())
    h = list(map(int, input().split()))
    res = 0
    while sum(h):
        for i in range(n):
            if h[i]==0:
                continue
            h[i] -= 1
            if i==n-1:
                res += 1
            elif h[i+1]==0:
                res += 1
    print(res)

if __name__ == '__main__':
    main()

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

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

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

print(cnt)

Solution (Python):
n=int(input())
l=[int(i) for i in input().split()]
v=sum(l)
e=0
for i in range(max(l)):
  ef=0
  for j in l:
    if j>i:
      ef+=1
    else:
      if ef>0:
        e+=ef-1
      ef=0
  if ef>1:
    e+=ef-1
print(v-e)

Solution (Python):
N = int(input())
h = list(map(int, input().split()))
ans = 0
while True:
    i = 0
    if not any(h):  
        break
    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()))
h.append(0)
count = 0
for j in range(100):
    work = []
    temp = []
    for el in h:
        if el == 0:
            if temp != []:
                m = min(temp)
                count += m
                for i in range(len(temp)):
                    temp[i] -= m
                temp.append(0)
                work.append(temp)
                temp = []
        else:
            temp.append(el)
    h = []
    for w in work:
        for el in w:
            h.append(el)
print(count)

Solution (Python):
N = int(input())
h = list(map(int, input().split()))
ans = 0
while True:
    i = 0
    if not any(h):
        break
    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 sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
h = LI()
ans = 0
while sum(h) > 0:
    flg = False
    for j in range(n):
        if h[j] > 0:
            if not flg:
                flg = True
                ans += 1
            h[j] -= 1
        else:
            flg = False
print(ans)

Solution (Python):
def main():
    n, *h = map(int, open(0).read().split())
    h = [0] + h
    ans = sum([max(0,h[i+1]-h[i]) for i in range(n)])
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    n, *h = map(int, open(0).read().split())
    ans = 0
    for i, j in zip([0] + h, h):
        if i < j:
            ans += (j - i)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    n, *h = map(int, open(0).read().split())
    ans = 0
    f = True
    base = 0
    for i, j in zip(h, h[1:]):
        g = i <= j
        if f and not g:
            ans += i - base
        if not f and g:
            base = i
        f = g
    else:
        if f:
            ans += h[-1] - base
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n = ni()
a = na()

flag = True
ans = 0
while flag:
    flag = False
    last = 0
    for i in range(n):
        t = a[i]
        if a[i] != 0:
            flag = True
            if last == 0:
                ans += 1
            a[i] -= 1
        last = t

print(ans)

Solution (Python):
n=int(input())
h=list(map(int,input().split()))
ans=0
def mizu(h_list):
  global ans
  if not h_list:
    return
  if max(h_list)==0:
    return
  m=min(h_list)
  ans+=m
  h_list_=list(map(lambda x :x-m, h_list))
  zero_ind = h_list_.index(0)
  mizu(h_list_[:zero_ind])
  mizu(h_list_[zero_ind+1:])
mizu(h)
print(ans)

Solution (Python):
N = int(input())
h = list(map(int, input().split()))
cnt = 0
while True:
    if max(h) == 0:
        print(cnt)
        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

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

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

ans = 0
while True:
    if not any(h):
        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):
def main():
    N = int(input())
    lst = list(map(int, input().split()))
    groups = [lst]
    ans = 0

    while len(groups) != 0:
        
        targetgroup = groups.pop()

        minval = min(targetgroup)
        targetgroup = [v - minval for v in targetgroup]
        ans += minval
        

        tmp = []
        for index, v in enumerate(targetgroup):
            if v != 0:
                tmp.append(v)
            if (v==0 or index==len(targetgroup)-1) and (len(tmp) != 0):
                groups.append(tmp)
                tmp = []
        
    print(ans)
main()

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

Solution (Python):
n=int(input())
h=list(map(int,input().split()))
zeros=[]
prev=0
for i in  range(n):
  if h[i]==0:
    if i==0:
      prev=i+1
    else:
      if prev<=i-1:
        zeros.append((prev,i-1))
      prev=i+1
if prev<=n-1:
  zeros.append((prev,n-1))
cnt=0
while zeros:
  l,r=zeros.pop()
  m=min(h[l:r+1])
  cnt+=m
  prev=l
  for i in range(l,r+1):
    h[i]-=m
    if h[i]==0:
      if i==l:
        prev=i+1
      else:
        if prev<=i-1:
          zeros.append((prev,i-1))
        prev=i+1
  if prev<=r:
    zeros.append((prev,r))
print(cnt)

Solution (Python):
n=int(input())
h=list(map(int,input().split()))
zeros=[]
prev=0
for i in  range(n):
  if h[i]==0:
    if i==0:
      prev=i+1
    else:
      if prev<=i-1:
        zeros.append((prev,i-1))
      prev=i+1
if prev<=n-1:
  zeros.append((prev,n-1))
cnt=0
while zeros:
  l,r=zeros.pop()
  m=min(h[l:r+1])
  cnt+=m
  prev=l
  for i in range(l,r+1):
    h[i]-=m
    if h[i]==0:
      if i==l:
        prev=i+1
      else:
        if prev<=i-1:
          zeros.append((prev,i-1))
        prev=i+1
  if prev<=r:
    zeros.append((prev,r))
print(cnt)

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

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

h1 = h+ []
lng = len(h1)
ans = 0
while not all([i == 0 for i in h1]):
    left = lng
    right = 0
    amin = float("inf")
    for i in range(lng):
        if h1[i] == 0 and amin == float("inf"):
            continue
        if amin > 0 and h1[i] == 0:
            break
        amin = min(amin, h1[i])
        left = min(left, i)
        right = max(right, i)

    ans += amin
    for i in range(left, right+1):
        h1[i] -= amin

print(ans)

Solution (Python):
N = int(input())
h = list(map(int, input().split()))
h.append(0)
ans = 0
while h.count(0) < N+1:
  count = 0
  for i in range(N+1):
    if h[i] > 0:
      count += 1
      h[i] -= 1
    else:
      if count > 0:
        ans += 1
      count = 0
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 = list(map(int, input().split()))
flower=[0]*N
count=0
on=0
for j in range(max(h)):
    for i in range(N):
        if i==0:
            on=0
        if flower[i]<h[i]:
            flower[i]+=1
            on=1
            if i==N-1:
                count+=1
        elif on==1 and flower[i]==h[i]:
            count+=1
            on=0
        
        
print(count)

Solution (Python):
N=int(input())
h=list(map(int,input().split()))
h.append(0)
ans=0
flag = False
for hei in range(1,101):
  for i in range(N+1):
    if h[i] >= hei and i!=N:
      flag = True
    else:
      if flag:
        ans+=1
        flag = False
print(ans)

Solution (Python):
import numpy as np

N = int(input())
H = np.array(list(map(int, input().split())))
cnt = 0
f_f = 0 
n_f = 0 
v = 0 

cnt = min(H)
H -=cnt
precnt = 0
for i in range(max(H)):
    a = 0
    for j in range(N):
        v=0
        if j == 0 and H[j] > 0:
            v+=1
        elif H[j] > 0 and H[j-1] == 0:
            v+=1
        cnt+=v
        a+=v

    for j in range(N):
        if H[j] > 0:
            H[j]-=1
print(cnt)

Solution (Python):
n = int(input())
h = list(map(int,input().split()))
count = 0
for i in range(1,101):
    flag = 1
    for j in range(n):
        if h[j] >= i:
            if flag:
                count += 1
                flag = 0
        else:
            flag = 1
print(count)

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

Solution (Python):
def solve():
    N = int(input())
    hlist = list(map(int, input().split()))
    tot = 0
    for i in range(N):
        if i==0:
            tot += hlist[i]
        else:
            if hlist[i]-hlist[i-1]>0:
                tot += hlist[i]-hlist[i-1]
    
    print(tot)
solve()

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

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

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

Solution (Python):
n = int(input())
h = list(map(int,input().split()))
f = [0]*n
fflag = [False]*n
cnt = 0
flag = False
while False in fflag:
    for i in range(n):
        if f[i] == h[i]:
            fflag[i] = True
        if not fflag[i]:
            f[i] += 1
            flag = True
        elif flag:
            cnt += 1
            flag = False
    if flag:
        cnt += 1
        flag = False
print(cnt)

Solution (Python):
N = int(input())
h =  [int(i) for i 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 = 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):
num = int(input())
count = 0
num_list = list(map(int,input().split()))
while(1):
  dummy = max(num_list)
  if dummy == 0:
    break
  flag = "nocheck"
  for i in range(num):
    if num_list[i] == dummy:
      num_list[i] -= 1
      flag = "check"
    else:
      if flag == "check":
        flag = "nocheck"
        break
  count += 1
print(count)

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

change_count = 0

while True:
    for i in range(n+1):
        status = [0] * 2
        if h_ls[i] == 0:
            status[0] = 'zero'
        else:
            status[0] = 'not_zero'
        if h_ls[i+1] == 0:
            status[1] = 'zero'
        else:
            status[1] = 'not_zero'
        if status[0] != status[1]:
            change_count+= 1
    for i in range(n+2):
        if h_ls[i] != 0:
            h_ls[i] -= 1
    if h_ls == [0] * (n+2):
        break

count = change_count // 2
print(count)

Solution (Python):
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
from math import *
from fractions import *

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

def f(arr):
    m = min(arr)
    for i in range(len(arr)):
        arr[i] -= m
    buf = []
    ret = m
    for i in arr:
        if i == 0:
            if len(buf) > 0:
                ret += f(buf)
                buf = []
        else:
            buf.append(i)
    if len(buf) > 0:
        ret += f(buf)
    return ret

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

main()

Solution (Python):
def main():
    n = int(input())
    num_list = list(map(int, input().split()))

    ans = 0
    while(1):
        if num_list.count(0) == n:
            break
        i = 0
        while(i < n):
            if num_list[i] == 0:
                i += 1
            else:
                ans += 1
                while(i < n and num_list[i] != 0):
                    num_list[i] -= 1
                    i += 1

    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
n,*h=map(int,open(0).read().split())
ans=h[0]
for i in range(n-1):
    ans+=max(h[i+1]-h[i],0)
print(ans)

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

Solution (Python):

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

def func(h):
    if len(h) == 0:
        return 0
    res = min(h)
    h = [i - min(h) for i in h]
    next_h = []
    flag = False
    tmp = 0
    for i in range(len(h)):
        if h[i] != 0 and not flag:
            flag = True
            tmp = i
        if h[i] == 0 and flag:
            next_h.append(h[tmp:i])
            flag = False
    if flag:
        next_h.append(h[tmp:len(h)])
    
    
    for i in range(len(next_h)):
        res += func(next_h[i])
    return res

print(func(h))

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

def func(arr):
    if len(arr) == 0:
        return 0
    tmp = min(arr)
    arr = [i - tmp for i in arr]
    n_arr = []
    strt = 0
    flag = False
    for i in range(len(arr)):
        if arr[i] == 0 and flag:
            n_arr.append(arr[strt:i])
            flag = False
        if arr[i] != 0 and not flag:
            flag = True
            strt = i
    if flag:
        n_arr.append(arr[strt:])
    s = tmp
    for i in n_arr:
        s += func(i)
    return s

n = INT()
h = LIST()
ans = func(h)
print(ans)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

def func(arr):
    if len(arr) == 0:
        return 0
    tmp = min(arr)
    for i in range(len(arr)):
        arr[i] -= tmp
    n_arr = []
    strt = 0
    flag = True if arr[0] != 0 else False
    for i in range(len(arr)):
        if arr[i] == 0 and flag:
            n_arr.append(arr[strt:i])
            flag = False
        if arr[i] != 0 and not flag:
            flag = True
            strt = i
    if flag:
        n_arr.append(arr[strt:])
    s = tmp
    for i in n_arr:
        s += func(i)
    return s

n = INT()
h = LIST()
ans = func(h)
print(ans)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

def func(arr):
    if len(arr) == 0:
        return 0
    if len(arr) == 1:
        return arr[0]
    tmp = min(arr)
    for i in range(len(arr)):
        arr[i] -= tmp
    n_arr = []
    strt = 0
    flag = True if arr[0] != 0 else False
    for i in range(len(arr)):
        if arr[i] == 0 and flag:
            n_arr.append(arr[strt:i])
            flag = False
        if arr[i] != 0 and not flag:
            flag = True
            strt = i
    if flag:
        n_arr.append(arr[strt:])
    s = tmp
    for i in n_arr:
        s += func(i)
    return s

n = INT()
h = LIST()
ans = func(h)
print(ans)

Solution (Python):
n,*h=map(int,open(0).read().split())
ans=h[0]
for i in range(n-1):
  ans+=max(h[i+1]-h[i],0)
print(ans)

Solution (Python):
def resolve():
    def countis(inputlist):
        ret = 0
        lenlist = len(inputlist)
        for i in range (lenlist-1):
            if inputlist[i] != 0 and inputlist[i+1] == 0:
               ret += 1
        return ret
    n = int(input())
    h = list(map(int, input().split()))
    h.append(0)
    ans = 0
    while True:
        if sum(h) == 0:
            print(ans)
            exit()
        else:
            ans += countis(h)
            h = list(map(lambda x: x-1, h))
            for j in range(len(h)):
                if h[j] <0 :
                    h[j] =0
resolve()

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

Solution (Python):
import numpy as np
n = int(input())
l = np.array(list(map(int,input().split())))

def counter(l):
  count = 1
  nc = 'True'
  for i in l:
    if i > 0:
      nc = 'False'
    elif i <= 0 and nc == 'False':
      count += 1
      nc = 'True'
  if l[-1] <= 0:
    count -=1
  return count

ans = 0
while any([i>0 for i in l]):
  ans +=  counter(l)
  l = l - np.ones(n)
print(ans)

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

cnt = 0
while True:
    allzero = True
    for i in range(N):
        if(h[i] != 0):
            allzero = False
    if allzero: break

    l = 0
    while h[l] == 0:l += 1
    r = l
    while r <N-1 and h[r+1]!=0:
        r +=1
    cnt += 1
    for i in range(l,r + 1,1):
        h[i] -=1
print(cnt)

Solution (Python):
import numpy as np

def search_min(h):
    global ans
    my_min = min(h)
    ans += my_min
    if len(h) == 1:
        return 0
    min_index = [i for i, k in enumerate(h) if k == my_min]
    h -= my_min
    if len(min_index) > 1:
        for i in range(len(min_index) - 1):
            h_new = h[min_index[i] + 1: min_index[i + 1]]
            if len(h_new) > 0:
                search_min(h_new)
    h_new = h[: min_index[0]]
    if len(h_new) > 0:
        search_min(h_new)
    h_new = h[min_index[-1] + 1:]
    if len(h_new) > 0:
        search_min(h_new)
        
    return 0
    
if __name__ == "__main__":
    N = int(input())
    H = list(map(int, input().split()))
    H_new = [H[i] for i in range(1, len(H)) if H[i] != H[i - 1]]
    H_new.insert(0, H[0])
    H_new = np.array(H_new)
    ans = 0
    search_min(H_new)
    print(ans)

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