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

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

if N==1:
    print(h[0])
    exit()

mi=min(h)
p=0
h0=h[0]
c=h0-mi
ans=mi+h0
for i in range(1,N):
    if h0<h[i]:
        c+=h[i]-h0
    elif h0>h[i]:
        c=h0-min(h[p:i])
        ans+=c
        p = i
        c=h[i]-mi
    h0=h[i]

ans+=c-min(h[p:])
print(ans)

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

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()))
sum=0
flag=False
for i in range(max(h)+1):
    for j in range(n):
        if(h[j]>0):
            flag=True
            h[j]-=1
        elif(flag):
            sum+=1
            flag=False
    if(flag):
        sum+=1
    flag=False
print(sum)

Solution (Python):
def main():
    N = int(input())
    h = [int(i) for i in input().split()]
    ans = 0
    mul = h[1:N-1].count(0) + 1
    for i in range(max(h)):
        ans += 1 * mul
        z_cnt = 0
        flag = False
        for j in range(N):
            h[j] = (h[j]-1 if h[j] != 0 else h[j]) 
            if h[j] != 0:
                flag = True
            elif j == N-1 and h[j] == 0 and not flag:
                z_cnt -= 1
            elif j != 0 and j != N-1 and h[j] == 0 and flag:
                z_cnt += 1
                flag = False
        mul = z_cnt + 1


    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np
N = int(input())
H = np.array([int(v) for v in input().split()])
hm = np.max(H)
cnt = 0
for h in range(1, hm + 1):
    hh = H >= h
    f = False
    for n in range(N):
        
        if not f and hh[n]:
            cnt += 1
            f = True
        elif not hh[n]:
            f = False
print(cnt)

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

cur = 0
total = 0
while h != [0] * N:
    for i in range(cur, N):
        if cur == i and h[i] == 0:
            cur += 1
        elif h[i] == 0:
            if cur == i - 1:
                total += h[i - 1]
                h[i - 1] = 0
            else:
                min_h = min(h[cur:i])
                total += min_h
                for j in range(cur, i):
                    h[j] -= min_h
        elif i == N - 1:
            min_h = min(h[cur:N])
            total += min_h
            for j in range(cur, N):
                h[j] -= min_h
print(total)

Solution (Python):





from sys import stdin,setrecursionlimit


setrecursionlimit(10**6)
input=stdin.readline

n=int(input().rstrip())
h=[int(i) for i in input().split()]
ans=0
while 1:
    l=0
    for i in range(n):
        if h[i]>0:
            l=i
            break
    else:
        print(ans)
        exit()
    
    while h[l]!=0:
        
        h[l]-=1
        if l!=n-1:
            l+=1
        else:
            break
        
    ans+=1

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

res = 0
left = 0
while left < n:
    if hs[left] == 0:
        left += 1
        continue
    right = left + 1
    while right <= n:
        if right < n and hs[right] > 0:
            right += 1
        else:
            a = min(hs[left:right])
            res += a
            for i in range(left, right):
                hs[i] -= a
            break
print(res)

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())
hs = list(map(int, input().split()))
def sub(l, r, b):
  if l == r:
    return 0
  i = min(range(l, r), key=lambda i: hs[i])
  h = hs[i]
  return h-b+sub(l, i, h)+sub(i+1, r, h)
r = sub(0, N, 0)
print(r)

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

ans=0
for i in range(len(h)-1):
    while h[i]!=0:
        
        for j in range(i+1,len(h)):
            if h[j]<h[i]:
                break
            else:
                h[j]-=1
        h[i]-=1
        ans+=1
ans += h[-1]
print(ans)

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

cnt = 0
peak = 0
prev = 0
down = False
for h in H:
    if down and h > prev:
        cnt += peak - prev
        peak = prev
        down = False
    elif h < prev:
        down = True
    peak = max(peak, h)
    prev = h
else:
    cnt += peak

print(cnt)

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

UP = True
pre = 0
bottom = 0
count = 0

for i in range(n):
    if UP:
        if H[i] >= pre:
            pre = H[i]
            continue
        else:
            count += pre - bottom
            pre = H[i]
            UP = False
    else:
        if H[i] <= pre:
            pre = H[i]
            continue
        else:
            bottom = pre
            pre = H[i]
            UP = True

if UP:
    count += pre - bottom

print(count)

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

Solution (Python):

N = int(input())
H = list(map(int, input().split()))
ans = 0
while sum(H) != 0:
    while True:
        if H[0] == 0:
            H.pop(0)
        else:
            break
    if 0 in H:
        ind = H.index(0)
        for i in range(0, ind):
            H[i] -= 1
    else:
        H = list(map(lambda x: x - 1, H))
    ans += 1
print(ans)

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

def cut(list_i):
  list_r = []
  tmp_list = []
  for i in list_i:
    if i == 0:
      if tmp_list != []:
        list_r.append(tmp_list)
      tmp_list = []
    else:
      tmp_list.append(i)
  else:
    if tmp_list != []:
      list_r.append(tmp_list)
  return list_r

ans = 0
def search(list_i):
  
  global ans
  ans += min(list_i)
  list_i = list(map(lambda x: x - min(list_i), list_i))
  for list_r in cut(list_i):
    search(list_r)
    
search(h)
print(ans)

Solution (Python):
import sys

N = int(input())
h = list(map(int, input().split()))
cnt = 0
start = 0
end = 0
if sum(h) == 0:
    print(0)
    sys.exit()

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

    end = N
    for i in range(start + 1, N):
        if h[i] == 0:
            end = i
            break

    for i in range(start, end):
        if h[i] != 0:
            h[i] = h[i] - 1

    cnt += 1
    start = 0
    end = 0
    if sum(h) == 0:
        break

print(cnt)

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

t = [0] * n
ans = 0

for i in range(n):
    while t[i] < h[i]:
        for j in range(i, n):
            if t[j] < h[j]:
                t[j] += 1
            else:
                break

        ans += 1

print(ans)

Solution (Python):
count = 0

def mizu(h):
    global count
    
    if len(h) is 0:
        return
    if len(h) is 1:
        count += h[0]
        return
    
    m = min(h)
    count += m
    
    h = [i - m for i in h]
    while 0 in h:
        
        mizu(h[:h.index(0)])
        h = h[h.index(0)+1:]
    mizu(h)

if __name__ == "__main__":
    N = int(input())
    h = list(map(int, input().split()))
    mizu(h)
    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]>0:
        ans += h[i]-h[i-1]
print(ans)

Solution (Python):
N = int(input())
H = list(map(int, input().split()))
ans = 0
H.append(0)
for i in range(max(H)):
    cnt = 0
    for k in range(N):
        if H[k] != 0 and H[k+1] == 0:
            cnt += 1
    ans += cnt
    H = list(map(lambda x:(x-1, 0)[x == 0], H))
print(ans)

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

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


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()))
ZTH = [0 for i in range(N+1)]

s = 0
H.append(0)

while H != ZTH:
  i = 0
  while i <= N - 1:
    if H[i] == 0:
      i += 1
    else:
      s += 1
      j = i
      while H[j] != 0 and j < N:
        j += 1
      i = j
  if i == N:
    for k in range(N):
      if H[k] != 0:
        H[k] -= 1
    i = 0
      
print(s)

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
r = 0
if len(h) == 1:
    print(h[0])
    exit()
while len(list(set(h))) != 1:
    t = 0
    for k in h:
        if k > 0:
            t = 1
        else:
            if t == 1:
                r += 1
            t = -1
    if t == -1:
        r -= 1
    for i, j in enumerate(h):
        if j != 0:
            h[i] -= 1
    r += 1
print(r)

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

count=0

while True:
    index = h.index(max(h))
    if max(h)==0:
        print(count)
        break

    lindex = 0
    for i in range(index):
        if h[index-(i+1)]==0:
            lindex = index-(i+1)+1
            break

    rindex = n
    for i in range(n-index-1):
        if h[index+(i+1)]==0:
            rindex = index+(i+1)-1
            break

    for i in range(len(h)):
        if i>=lindex and i<=rindex:
            h[i]-=1
    
    
    
    count+=1

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

ans = 0
flag = 0
tmp = H[0]
for i in range(N-1):
    if flag==0:
        if H[i] <= H[i+1]:
            tmp = H[i+1]
        else:
            ans += tmp
            tmp = H[i+1]
            flag = 1
    else:
        if H[i] >= H[i+1]:
            tmp = H[i+1]
        else:
            ans -= tmp
            tmp = H[i+1]
            flag = 0
if flag == 0:
    ans += tmp
print(ans)

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

ans = 0
before_num = 0
for n in range(N):
  dif = h[n] - before_num
  if dif > 0:
    ans += dif
  
  before_num = h[n]

print(ans)

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
ans = h[0]
for i in range(1, n):
  if h[i]-h[i-1] > 0:
    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(1,n):
  cp = 0
  if H[i] - H[i-1] >= 0:
    ans += H[i] - H[i-1]
  else:
    continue

print(ans)

Solution (Python):
n=int(input())
h=[0]+[int(i) for i in input().split()]+[0]
c=0
while sum(h)>0:
    z=[i for i,x in enumerate(h) if x==0]
    for i in range(len(z)-1):
        l=z[i]
        r=z[i+1]
        if r-l>1:
            m=min(h[l+1:r])
            c+=m
            for j in range(l+1,r):
                h[j]-=m
print(c)

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


def WaterTime(list):
    times=0
    if list[0]!=0:
        times+=1
    for i in range(1,len(list)):
        if list[i]!=0 and list[i-1]==0:
            times+=1
    return times
ans=0
tmp=0
j=0
while max(h) != 0:
    tmp = max(h)
    for i in h:
        if i!=0 and i<tmp:
            tmp=i
    ans += tmp*WaterTime(h)
    for j in range(n):
        if h[j]!=0:
            h[j] = h[j]-tmp
print(ans)

Solution (Python):
import math
import copy
import sys
import fractions
import numpy as np
from functools import reduce



def getInputInt():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList



n, = map(int, input().split())
data = getInputListInt()

maximum = max(data)

for i in range(n):
    data[i] = maximum - data[i]

flgWhileContinue = True
cnt = 0

while flgWhileContinue:
    flgForBreak = False
    flgWhileContinue = False
    for i in range(n):
        if data[i] == maximum and flgForBreak:
            break

        if data[i] != maximum:
            flgForBreak = True
            flgWhileContinue = True
            data[i] += 1

    if flgWhileContinue:
        cnt += 1

print(cnt)

Solution (Python):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


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


cur = [0] * N

count = 0

left = 0
while left < N:
    while cur[left] < H[left]:
        right = left
        for i in range(left+1, N):
            if cur[i] == H[i]:
                break
            right = i


        for i in range(left, right+1):
            cur[i] += 1

        count += 1


    
    left += 1

print(count)

Solution (Python):
N = int(input())
h = list(map(int, input().split()))
ans = 0
count = 0
h.append(0)
f = set(h)
for i in range(max(h)):
    if i in f:
        count = 0
        for k in range(N):
            if h[k] != 0 and h[k + 1] == 0:
                count += 1
    ans += count
    h = list(map(lambda x: (x - 1, 0)[x == 0], h))
print(ans)

Solution (Python):
N = int(input())
h = list(map(int, input().split()))
ans = 0
for i in range(max(h)):
    h.append(0)
    count = 0
    for k in range(N):
        if h[k] != 0 and h[k + 1] == 0:
            count += 1
    ans += count
    h = list(map(lambda x: (x - 1, 0)[x == 0], h))
print(ans)

Solution (Python):
from collections import deque
N=int(input())
H=list(map(int,input().split()))
h=deque(H)
h.appendleft(0)
s=0
i=1
while i<=N-1:
    while h[i]<=h[i+1]:
        i+=1
        if i==N:
            s+=h[N]
            break
    if i==N:
            break
    s+=h[i]
    while h[i]>=h[i+1]:
        i+=1
        if i==N:
            break
    if i==N:
            break
    s-=h[i]
if N==1:
    s+=h[1]
print(s)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

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()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

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

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

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

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

    print(ans)


main()

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
result = 0
while True:
  start = n
  for i in range(n):
    if h[i] != 0:
      start = i
      break
  if start == n:
    break
  end = n - 1
  count = 101
  for i in range(start, n):
    if h[i] == 0:
      end = i - 1
      break
    if h[i] < count:
      count = h[i]
  for i in range(start, end + 1):
    h[i] -= count
  result += count
print(result)

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
result = 0
while True:
  start = n
  for i in range(n):
    if h[i] != 0:
      start = i
      break
  if start == n:
    break
  end = n - 1
  for i in range(start, n):
    if h[i] == 0:
      end = i - 1
      break
    h[i] -= 1
  result += 1
print(result)

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

def main():

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

    ans = 0
    while True:
        m = max(h)
        if m == 0:
            print(ans)
            return
        else:
            b = False
            for i,x in enumerate(h):
                if x == m:
                    h[i] -= 1
                    b = True
                elif b:
                    break
            ans += 1

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
h.insert(0, 0)
h.append(0)
cnt = 0
while True:
    s = -1
    e = -1
    m_n = 10 ** 10
    for i in range(1, n + 2):
        if h[i] != 0 and h[i-1] == 0:
            s = i
            m_n = min(m_n, h[i])
            for j in range(i + 1, n + 2):
                if h[j] == 0 and h[j - 1] != 0:
                    e = j - 1
                    break
                else:
                    m_n = min(m_n, h[j])
    if s == -1 and e == -1:
        print(cnt)
        exit()
    else:
        cnt += m_n
        for i in range(s, e + 1):
            h[i] -= m_n

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

flag = False
cnt = 0

for i in range(max(hi)):
    flag = False
    for h in hi:
        if h > i and not flag:
            cnt += 1
            flag = True
        elif h > i and flag:
            pass
        else:
            flag = False

print(cnt)

Solution (Python):
n, *h = map(int, open(0).read().split())
h += 0,
a = b = 0
while sum(h):
    if h[b] > 0: a += 1
    else: b = (b+1)%(n+1); continue
    while h[b] >0:
        h[b] -= 1
        b += 1
print(a)

Solution (Python):
N=int(input())
lst = [int(s) for s in input().split()]
def suc(ls):
  val_ls=ls
  i=0
  while(i<N and val_ls[i]==0):
    i+=1
  if i==N:
    return []
  else:
    while(i<N and val_ls[i]!=0):
      val_ls[i]-=1
      i+=1
    return val_ls
ans=0
while(lst!=[]):
  ans+=1
  lst=suc(lst)
print(ans-1)

Solution (Python):


import copy

n = int(input().split()[0])
h_list = list(map(int, input().split()))

now_h_list = [0] * n
nokori_h_list = copy.copy(h_list)


count = 0

for i in range(n):

    while nokori_h_list[i] > 0:
        zero_index = nokori_h_list[i:].index(0) if 0 in nokori_h_list[i:] else - 1
        zero_index += i
        if zero_index < i:
            h_add = min(nokori_h_list[i:])
            count += h_add
            nokori_h_list[i:] = map(lambda x: x - h_add, nokori_h_list[i:])
        else:
            h_add = min(nokori_h_list[i:zero_index])
            count += h_add
            nokori_h_list[i:zero_index] = map(lambda x: x - h_add, nokori_h_list[i:zero_index])
        

print(count)

Solution (Python):
N = int(input())
h_list = [int(number) for number in input().split(' ')]

counter = 0

while True:
	flag=False
	keep=False
  
	for i, h in enumerate(h_list):
		if h>=1:
			keep=True
			h_list[i] -= 1
			flag=True
			if (i+1)==N:
				counter += 1
		elif h==0:
			if flag:
				counter += 1
				flag=False
		else:
			raise ValueError()
      
	if not keep: break
    
print(counter)

Solution (Python):
import sys
import math



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

ans = 0

def w(_l):
    if len(_l) == 0:
       return
    zero = [i for i, x in enumerate(_l) if x == 0]
    if len(zero) == 0:
        global ans
        ans += 1
        w(list(map(lambda x: x - 1,_l)))
    elif len(zero) == len(_l):
        return
    else:
        w(_l[:zero[0]])
        w(_l[zero[0] + 1:])

w(h)
print(ans)

Solution (Python):

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

count = 0
L = -1
R = N
M = max(H)
for i in range(M):
    wflag = 0
    for j in range(N):
        if H[j] >= 1:
            wflag = 1
            H[j]-=1
        else:
            if wflag == 1:
                count+=1
                wflag = 0
            else:
                pass
    if wflag == 1:
        count+=1
                
print(count)

Solution (Python):
"""
4
1 2 2 1

2


5
3 1 2 3 1

5


8
4 23 75 0 23 96 50 100

221
"""

_ = int(input())
first = list(map(int, input().split()))
count = 0


def water(base_list):
    global count
    count += 1
    separated = []
    each = []
    for i in base_list:
        hoge = i - 1
        if hoge == 0:
            separated.append(each)
            each = []
        else:
            each.append(hoge)
    if each:
        separated.append(each)

    new_separated = []
    for i in separated:
        if i:
            new_separated.append(i)

    if new_separated:
        for i in new_separated:
            water(i)
    else:
        return


def plus_one(i):
    return i + 1


first = list(map(plus_one, first))


water(first)

print(count - 1)

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

ans = 0
watering = 0

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

print(ans)

Solution (Python):
import sys
n=int(input())
h=list(map(int,input().split()))
if len(set(h))==1:
  print(h[0])
  sys.exit()
totl=0
for i in range(1,max(h)+1):
  cnt=0
  if i<=h[0]:
    cnt+=1
  for j in range(n-1):
    if h[j]<i:
      if i<=h[j+1]:
        cnt+=1
  totl+=cnt
print(totl)

Solution (Python):


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







water = flower[0]

for i in range(1, n):
    if flower[i] > flower[i-1]:
        water += flower[i] - flower[i-1]

print(water)

Solution (Python):


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

ans = 0

min_ = min(goal)
max_ = max(goal)


ans += min_
goal = list(map(lambda x: x - min_, goal))


r = max_ - min_

for i in range(r):
    
    f = 0

    for j in goal:
        
        if j > i:
            f = 1
        
        else:
            if f == 1:
                ans += 1 
            f = 0
            continue
    
    else:
        if f == 1:
            ans += 1 

print(ans)

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

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

Solution (Python):
import numpy as np
n=int(input())+2
h=np.array([0]+list(map(int, input().split()))+[0])

ans=0
while sum(h)>0:
    l=0
    for r in range(n-1):
        if h[r]==0 and h[r+1]!=0:
            l=r
        if h[r]!=0 and h[r+1]==0:
            water=min(h[l+1 : r+1])
            ans+=water
            h[l+1 : r+1]-=water
    
print(ans)

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

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

    count = 0
    while max(H) > 0:
        count += 1
        maxH = max(H)
        is_found = False
        start, end = 0, N
        for i in range(N):
            if not is_found and H[i] == maxH:
                is_found = True
                start = i
            elif is_found and H[i] != maxH:
                end = i
                break
        for i in range(start, end):
            H[i] -= 1

    return count

if __name__ == '__main__':
    print(main())

Solution (Python):

import sys
import math
from collections import defaultdict


sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]


mod = 10**9 + 7


def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))



N = I()
h = III()

val = 0
while 1:
    for i in range(N):
        if h[i]!=0:
            if i==0:
                val += 1
            else:
                if h[i-1]==0:
                    val += 1
                    
    flag = True
    for i in range(N):
        if h[i]!=0:
            h[i] -= 1
            flag = False
    
    if flag:
        break

print(val)

Solution (Python):
N = int(input())
height = [int(i) for i in input().split()] + [0]
k = 0
while True :
    if sum(height) == 0 :
        break 
    for i in range(N):
        if height[i] > 0 :
            lv = i 
            break 

    for i in range(lv,N+1):
        if height[i] == 0 :
            uv = i 
            break 
    for i in range(lv,uv):
        height[i] -= 1
    k += 1
print(k)

Solution (Python):

import sys


def solve(N: int, h: "List[int]"):
    ans = 0
    
    for i in range(1,max(h)+1):
        t = [1 if h[k] >= i else 0 for k in range(N)]
        
        
        
        for j in range(1, len(t)):
            if(t[j-1] == 1 and t[j] == 0):
                ans += 1

        if(t[-1] == 1):
            ans += 1
            
    print(ans)


    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    h = [ int(next(tokens)) for _ in range(N) ]  
    solve(N, h)

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
a.append(-1)
ans = 0

while max(a):
    max_a = max(a)
    i = 0
    while i < n and i >= 0:
        if a[i] == max_a:
            a[i] -= 1
            while a[i+1] == max_a:
                i += 1
                a[i] -= 1
            ans += 1
        i += 1
print(ans)

Solution (Python):
N = int(input())
H = list(map(int, input().split()))
count = 0
H.append(0)
for lv in range(1, 101):
    flag = False
    for h in H:
        if flag and h < lv:
            count += 1
            flag = False
        elif not flag and h >= lv:
            flag = True
print(count)

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

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

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())
l = list(map(int, input().split()))
l = [0] + l + [0]

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

Solution (Python):

n = int(input())
flower_list = [ int(v) for v in input().split() ]

def water():
    grown = 0
    l = 0
    r = n
    for i, v in enumerate(flower_list):
        if grown == 0:
            if v > 0:
                grown = 1
                l = i
        elif grown == 1:
            if v == 0:
                grown = 2
                r = i
    if grown != 0:
        for i in range(l,r):
            flower_list[i] -= 1

    flg = 0
    if grown == 0:
        flg = 1
    return flg

ans = 0
stop = 0
while stop == 0:
    stop = water()
    if stop == 0:
        ans += 1

print(ans)

Solution (Python):
import sys


args = None
INF = float("inf")
MOD = int(1e9 + 7)
def int1(n):
    return int(n) - 1
def parse(*params):
    if len(params) == 1:
        return params[0](next(args))
    return tuple(p(v) for p, v in zip(params, next(args).split()))
def debug(*v):
    if __debug__:
        print(*v, file=sys.stderr)


def main():
    N = parse(int)
    H = [0] + list(map(int, next(args).split()))

    c = 0
    debug(H)
    for h in range(100):
        for n in range(1, N + 1):
            if H[n - 1] - h <= 0 and 0 < H[n] - h:
                c += 1
    print(c)

if __name__ == '__main__':
    args = iter(sys.stdin.read().split("\n"))
    main()

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

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

def watering(h_list):
  if h_list == []:
    return 0
  
  tmp = min(h_list)
  water = tmp
  h_list = list(map(lambda x:x-tmp, h_list))
  ind = h_list.index(0)
  water += watering(h_list[:ind])
  water += watering(h_list[(ind+1):])
  
  return water

print(watering(hs))

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
k=sum(a)
cnt=0
cn=0
for i in range(100):
	for i in range(n):
		if a[i]!=0:
			a[i]-=1
			cn+=1
		elif cn>0:
			cn=0
			cnt+=1
	if cn>0:
		cnt+=1
	cn=0
	if sum(a)==0:
		break
print(cnt)

Solution (Python):

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

import numpy as np

h.append(0)
h_np = np.array(h)
water_counter = 0
while True:
    h_np -= 1
    water = h_np >= 0
    if True not in water:
        break
    change_counter = 0
    for i in range(1, n+1):
        if water[i-1] != water[i]:
            change_counter += 1
    water_counter += (change_counter+water[0]) // 2

print(water_counter)

Solution (Python):
N=int(input())
ff=list(map(int,input().split()))
ss=[0]*(N+1)
ans=ss[0]=ff[0]
nss=1
for f in ff[1:]:
  if f==ss[nss-1]: continue
  if f>ss[nss-1]: 
    ans+=(f-ss[nss-1])
    ss[nss]=f; nss+=1
    continue
  t=nss;
  while t>0 and f<ss[t-1]: t-=1
  ss[t]=f; nss=t+1
print(ans)

Solution (Python):

import bisect
import collections
import itertools


def getint(): return int(input())
def getints(): return list(map(int, input().split()))
def getint2d(rows): return [getints() for _ in range(rows)]
def getgrid(rows): return [input() for _ in range(rows)]
def array1d(n, value): return [value for _ in range(n)]
def array2d(n, m, value): return [array1d(m, value) for _ in range(n)]

n=getint()
hs=getints()

def solve(hs:list):
    if not hs or not max(hs):
        return 0
    add = min(hs)
    for i in range(len(hs)):
        hs[i] -= add
    res = add
    now = []
    for h in hs:
        if not h:
            res += solve(now)
            now = []
            continue
        now.append(h)
    res += solve(now)
    return res

print(solve(hs))

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

h.append(0)
i = 0
answer = 0
while i < n:
    if h[i] == 0:
        i += 1
    else:
        j = i
        while h[j] != 0:
            j += 1
        min_h = min(h[i:j])
        for k in range(i,j):
            h[k] -= min_h
        answer += min_h

print(answer)