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()))
answer = 0

while h != [0]*n:
  prev = -1
  subcount = 0 
  for index in range(n):
    if prev != -1 and prev != 0 and h[index] == 0:
      subcount += 1
    prev = h[index]
    h[index] = max(h[index]-1, 0)
      
  if prev != 0:
    subcount+=1
  
  answer+=subcount

print(answer)

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

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

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

ans = 0
p = 0
started = True 

while any(h):

    cur = h[p] 
    
    if cur > 0:
        h[p] -= 1
        if started:
            started = False
            ans += 1
    else:
        started = True
         
    p += 1
    
    if p >= N:
        p = 0 
        started = True

print(ans)

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

h = list(map(int,input().split()))
c=0
while max(h)>0:   
    
    if h[0] > 0:
      h.insert(0,0)
    if h[-1] > 0:
      h.append(0)
    p=0
    for i in range(len(h)-1):
      if h[i]>=1 and h[i+1]<=0:
        p+=1
    
    c+=max(1,p)
    
    h = [n-1 for n in h]
    
    
print(c)

Solution (Python):
N = int(input())
h = list(map(int, input().split()))
h.append(0)
min_n = 100
ans = 0
cnt = 0
i = 0
while i < N + 1:
    if h[i] != 0:
        cnt += 1
        min_n = min(min_n, h[i])
    elif h[i] == 0 and cnt != 0:
        ans += min_n
        for j in range(i+1):
            h[j] = max(h[j]-min_n, 0)
        min_n = 100
        cnt = 0
        i = -1
    i += 1
print(ans)

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

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

ans = 0
prev = 0
for h_i in h:
    ans += max(h_i - prev, 0)
    prev = h_i
print(ans)

Solution (Python):
n, *l = map(int, open(0).read().split())

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

print(count)

Solution (Python):
import numpy as np

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

diff = H[1:] - H[:-1]
diff = [x if x > 0 else 0 for x in diff]
answer = H[0] + sum(diff)
print(answer)

Solution (Python):


N=int(input())

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

for i in range(1,101):
    judge=False
    for item in H:
        if judge:
            if item>=i:
                continue
            else:
                judge=False
        else:
            if item>=i:
                judge=True
                count+=1
            else:
                continue
print(count)

Solution (Python):
n = int(input())
h = list(map(int,input().split()))
h.insert(0,0)
sum = 0
bottom = 0
for i, hn in enumerate(h):
  if (i == 0) :
    continue
  if (hn < h[i-1]):
    bottom = hn
  else:
    sum += hn - h[i-1]
print(sum)

Solution (Python):
n = int(input())
array = [int(x) for x in input().split()]
now = 0
cnt = 0
for a in array:
  if a > now:
    cnt += a-now
  now = a
print(cnt)

Solution (Python):
n = int(input())
array = [int(x) for x in input().split()]
now = 0
cnt = 0
for a in array:
  if a > now:
    cnt += a-now
  now = a
print(cnt)

Solution (Python):



N = int(input())
h = list(map(int, input().split()))
def bury(x):
    for i in range(1,N):
        if x+i >= N or h[x+i] != h[x]:
            break
        else:
            h[x+i] -= 1
    for i in range(1,N):
        if x-i < 0 or h[x-i] != h[x]:
            break
        else:
            h[x-i] -= 1
    h[x] -= 1
 
ans = 0
while sum(h) > 0:
    bury(h.index(max(h)))
    ans += 1
    
print(ans)

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    h = list(map(int, input().rstrip('\n').split()))
    l = 0
    cnt = 0
    for i in range(n):
        if l < h[i]:
            cnt += h[i] - l
        l = h[i]
    print(cnt)


if __name__ == '__main__':
    slove()

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
ans = 0
def reverse():
    p = h.index(max(h))
    a = 0
    if p == n-1:
        a += 1
        h[p] -= 1
        return a
    elif h[p] == h[p+1] and p < n-1:
        h[p] -= 1
        return a
    else:
        a += 1
        h[p] -= 1
        return a

while sum(h) > 0:
    ans += reverse()
print(ans)

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





def bury(x):
    for i in range(1,N):
        if x+i >= N or h[x+i] != h[x]:
            break
        else:
            h[x+i] -= 1
    for i in range(1,N):
        if x-i < 0 or h[x-i] != h[x]:
            break
        else:
            h[x-i] -= 1
    h[x] -= 1

ans = 0
while sum(h) > 0:
    bury(h.index(max(h)))
    ans += 1
    
print(ans)

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 = float('inf')
    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()))
ans = 0
while True:
  water = False
  finish = True
  for i in range(n):
    if h[i] > 0:
      h[i] -= 1
      water = True
      finish = False
    elif water:
      ans += 1
      water = False
  if water:
    ans += 1
  if finish:
    break
print(ans)

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

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

water=0
count=0

for i in range(n):
    if h[i]>water:
        count+=h[i]-water
    
    water=h[i]
print(count)

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

w = 0
c = 0
for i in range(n):
    if h[i] > w:
        c += h[i] - w
    w = h[i]

print(c)

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

water = 0
pre = 0
for now in h_s:
  if now > pre:
    
    water += now - pre
  pre = now
print(water)

Solution (Python):
from collections import deque

def sol():
  q = deque()
  q.append(H)
  ans = 0
  while len(q) != 0:
    prv_H = q.pop()
    min_h = min(prv_H)
    ans += min_h
    
    tmp_H = ''.join([',' if h-min_h == 0 else str(h-min_h)+' ' for h in prv_H])
    for sub_H in tmp_H.split(','):
      if len(sub_H.replace(' ','')) != 0 :
        q.append([int(h) for h in sub_H.split()])
    
  return ans

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

Solution (Python):
n = int(input())
flowers = list(map(int,input().split()))
ans = 0
if n ==1:
    print(flowers[0])
    exit()
while any(flowers):
    count = 0
    for i in range(n):
        if i ==0:
            if flowers[i]!=0:
                count +=1
        else:
            if (flowers[i] > 0) and (flowers[i-1]==0):
                    count +=1
    ans +=count
    flowers = [x-1 if x>0 else 0 for x in flowers]
print(ans)

Solution (Python):
import copy
N = int(input())
H = list(map(int,input().split()))
HH = copy.deepcopy(H) 
ans = 0
while HH.count(0) != N:
  for i in range(N):
    if HH[i] == 0:
      pass
    else:
      HH[i] -= 1
      if i == N - 1:
        ans += 1
      else:
        if HH[i+1] == 0:
          ans += 1
print(ans)

Solution (Python):
import sys
from bisect import *
from collections import *
from copy import deepcopy
from datetime import *
from heapq import *
from itertools import *

from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N = int(input())
    HS = list(map(int, input().split()))
    max_h = max(HS)
    ans = 0
    for i in range(1, max_h+1):
        tmp = 0
        state = False
        for j in range(N):
            if HS[j] >= i and not state:
                tmp += 1
                state = True
            elif HS[j] < i and state:
                state = False
        ans += tmp
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
n =int(input())
h = list(map(int,input().split()))
i = 0
res = 0
for _ in range(1,10000):
    i = 0
    while h[i] == 0:
        i += 1
        if i >n-1:
            break
    if i > n-1:
        break
    while h[i]>0:
        h[i] -= 1
        i += 1
        if i > n-1:
            break
    res += 1

print(res)

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

ans, cur = 0, 0
for h in H:
    if cur < h:
        ans += h - cur
    cur = h
print(ans)

Solution (Python):
n = int(input())
l = list(map(int,input().split()))
count = 0
prev = 0
for i in l:
  if i > prev:
    count += i - prev
  prev = i
    
print(count)

Solution (Python):
N=int(input());a=0;t=0
for h in map(int,input().split()):
    a+=max(h-t,0);t=h
print(a)

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



while (len(h)):
    now_h = h.pop()
    min_k = min(now_h)
    ans += min_k
    tmp = []
    for i in range(len(now_h)):
        now = now_h[i] - min_k
        if now == 0:
            if len(tmp):
                h.append(tmp)
                tmp = []
        else:
            tmp.append(now)
    if len(tmp):
        h.append(tmp)

print(ans)

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

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

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

ct  = 0
prev = 0
for i in l:
    if i > prev:
        ct += i - prev
    prev = i
    
print(ct)

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

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

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

water = 0
before = 0
for i in lis_h:
    if i > before:
        water += i - before
    before = i

print(water)

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

cnt=0
while any([i!=0 for i in h]):
    start,end=100,100
    for i in range(n+2):
        if h[i]!=0:
            start=min(start,i)
        elif h[i]==0 and start<i:

            end=i
            break
    l=[i-1 for i in h[start:end]]
    h=h[:start]+l+h[end:]
    cnt+=1
print(cnt)

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

water = 0
before = 0
for i in lis_h:
    if i > before:
        water += i - before
    before = i

print(water)

Solution (Python):


n=int(input())  
h=list(map(int, input().split()))  
cnt=0
L=0
while L != len(h):
    if h[L] != 0:
        for r in range(L+1 ,len(h)):
            if h[r] == 0:
                
                h[L:r] = [i-1 for i in h[L:r]]
                cnt+=1
                break
        else:
            r = len(h)
            h[L:r] = [i-1 for i in h[L:r]]
            cnt+=1
    elif h[L] == 0:
        L+=1
print(cnt)

Solution (Python):


n=int(input())  
h=list(map(int, input().split()))  
cnt=0
L=0
while L != len(h):
    if h[L] != 0:
        for r in range(L+1 ,len(h)):
            if h[r] == 0:
                
                for k in range(L,r):
                    h[k]-=1
                cnt+=1
                break
        else:
            r = len(h)
            for k in range(L,r):
                h[k]-=1
            cnt+=1
    elif h[L] == 0:
        L+=1
print(cnt)

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())
inp_h = [int(i) for i in input().split()]

h_max = max(inp_h)
h_len = len(inp_h)

ind = [0]*h_len

h_bool = [True if ind[i] == inp_h[i] else False for i in range(h_len)]

def make_index(h_bool):
    try:
        index = h_bool.index(False)
    except:
        index = -1
    return index

num = 0
while True:
    index = make_index(h_bool)
    index_list = []
    if index != -1:
        while True:
            if index < h_len:
                if h_bool[index] == False:
                    index_list.append(index)
                    index += 1
                elif h_bool[index] == True:
                    ind = [ind[i]+1 if i in index_list else ind[i] for i in range(h_len)]
                    h_bool = [True if ind[i] == inp_h[i] else False for i in range(h_len)]
                    num += 1
                    break
            elif index >= h_len:
                ind = [ind[i]+1 if i in index_list else ind[i] for i in range(h_len)]
                h_bool = [True if ind[i] == inp_h[i] else False for i in range(h_len)]
                num += 1
                break
    else:
        break
    
print(num)

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

def rWater(L):

  if len(L) == 1:
    return L[0]
  if L[0] == 0:
    return rWater(L[1:])
  if L[-1] == 0:
    return rWater(L[:-1])
  if 0 in L:
    return rWater(L[:L.index(0)]) + rWater(L[L.index(0)+1:])
  return rWater(list(map(lambda x: x-1,L)))+1
print (rWater(h))

Solution (Python):
def cal(n):
    if len(n)==1:
        return n[0]
    if len(n)==0:
        return 0
    if 0 in  n:
        indexes=n.index(0)
        ind1=n[indexes+1:]
        ind2=n[:indexes]
        return cal(ind2)+cal(ind1)
    else:
        mins=min(n)
        lists=[n[j]-mins for j in range(len(n))]
        return cal(lists)+mins
num=int(input())
listw=list(map(int,input().split()))
print(cal(listw))

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

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

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

def f(x):
  m=min(x)
  n=len(x)
  if n>1:
    x=[x[i]-m for i in range(n)]
    temp=devider(x)
    for t in temp:
      m+=f(t)
  return m

def devider(y):
  output=[]
  n=len(y)
  i=0
  while i<n:
    while i<n and y[i]==0:
      i+=1
      
    if i>=n:
      break
      
    j=i+1
    while j<n and y[j]!=0:
      j+=1
      
    if j-i==1:
      output.append([y[i]])
    else:
      output.append(y[i:j])
      
    i=j
    
  return output

h=devider(h)
ans=0
for htemp in h:
  ans+=f(htemp)
  
print(ans)

Solution (Python):
n=int(input())
h=[int(i) for i in input().split()]
hana=[0]*n
ans=0
left=right=0
while hana!=h:
    for i in range(n):
        right=i
        if hana[i]==h[i]:
            if left<right:
                for j in range(left,right):
                    hana[j]+=1
                ans+=1
            left=right+1
        elif i==n-1:
            if left<n:
                for j in range(left,n):
                    hana[j]+=1
                ans+=1
    left=right=0
print(ans)

Solution (Python):
N = int(input())
h = list(map(int, input().split()))
if sum(h) == 0:
    print(0)
    exit()
ans = 0
flag = False
while True:
    if h[0] == 0:
        flag = True
    for i in range(N):
        if h[i] == 0 and flag == True:
            continue
        elif h[i] == 0 and flag == False:
            break
        h[i] -= 1
        flag = False
    ans += 1
    if sum(h) == 0:
        break
print(ans)

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

ans = 0
h_min = min(h_list)

ans += h_min

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

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

ans = 0
h_min = min(h_list)

ans += h_min

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

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

cnt = 0

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

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
global count
count = 0
def calc(data):
    if len(data) == 0:
        return 0
    if min(data) > 0:
        data = list(map(lambda x:x - 1, data))
        global count
        count += 1
        calc(data)
    else:
        k = data.index(min(data))
        calc(data[0:k])
        calc(data[k+1:])
calc(h)
print(count)

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

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

ans = 0
tmp = 0

for i in range(n):
    ans += h[i]
    tmp = int(h[i])
    for j in range(i, n):
        if h[j] - tmp >= 0:
            h[j] -= tmp
        else:
            tmp = int(h[j])
            h[j] = 0

print(ans)

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

ans = 0
tmp = 0

for i in range(n):
    ans += h[i]
    tmp = copy.deepcopy(h)
    tmp_ = tmp[i]
    for j in range(i, n):
        if h[j] - tmp_ >= 0:
            h[j] -= tmp_
        else:
            tmp_ = tmp[j]
            h[j] = 0

print(ans)

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

out = 0

def divide_list_into_zero(l):
  ret = []
  tmp = []
  for i in l:
    if i != 0:
      tmp.append(i)
    elif len(tmp) is not 0:
      ret.append(tmp)
      tmp = []
  if len(tmp) is not 0:
    ret.append(tmp)
  return ret

def substract(l):
  global out
  out += 1
  return [i-1 for i in l]

def watering(l):
  tmp_1 = substract(l)
  tmp_2 = divide_list_into_zero(tmp_1)
  for child in tmp_2:
    watering(child)

for l in divide_list_into_zero(h):
  watering(l)
print(out)

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

water = 0
before = 0
for i in lis_h:
    if i > before:
        water += i - before
    before = i

print(water)

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

Solution (Python):
N=int(input())
h=list(map(int, input().split()))
c=i=0
while sum(h)>0:
  if h[i]>0:
    j=i
    c+=1
    while j<N and h[j]>0:
      h[j]-=1
      j+=1
  else:
    i+=1
print(c)

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

cnt = 0
while True:
    decrease_cnt = 0
    for j in range(N):
        if h[j] > 0:
            h[j] -= 1
            decrease_cnt += 1
        elif decrease_cnt > 0:
            break
    if decrease_cnt == 0:
        print(cnt)
        break
    else:
         cnt += 1

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

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

Solution (Python):
def test():
    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)


if __name__ == "__main__":
    test()

Solution (Python):
def test():
    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)


if __name__ == "__main__":
    test()

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

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

Solution (Python):
def countA(A):
    global cnt
    if len(A)==1:
        cnt += A[0]
    else:
        amin = min(A)
        A = [A[i]-amin for i in range(len(A))]
        cnt += amin
        while A:
            if A[0]==0:
                A.pop(0)
            elif A[-1]==0:
                A.pop()
            else:break
        B = []
        for i in range(1,len(A)):
            if A[i]==0 and A[i-1]==0:
                B.append(i)
        C = []
        for i in range(len(A)):
            if i not in B:
                C.append(A[i])
        C0 = []
        for i in range(len(C)):
            if C[i]==0:
                C0.append(i)
        if len(C0)==0 and len(C)>0:
            countA(C)
        else:
            cur = 0
            for c in C0:
                countA(C[cur:c])
                cur = c+1
            if cur<len(C):
                countA(C[cur:])
            
N = int(input())
H = list(map(int,input().split()))
cnt = 0
countA(H)
print(cnt)

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

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

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:
        break
      else:
        H[j]-=1
    ans+=1
print(ans)

Solution (Python):
N = int(input())
data = [int(i) for i in input().split()]
z_frug = 1
counter = 0
point = 0
i = 0
a = 0
while sum(data)!= 0:
  a +=1
  
  try:
    y = data[i]
  except:
    pass
  if y == 0:
    z_frug = (z_frug+1)%2
  if z_frug == 0 or i==N:
    if counter != 0:
      x = min(data[i-counter:i])
      point += x
      for j in range(i-counter,i):
        
        data[j] -= x
      i = 0
      counter = 0
    else:
      i += 1
    z_frug = 1
    
  else:
    counter += 1
    i += 1
    
print(point)

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

for i in range(N):
    while H[i] != 0:
        for j in range(i,N):
            if H[j] == 0:
                break
            else:
                H[j] -= 1
        count += 1
    
print(count)

Solution (Python):
import numpy as np

input()
H = np.array([int(h) for h in input().split()])
k = np.array([1, -1])
c = 0
while (H >= 1).any():
    m = H[H >= 1].min()
    n_blocks = (np.convolve(H >= 1, k))
    c += (n_blocks < 0).sum() * m
    H = np.maximum(H - m, 0)

print(c)

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

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

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

Solution (Python):

import numpy as np
n = int(input())
h = list(map(int,input().split()))
l = [9]*n
t = 0
x = 0
if n == 1:
    print(h[0])
    exit()

while max(h) > 0:
    if x != 0:
        for i in range(n):
            h[i] -= 1

    for i in range(n):
        if h[i] > 0:
            l[i] = 1
        else:
            l[i] = 0

    for i in range(n-1):
        if i == 0 and l[0] == 1:
            t += 1
        if l[i+1]-l[i] == 1:
            t += 1
    x += 1

print(t)

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

for _ in range(max(h)):
    vi = [i for i in range(n) if h[i] > 0]
    cnt = 1
    for i in range(len(vi)-1):
        cnt += (vi[i] != vi[i+1] -1)
    ans += cnt
    h = list(map(lambda x: x - 1, h))
    
print(ans)

Solution (Python):
N = int(input())
H = [int(x) for x in input().split()]
ans = 0
for i in range(N):
  mi = H[i]
  ans += mi
  for j in range(i+1,N):
    if mi<=H[j]:
      H[j] -=mi
    else:
      mi = min(mi,H[j])
      H[j]=0
print(ans)

Solution (Python):
import numpy as np
if __name__ == '__main__':
    N = int(input())
    H = np.array(list(map(int, input().split())))
    
    count = 0
    while H.sum() != 0:
        start = 0
        for i in range(N):
            if H[i] == 0:
                end = i
                if len(H[start:end]) > 0:
                    num = H[start:end].min()
                    H[start:end] -= num
                    count += num
                start = i+1
        if len(H[start:i+1]) > 0:
            num = H[start:i+1].min()
            H[start:i+1] -= num
            count += num
    print(count)

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


while sum(h) != 0:
    
    left = float("inf")
    right = float("inf")
    
    
    for i in range(n):
        if h[i] > 0:
            left = i
            break
    
    for j in range(i + 1, n):
        if h[j] <= 0:
            right = j
            break
    if right == float("inf"):
        right = n
    
    for i in range(left, right):
        h[i] -= 1
    ans += 1
print(ans)

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
ans = 0
while sum(h) != 0:
    left = float("inf")
    right = float("inf")
    for i in range(n):
        if h[i] > 0:
            left = i
            break
    for j in range(i + 1, n):
        if h[j] <= 0:
            right = j
            break
    if right == float("inf"):
        right = n
    for i in range(left, right):
        h[i] -= 1
    ans += 1
print(ans)

Solution (Python):

n=int(input())
H=list(map(int,input().split()))
count=0
while True:
    start,end=0,0
    for i in range(n):
        if H[i]!=0:
            H[i]-=1
            start=1
            if end:
                count+=1
                end=0
        else:
            if start:
                end=1
    if not start:
        break
    count+=1
print(count)

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

Solution (Python):
n=int(input())
h=list(map(int,input().split()))
count=0
i=0
while(i<n):
  if(h[i]==0):
    i=i+1
    continue
  j=i
  while(j<n):
    if(h[j]==0):
      break
    if(h[j]>0):
      h[j]=h[j]-1
      j=j+1
      continue
  count=count+1
  
print(count)

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

while True:
    if 0 not in h:
        for i in range(N):
            h[i] -= 1
        ans += 1
    elif set(h) == {0}:
        break
    else:
        tmp = 0
        for i in range(N):
            if h[i] > 0:
                h[i] -= 1
                tmp = 1
            elif tmp == 0:
                continue
            else:
                break
        ans += tmp
print(ans)

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

count = a[0]

for i in range(n-1):
    if a[i] < a[i+1]:
        count += a[i+1] - a[i]

print(count)

Solution (Python):
import numpy as np
N = int(input())
h = list(map(int, input().split()))
h = np.array(h)
h_diff = h[1:] - h[:N-1]
count = 0
for i in range(N-1):
    count -= min(h_diff[i], 0)
    
print(count + h[N-1])

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

l=r=0
count=0


while any(h)==True:
    for i in range (n):
        if h[i]!=0:
            l = i
            break
    if all(h[l+1:n])==True:
        r = n-1
    else:
        for k in range (l+1,n):
            if h[k] == 0:
                r = k-1
                break

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

    count += 1
print(count)

Solution (Python):
N = int(input())
H = [int(i) for i in input().split()]
Min = min(H)
ans = Min
for i in range(N):
    H[i] -= Min
dif = []
pre = 0
for i in range(N):
    if pre!=H[i] and H[i]-pre>0:
        dif.append(H[i]-pre)
    else:
        dif.append(0)
    pre = H[i]

print(ans+sum(dif))

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


n = I()
L = [-INF] + LI()
flag = True
cnt = 0
j = 0
while flag:
    flag = False
    for i in range(n):
        if L[i] <= j < L[i+1]:
            cnt += 1
            flag = True
    j += 1



print(cnt)

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

I = []
for _ in range(max(H)):
    I.append([1 if h > 0 else 0 for h in H])
    H = [h-1 if h > 0 else 0 for h in H]
    
for i in I:
    j = [l for l in ''.join([str(k) for k in i]).split('0') if l != '']
    ans += len(j)
    
print(ans)

Solution (Python):
def resolve():
    n = int(input())
    h = list(map(int, input().split()))
    res = 0
    for height in range(1, max(h) + 1):
        flag = False
        for i in range(n):
            if h[i] >= height and not flag:
                flag = True
                res += 1
            elif h[i] < height:
                flag = False
    print(res)


if __name__ == "__main__":
    resolve()