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 copy
N=int(input())
H = [int(x) for x in input().split()]

if N==1:
    print(H[0])
    sys.exit()

cnt=0
while True:
    f=True
    for h in H:
        if h!=0:
            f=False
            break
    if f:
        break

    H_new = copy.copy(H)
    if H[0]!=0:
        if H[0]!=0:
            cnt+=1
        H_new[0]-=1
    for i in range(1,len(H)):
        if H[i-1]==0 and H[i]!=0:
            cnt+=1
        if H_new[i]!=0:
            H_new[i]-=1
    H = copy.copy(H_new)


print(cnt)

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

N = int(input().strip())
H = [int(x) for x in input().strip().split()]

G = [0] * N
ans = 0
while H != G:
    ans += 1
    f = False
    for n in range(N):
        if f:
            if G[n] == H[n]:
                break
            else:
                G[n] += 1
        else:
            if G[n] != H[n]:
                G[n] += 1
                f = True
            else:
                continue

print(ans)

Solution (Python):

import sys

input = sys.stdin.readline


sys.setrecursionlimit(2147483647)


def split(h):
    pieces = []
    tmp = []
    for i in range(len(h)):
        if h[i] == 0:
            pieces.append(tmp)
            tmp = []
        else:
            tmp.append(h[i])

    pieces.append(tmp)
    return pieces


def f(h):
    if len(h) == 0:
        return 0

    ith = 0
    while True:
        maxh = max(h)
        if maxh == 0:
            break
        for i in range(len(h)):
            h[i] += 1
        ith += 1

    pieces = split(h)

    m = 0
    for piece in pieces:
        m += f(piece)

    return ith + m


def main():
    N = int(input())
    h = list(map(int, input().split()))
    h = [-i for i in h]

    pieces = split(h)

    m = 0
    for piece in pieces:
        m += f(piece)

    print(m)


if __name__ == '__main__':
    main()

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

L = []
for i in range(1,n+1):
    L.append(li[i]-li[i-1])

L = [x for x in L if x>0]
print(sum(L))

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

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

Solution (Python):
from collections import deque
N = int(input())
h = list(map(int, input().split()))
count = 0
water=deque()
while sum(h)!=0:
    for i in range(N):
        if h[i] != 0:
            water.append(i)
        if water and h[i]==0:
            break
    for i in range(len(water)):
        k=water.popleft()
        h[k]-=1
    count += 1
    water.clear()

print(count)

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

cnt = 0
for i in range(1, 100+1):
  prev = False
  for x in h:
    if x >= i and not prev:
      cnt += 1
    prev = x >= i 

print(cnt)

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

ans = 0

for i,j in zip(h,h[1:]):
  ans += max(0,j-i)

print(ans)

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

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

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

print(ans)

Solution (Python):
n = int(input())
list1 = list(map(int,input().split()))
count = 0
def mizuyari(a,b):
	global count
	global list1
	for i in range(a,b):
		list1[i] -= 1
	count += 1

def search():
	global list1
	flag = 0
	for i in range(n):
		if list1[i] != 0:
			s = i
			break
	for j in range(s+1,len(list1)):
		if list1[j] == 0:
			mizuyari(s,j)
			flag = 1
			break
	if not flag:
		mizuyari(s,len(list1))

if __name__ == "__main__":
	while sum(list1) != 0:
		search()
	print(count)

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

res = 0
while True:
    if max(h) == 0:
        break
    for i in range(N):
        if h[i] > 0:
            l = i
            break
    for j in range(i+1, N+1):
        if h[j] == 0:
            r = j
            break
    
    x = min(h[l:r])
    for i in range(l, r):
        h[i] -= x
    res += x

print(res)

Solution (Python):

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

def find_res(h):
    count = 0

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

    while len(h) > 1:
        if 0 in h:
            idx = h.index(0)
            
            count +=  find_res(h[0:idx]) + find_res(h[idx+1:])
            return count
        else:
            min_h = min(h)
            h = [a - min_h for a in h]
            count += min_h

    return count

ans = find_res(h)
print(ans)

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

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

cnt = height[0]
for i in range(n-1):
    cnt += max(0, height[i+1]-height[i])

print(cnt)

Solution (Python):
import sys
sys.setrecursionlimit(20000)

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

counter = 0


def devzero(l,moji=0):
    return_L,tmp = [],[]
    for val in l:
        if val != moji:
            tmp.append(val)
            
        elif val == moji:
            return_L.append(tmp)
            tmp = []
    return_L.append(tmp)

    return return_L

def rec(L):
    global counter

    if L == []:
        return
    if 0 not in L:
        L = [i-1 for i in L]
        counter += 1
    L = devzero(L,moji=0)
    for val in L:
        rec(val)

if __name__=="__main__":
    rec(h_L)
    print(counter)

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

def splitList(ks):
  temp = []
  for k in ks:
    if k == 0:
      if temp:
        yield temp
        temp = []
    else:
      temp.append(k)
  if temp:
    yield temp

def f(ks):
  if not ks:
    return 0
  n = min(ks)
  ks_ = [k-n for k in ks]
  kss = list(splitList(ks_))
  return n + sum(map(f, kss))

print(f(ks))

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
cnt = 0
v = 0
for i in h:
    if i > v:
        cnt += i - v
    v = i
print(cnt)

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    H=[0]+list(map(int,input().split()))
    ans=0
    for i in range(n):
        ans+=max(0,H[i+1]-H[i])
    print(ans)
resolve()

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

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

ans = 0
while max(H) > 0:
    group = 0
    for i in range(1, N+1):
        if H[i-1] == 0 and H[i] > 0:
            group += 1
    ans += group
    for i in range(1, N+1):
        if H[i] > 0:
            H[i] -= 1

print(ans)

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


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

Solution (Python):

n = int(input())
hi = list(map(int, input().split()))
flag = False
cnt = 0
while sum(hi)>0:
    flag = False
    for hidx in range(len(hi)):
        if hi[hidx] > 0:
            if not flag:
                cnt += 1
                flag = True
            hi[hidx] -= 1
        else:
            flag = False
print(cnt)

Solution (Python):
n=int(input())
h=list(map(int,input().split()))
d=[]
a=[]
x=0
k=0
while k<len(h)-1:
  if h[k]==h[k+1]:
    h.pop(k)
    k-=1
  k+=1

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

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

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

tmp = 0
ans = 0

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

print(ans)

Solution (Python):
N = int(input())
h = list(map(int,input().split()))
cnt = 0
 
while sum(h) > 0:
    min_h = max(h)
    i = h.index(min_h)
    
    while i < len(h):
        if h[i] == min_h:
            h[i] -= 1
            i += 1
        else:
            break
    cnt += 1
 
print(cnt)

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

Solution (Python):
import os, sys, re, math

N = int(input())
h = list(map(lambda x: -1 * int(x),input().split(' ')))
cnt = 0

while sum(h) < 0:
	min_h = min(h)
	i = h.index(min_h)
	while i < len(h):
		if h[i] == min_h:
			h[i] += 1
			i += 1
		else:
			break
	cnt += 1

print(cnt)

Solution (Python):
def tree(lst):
	if len(lst) == 0:
		return 0
	mi = min(lst)
	lst = [a - mi for a in lst]
	sum = mi
	start = 0
	for i in range(len(lst)):
		if lst[i] == 0:
			sum += tree(lst[start : i])
			start = i + 1
		elif i == len(lst) - 1:
			sum += tree(lst[start:])
	return sum
    
n = int(input())
h = [int(a) for a in input().split()]
print (tree(h))

Solution (Python):
import os, sys, re, math

N = int(input())
H = [int(n) for n in input().split()]

def get_count(heights):
    count = 0
    while not 0 in heights:
        count += min(heights)
        heights = [n - min(heights) for n in heights]
    group = []
    groups = [group]
    for h in heights:
        if h != 0:
            group.append(h)
        else:
            group = []
            groups.append(group)
    for group in groups:
        if group:
            count += get_count(group)
    return count

print (get_count(H))

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

def doit(sub_hs):
    if len(sub_hs) == 0:
        return 0
    for i in range(len(sub_hs)):
        if sub_hs[i] == 0:
            a = 0
            if len(sub_hs[0:i]) > 0:
                min_h = min(sub_hs[0:i])
                a += min_h + doit([h - min_h for h in sub_hs[0:i]])
            if len(sub_hs) >= i:
                a += doit(sub_hs[i+1:])
            return a
    min_h = min(sub_hs)
    a = min_h + doit([h - min_h for h in sub_hs])
    return a
print(doit(hs))

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

ans = 0
while sum(fs):
    min_val = 99999999999
    min_index = 0
    for i in range(n):
        if fs[i] and fs[i] < min_val:
            min_index = i
            min_val = fs[i]
    ans += min_val
    for l in range(min_index-1, -1, -1):
        if not fs[l]:
            break
        fs[l] -= min_val
    for r in range(min_index, n):
        if not fs[r]:
            break
        fs[r] -= min_val
print(ans)

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

def doit(s, e, t):
    if s == e:
        return 0
    ret = 1
    i = s
    for j in range(s, e):
        if h[j] == t:
            ret += doit(i, j, t + 1)
            i = j + 1
    ret += doit(i, e, t + 1)
    return ret

print(doit(0, n, 0) - 1)

Solution (Python):
n = int(input())
H = list(map(int, input().split())) + [0]
c = 0
while True:
  flag = True
  for i in range(n):
    if H[i] > 0:
      flag = False
      H[i] -= 1
      if H[i+1] == 0:
        c += 1
  if flag:
    break
print(c)

Solution (Python):
test = False
if test:
    n = 100
    from random import randint
    h = [randint(0, 100) for _ in range(n)]
else:
    n = int(input())
    h = list(map(int, input().split()))

a = [0] * n
cost = 0
changed = True
while changed:
    changed = False
    left = 0
    while left < n and a[left] == h[left]:
        left += 1
    right = left
    while right < n and a[right] < h[right]:
        right += 1
    if left < n:
        cost += 1
        changed = True
        for i in range(left, right):
            a[i] += 1
print(cost)

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

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

ans = 0
while True:
    if sum(hl) == 0:
        break
    ans += 1
    flag = False
    for idx, h in enumerate(hl):
        if h > 0:
            hl[idx] -= 1
            flag = True
        elif flag:
            break
        else:
            continue

print(ans)

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

c=0
cur=0
for i in h:
    if(cur<i):
        c+=i-cur
    cur=i
print(c)

Solution (Python):

import sys










def main():
    n, *h = [int(x) for x in sys.stdin.read().split()]
    if n == 1:
        print(h[0])
        sys.exit()

    mountain = [0]
    valley = [0]
    flat = 0
    i = 0
    while True:
        if h[i] == h[i+1]:
            if i < n-2:
                i += 1
                continue
            else:
                print(h[i])
                sys.exit()
        elif h[i] < h[i+1]:
            break
        else:
            mountain.append(h[0])
            break
    i = -1
    while True:
        if h[i-1] == h[i]:
            i -= 1
            continue
        elif h[i-1] > h[i]:
            break
        else:
            mountain.append(h[-1])
            break

    for i in range(1, n-1):
        if flat == 0:
            if h[i-1] < h[i] > h[i+1]:
                mountain.append(h[i])
            elif h[i-1] > h[i] < h[i+1]:
                valley.append(h[i])
            elif h[i-1] < h[i] == h[i+1]:
                flat = 1
            elif h[i-1] > h[i] == h[i+1]:
                flat = -1
        else:
            if flat == 1:
                if h[i] > h[i+1]:
                    mountain.append(h[i])
                    flat = 0
                elif h[i] < h[i+1]:
                    flat = 0
                else:
                    continue
            elif flat == -1:
                if h[i] < h[i+1]:
                    valley.append(h[i])
                    flat = 0
                elif h[i] > h[i+1]:
                    flat = 0
                else:
                    continue

    
    ans = sum(mountain) - sum(valley)
    print(ans)
    

if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
h = list(map(int,input().split()))
ans = 0
for i in range(1,max(h)+1):
    jud = False
    for j in range(N):
        if h[j]>=i:
            if not jud:
                ans += 1
            jud = True
        else:
            jud = False
print(ans)

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

count = 0
left = 0
for flower in flowers:
  if flower > left:
    count += flower - left
  left = flower

print(count)

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

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

ans = 0
interval = 0

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

print(ans)

Solution (Python):
N = int(input())
array = list(map(int,input().split()))
ans = 0
while True:
    if max(array) == 0:
        break
    flg = False
    for i in range(N):
        if array[i] == 0:
            if flg:
                break
            continue
        array[i] -= 1
        flg = True
    ans += 1
print(ans)

Solution (Python):
N = int(input())
L = list(map(int,input().split()))
s = L[0]
ans = s
for i in range(0,N):
  if s <= L[i]:
    ans += L[i] - s
  s = L[i]

print(ans)

Solution (Python):
n=int(input())
ans=0 
l=[int(i) for i in input().split()]
while sum(l):
    c=0 
    f=0 
    for i in range(n):
        if l[i]!=0:
            l[i]-=1 
            c+=1 
        else: 
            if c:
                ans+=1 
                c=0 
    if c:
        ans+=1 
print(ans)

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

cnt = 0
while not all([x == 0 for x in hli]):
    sIdx = -1
    for i, h in enumerate(hli):
        if h != 0:
            sIdx = i
            break
    eIdx = sIdx + 1
    minNum = hli[sIdx]
    for i in range(sIdx+1, n):
        if hli[i] == 0:
            break
        eIdx = i + 1
        minNum = min(hli[i], minNum)
    for i in range(sIdx, eIdx):
        hli[i] -= minNum

    cnt += minNum
print(cnt)

Solution (Python):
N = int(input())
H = list(map(int,input().split()))
H.append(0)
ans = 0
maxH = max(H)
for h in range(maxH):
    state = 0
    for n in range(N+1):
        if H[n] > 0:
            H[n] -= 1
            state = 1
        elif H[n] == 0 and state == 1:
            state = 0
            ans += 1
        else:
            pass
print(ans)

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

ans = 0
cur = 0
for ai in a:
    if ai < cur:
        cur = ai
    else:
        ans += ai - cur
        cur = ai

print(ans)

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

l = []
for i in range(n):
    tmp = h[i]
    l.append(h[i])
    for j in range(n):
        h[j] -= tmp
        
ans = 0
for i in l:
    if i > 0:
        ans += i

print(ans)

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

total = 0
counter = 0
while H.count(0) != len(H) and counter < 1:
  left = 0
  right = 0
  for i in range(len(H)):
    if H[i] != 0:
      left = i
      break
  for i in range(i+1, len(H)):
    if H[i] == 0:
      right = i
      break
  
  min_val = min(H[left:right])
  total += min_val
  H[left:right] = map(lambda x: x - min_val, H[left:right])


print(total)

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    H=list(map(int,input().split()))
    cnt=0
    while(sum(H)):
        flag=False
        for i in range(n):
            if((not flag) and H[i]>0):
                flag=True
            if(flag and H[i]==0):
                break
            if(flag):
                H[i]-=1
        cnt+=1
    print(cnt)
resolve()

Solution (Python):
N = int(input())
H = list(map(int,input().split()))
flags = [i >=1 for i in H]
flags.append(False)

ans = 0
while any(flags):
    for i in range(N):
        if flags[i] and not flags[i+1]:
            ans += 1
        H[i] = H[i] - 1 if H[i] else 0
    flags = [e >= 1 for e in H]
    flags.append(False)
print(ans)

Solution (Python):
import numpy as np
n = int(input())
h = list(map(int, input().split()))
h = np.array(h)
ans = 0
def mizuyari(list):
    global ans
    
    if len(list) == 0:
        return
    if len(list) == 1:
        ans += min(list)
        return
    min_list = min(list)
    list = list - min_list
    ans += min_list
    zero_list = np.where(list == 0)[0]
    mizuyari(list[:zero_list[0]])
    mizuyari(list[zero_list[-1]+1:])
    for i in range(len(zero_list)-1):
        mizuyari(list[zero_list[i]+1:zero_list[i+1]])
mizuyari(h)
print(ans)

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

s = [0]*(N+2)
s[1] = h[0]
s[N+1] = -h[N-1]
for i in range(1, N):
    s[i+1] = h[i] - h[i-1]
ans = 0
for x in s:
    if x > 0:
        ans += x
print(ans)

Solution (Python):

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

ans = 0

while sum(h) != 0:
    s = 0
    for i in range(N):
        if h[i] == 0 and s == 1:
            ans += 1
            break
        elif h[i] != 0:
            h[i] -= 1
            s = 1
        if i == N - 1:
            ans += 1
print(ans)

Solution (Python):
from sys import stdin
from itertools import groupby

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
li = [0] + li
zantei = 0
point = 0
for i in range(len(li)):
    if li[i-1] <= li[i]:
        point += li[i]-li[i-1]

print(point)

Solution (Python):
n = int(input())
h = list(map(int,input().split()))
g = [[1] * (n+1) for i in range(max(h))]
for i in range(n):
  for j in range(h[i]):
    g[j][i] = 0
c = 0
for i in range(max(h)):
  for j in range(n):
    if g[i][j] == 0 and g[i][j+1] == 1:
      c += 1
print(c)

Solution (Python):
N=int(input())
h=list(map(int,input().split()))
p=h[0]
for i in range(N-1):
  if p<h[i+1]:
    p=h[i+1]
  else:
    p=p
 
q=1
r=0
if p==0:
    print(0)
else:
    while q<=p:
        if h[0]>=q:
            r=r+1
        else:
            r=r
        for i in range(N-1):
              if h[i]<q and h[i+1]>=q:
                r=r+1
              else:
                r=r
        q=q+1
    print(r)

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


def minus(x,y): 
    if x > 0:
        return(x - y) 
    else:
        return(x)

def non_zero_min(hs):
    hmin = 1000000 
    for h in hs: 
        if h > 0: 
            if h < hmin: 
                hmin = h 
    return(hmin)


def zero_div_counter(hs):
    length = 0
    n_div = 0
    for i in range(len(hs)):
        h = hs[i]
        if h > 0:
            length += 1
        elif h == 0:
            if length > 0:
                n_div += 1
                length = 0
            else:
                length = 0  
        if i == len(hs)-1:
            if length > 0:
                n_div += 1
    return(n_div)

count = 0

orig_max = max(hs)

for i in range(N):
    
    n_div = zero_div_counter(hs)

    nz_min = non_zero_min(hs)
    
    
    count += n_div * nz_min

    
    
    hs = [minus(x,nz_min) for x in hs] 


print(count)

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

flowers = [0 for i in range(n)]
count = 0

def pour(li):
    li.insert(0, 0)
    pour_count = 0
    for i in range(len(li)-1):
        if li[i] == 0 and li[i+1] == 1:
            pour_count += 1
    return pour_count


while flowers != num_list:
    pour_list = [0] * n
    for i in range(n):
        if flowers[i] != num_list[i]:
            pour_list[i] = 1
            flowers[i] += 1
    count += pour(pour_list)

print(count)

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

maxh=max(A)
ans=0
for i in range(1,maxh+1):
  
  block=0
  cur=False
  if A[0]>=i:
    block+=1
    cur=True
  for j in range(1,len(A)):
    if A[j]>=i:
      if not cur:
        block+=1
        cur=True
    else:
      cur=False
  ans+=block

print(ans)

Solution (Python):
N = int(input())
H = [int(x) for x in input().split()] + [0]
ans = 0
i = 0
while(1):
    if (i == N): break
    if (H[i] == 0): 
        i += 1
        continue
    j = i + 1
    m = H[i]
    while(1):
        if (H[j] == 0): break
        m = min(m, H[j])
        j += 1
    ans += m
    for k in range(i, j):
        H[k] -= m
print(ans)

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

def rec(h) :
    m = min(h)
    for i in range(len(h)) :
        h[i] -= m
    
    ret = m
    pre = 0
    for i in range(len(h)) :
        if h[i] == 0 :
            if i - pre > 0 :
                ret += rec(h[pre:i])
            pre = i + 1
        elif i == len(h) - 1 :
            ret += rec(h[pre:])
    return ret
    
print(rec(h))

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

count = 0

while sum(H) != 0:
    temp = 0
    H_max = max(H)
    H_no_max = [h for h in H if h != H_max]
    if len(H_no_max) == 0:
        count += H_max
        break
    H_second_max = max(H_no_max)
    dif = H_max - H_second_max
    
    temp += H.count(H_max)
    for n in range(N-1):
        if H[n] == H[n+1] == H_max:
            temp -= 1
    for n in range(N):
        if H[n] == H_max:
            H[n] = H[n] - dif
    count += dif * temp

print(count)

Solution (Python):

n = int(input())

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

if n == 1:
	print(h[0])
else:
	cnt = 0
	while 1:
		while h[0] == 0:
			del h[0]
			if len(h) == 1:
				print(cnt+h[0])
				exit(0)
		while h[len(h)-1] == 0:
			del h[len(h)-1]
			if len(h) == 1:
				print(cnt+h[0])
				exit(0)
		num = 1
		i = 0
		while 1:
			while h[i] != 0:
				i += 1
				if i == len(h):
					break
			if i == len(h):
				break
			num += 1
			while h[i] == 0:
				i += 1
		cnt += num
		for i in range(len(h)):
			if h[i] != 0:
				h[i] -= 1

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

intended_height = [int(x) for x in input().split(' ')]

times = 0

stop = False

while True:
    times = times + 1
    watered = False
    
    for i in range(0, len(intended_height)):
        if intended_height[i] != 0:
            intended_height[i] = intended_height[i] - 1
            
            watered = True
        else:
            if watered:
                break
    
    if not watered:
        times -= 1
        break

print(times)

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

def calc(i,j):
    SUM=0
    T=H[i:j]
    TH=H
    if(len(T)==0):
        return 0
    
    tmp=min(T)
    for a in range(i,j):
        H[a]-=tmp
    SUM+=tmp
    
    List=[n for n, v in enumerate(T) if v == min(T)]

    if(len(T)>1):
        B=0
        for b in List:
            SUM+=calc(i+B,i+b)
            B=b+1
        SUM+=calc(i+B,j)

    return SUM


if __name__ == "__main__":

    print(calc(0,N))
    
    exit()

Solution (Python):
n = int(input())
h = [int(i) for i in input().split()]
ans = 0
while sum(h) > 0:
    L = 0
    if 0 not in h:
        ans += 1
        for i in range(n):
            h[i] -= 1
    else:
        for i in range(n):
            if h[i] == 0 and L != i:
                for j in range(L,i):
                    h[j] -= 1
                ans += 1
                L = i + 1
            elif h[L] == 0:
                L += 1
            if i == n-1 and h[i] != 0:
                for j in range(L,n):
                    h[j] -= 1
                ans += 1
print(ans)

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

if min(h) > 0:
    tmp = min(h)
    h = list(map(lambda x: x - tmp, h))
    count += tmp

while True:
    star = -1
    end = -1
    frag = False
    min_num = -1
    if min(h) == max(h):
        break

    for i in range(N):
        if h[i] > 0 and not frag:
            star = i
            frag = True
        if h[i] == 0 and frag:
            end = i
            break
    if end == -1:
        end = len(h)

    min_num = min(h[star:end])
    count += min_num
    for j in range(min_num):
        for i in range(star, end):
            h[i] -= 1

print(count)

Solution (Python):
N = int(input())
L = list(map(int,input().split()))
s = L[0]
ans = s
for i in range(0,N):
  if s <= L[i]:
    ans += L[i] - s
  s = L[i]

print(ans)

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

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

flowers = [0] * N

start = 0
end = 0

con = 0

while flowers != H:
	for i in range(0,N):
		if H[i] > flowers[i]:
			start = i
			for j in range(i,N):
				if H[j] == flowers[j]:
					end = j
					break
				else:
					end = N
			break


	for k in range(start,end):
		flowers[k] += 1
	con += 1
	start = 0
	end = 0
	
	


print(con)

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

Solution (Python):
n = int(input())
list1 = list(map(int,input().split()))
cout = 0 
now_water = 0 
i = 0
def func(flower):
	global cout
	global i
	if flower == n-1: 
		if list1[flower] <= now_water:
			cout += 1
			i = flower + 1
			return
		else:
			cout += 1
			i = flower + 1
			return

	elif list1[flower] <= now_water: 
		cout += 1 
		i = flower + 1
		return
	else:
		func(flower + 1)

while now_water <= max(list1): 
	i = 0
	while i < n: 
		if list1[i] > now_water:
			func(i)
		else:
			i+=1
	now_water += 1





print(cout)

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

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

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

print(ans)

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

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

m=max(h)
c=0

for i in range(1,m+1):
  s=-1
  for j in range(n):
    if s==-1 and h[j]>=i:
      s=j
    if s!=-1 and h[j]<i:
      s  =-1
      c += 1
  else:
    if s!=-1:
      c += 1

print(c)

Solution (Python):
def merge(hight):
    if len(hight) == 0:
        return 0
    if len(hight) == 1:
        return hight[0]
    m = min(hight)
    m_idx = hight.index(m)
    hight = [h - m for h in hight]
    left_hight = hight[:m_idx]
    right_hight = hight[m_idx + 1:]
    return  merge(left_hight) + merge(right_hight) + m

if __name__ == '__main__':
    N = int(input())
    h = list(map(int, input().split()))
    print(merge(h))

Solution (Python):
N=int(input())
H=list(map(int,input().split()))
ans=0
M=0
for i in range(N):
  if(M<H[i]):
    M=H[i]
for i in range(M):
  X=0
  for j in range (N):
    H[j]=min(H[j],M-i)
    if(j):
      if(H[j]!=H[j-1] and H[j-1]==M-i):
        X+=1
    if(j==N-1):
      if(H[j]==M-i):
        X+=1
  ans+=X
print(ans)

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

for i in range (0,N-1):
  if h[i] > h[i+1]:
    x = x + (h[i] - h[i+1])
x = x + (h[N-1] - min(h))
print(x)

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

count = 0
flag = True
while flag:
    for i in range(N-1):
        if h[i] != 0 and h[i+1] == 0:
            count += 1
        if h[i] > 0:
            h[i] -= 1
    if h[N-1] > 0:
        h[N-1] -= 1
        count += 1
        
    count_0 = 0
    for i in range(N):
        if h[i] == 0:
            count_0 += 1
    if count_0 == N:
        flag = False

print(count)

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