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()))
c=0
while h:
  while h:
    if h[-1]==0:
      _=h.pop(-1)
    else:
      break
  if h:
    l=len(h)
    for i in range(l):
      if h[l-i-1]:
        h[l-i-1]-=1
      else:
        break
    c+=1
print(c)

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

Solution (Python):
def main():
    N = int(input())
    height = list(map(int, input().split(" ")))
    target = [0] * N
    result = 0
    
    while not height == target:
        
        end = False
        result += 1
        for i in range(N):
            if not end:
                if height[i] > 0:
                    end = True
                    height[i] -= 1
            else:
                if height[i] > 0:
                    height[i] -= 1
                else:
                    break
    print(result)


if __name__ == '__main__':
    main()

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

L.insert(0,0)
ans=0
for i in range(N):
  ans+=max(0,L[i+1]-L[i])
print(ans)

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

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

def main():
    N = INT() 
    H = LIST()
    ans = 0
    for i in range(N - 1):
        if H[i] > H[i + 1]:
            ans += H[i] - H[i + 1]
    ans += H[N - 1]
    print(ans)
    


if __name__ == "__main__":
    main()

Solution (Python):

import sys
import math
import os
import itertools
import _collections
import string

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]

class Util():
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Util.round_up(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)

def main():
    N = cin.int()
    H = cin.mapInt()
    ans = 0
    now = 0
    for h in H:
        if now < h:
            ans += h - now
        now = h
    print(ans)
    return

if __name__ == "__main__":
    main()

Solution (Python):
import queue

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

q = queue.Queue()
q.put([H,0])

num = 0
while not q.empty():
    data = q.get()
    if len(data[0]) == 0:
        continue
    if len(data[0]) == 1:
        num += data[0][0]-data[1]
        continue
    min_index = data[0].index(min(data[0]))
    num += data[0][min_index]-data[1]
    tmp = data[0][min_index]

    tmp_data = []
    for d in data[0]:
        if d == data[0][min_index]:
            q.put([tmp_data,tmp])
            tmp_data = []
        else:
            tmp_data.append(d)
    q.put([tmp_data,tmp])

print(num)

Solution (Python):

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

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

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

ans = 0
pre = 0
for i in range(N):
    ans += max(0, H[i] - H[i - 1])

print(ans)

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

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

    pre = h

print(ans)

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

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

print(ans)

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

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

        elif cnt==1 and h[i] == j:
            h[i]-=1

        elif cnt==1 and h[i]!=j:
            cnt=0
            ans +=1


    if cnt ==1:
        ans+=1
print(ans)

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

            
    if renzokucnt >0:ans+= 1
    
        
print(ans)

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

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

print(ans)

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

Solution (Python):

import math
import heapq
import bisect
import numpy as np


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

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

print(ans)

Solution (Python):
from collections import deque
import numpy as np
N = int(input())
h = np.array(list(map(int,input().split())))
count = 0
tmp = deque()
tmp.append(h)
while True:
    st,en = -1,-1
    if len(tmp) == 0:
        break
    count += min(tmp[0])
    tmp[0] -= min(tmp[0])
    if list(tmp[0]) == [0]*len(tmp[0]):
        tmp.popleft()
        continue
    for i in range(len(tmp[0])):
        if st == -1 and tmp[0][i] != 0:
            st = i
        if st != -1 and tmp[0][i] == 0:
            en = i
        if st != -1 and i == len(tmp[0])-1 and tmp[0][i] != 0:
            en = i+1
        if st != -1 and en != -1:
            tmp.append(tmp[0][st:en])
            st,en = -1,-1
    tmp.popleft()
print(count)

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

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

ans = 0

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

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

k = 0
while any([i > 0 for i in h_list]):
    bool_list = [True if i==max(h_list) else False for i in h_list]
    indexes = []
    true_index = bool_list.index(True)
    while bool_list[true_index]:
        indexes.append(true_index)
        true_index += 1
        if true_index == len(h_list):
            break

    h_list = [h_list[i]-1 if i in indexes else h_list[i] for i in range(len(h_list))]
    k += 1
  
print(k)

Solution (Python):

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

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

ans = 0
mode = 0

for i in h:
    while i > mode:
        mode += 1
        ans += 1
    while i < mode:
        mode -= 1
print(ans)

Solution (Python):
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

n = ni()
a = na()

res = 0
while sum(a):
    res += 1
    f = False
    for i in range(n):
        if a[i] > 0:
            a[i] -= 1
            f = True
        elif f is True:
            break

print(res)

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

Solution (Python):
def examA():
    L = LI(); L.sort()
    ans = L[0]*L[1]//2
    print(ans)
    return

def examB():
    def fun(s):
        if s%2==0:
            return s//2
        else:
            return s*3+1
    S = I()
    d = defaultdict(bool)
    d[S] = True; cur = 1
    while(True):
        cur +=1
        S = fun(S)
        if d[S]:
            break
        d[S] = True
    print(cur)
    return

def examC():
    N = I()
    H = LI()
    cur = 0
    ans =0
    for i in range(N):
        if cur<H[i]:
            ans += H[i]-cur
        cur = H[i]
    print(ans)
    return

def examD():
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,ALPHABET, _ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 1e-9
alphabet = [chr(ord('a') + i) for i in range(26)]
ALPHABET = [chr(ord('A') + i) for i in range(26)]

if __name__ == '__main__':
    examC()

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

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

Solution (Python):
N=int(input())
H=[int(i) for i in input().split()]
ans=0
while any(h>0 for h in H):
  itv=1
  for i in range(N-1):
    if H[i]>0 and H[i+1]<=0:
      itv+=1
  if H[-1]<=0:
    itv-=1
  ans+=itv
  H=[h-1 for h in H]
  
print(ans)

Solution (Python):
import itertools


def get_num_1group(input_list):
    num_group = 0
    for key, elems in itertools.groupby(input_list):
        if key == 1:
            num_group += 1
    return num_group


N = int(input())
H = list(map(int, input().split()))
maxH = max(H)
hist = [[0 for _ in range(N)] for _ in range(maxH)]
for idx, h in enumerate(H):
    for num in range(h):
        hist[num][idx] = 1

print(sum([get_num_1group(hist[num]) for num in range(maxH)]))

Solution (Python):
n = int(input())
h = [int(x) for x in input().split()]
ans = 0
while sum(h) != 0:
    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)

Solution (Python):
import sys

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

    ans = 0
    zero_list = [0] * N

    while True:
        for i in range(N):
            if h[i] > zero_list[i]:
                L_p = i
                R_p = i

                for j in range(L_p+1, N):
                    if h[j] > zero_list[i]:
                        R_p = j
                    else:
                        break

                for k in range(L_p, R_p+1):
                    zero_list[k] += 1

                ans += 1
                break

        if h == zero_list:
            break
    print(ans)

main()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
cnt = 0
while max(a) != 0:
  
  betweenZero = True
  for i in range(n):
    if a[i] != 0:
      a[i] -= 1
      betweenZero = False
    elif betweenZero == False:
      cnt += 1
      betweenZero = True
  if betweenZero == False:
    cnt += 1
print(cnt)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
cnt = 0
while max(a) != 0:
  
  betweenZero = True
  for i in range(len(a)):
    if a[i] != 0:
      a[i] -= 1
      betweenZero = False
    elif betweenZero == False:
      cnt += 1
      betweenZero = True
  if betweenZero == False:
    cnt += 1
print(cnt)

Solution (Python):
N = int(input())
H = list(map(int, input().split()))
ans = 0
for l in range(1, max(H)+1):
    streak = False
    for h in H:
        if h>=l:
            streak=True
        elif streak:
            streak=False
            ans+=1
    if streak: ans+=1

print(ans)

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

count = 0
while sum(ans) != 0:
    st = -1
    ed = 0
    for i in range(n):
        if (ans[i] != 0) and (st == -1):
            st = i
        if ans[i] == 0 and st != -1:
            ed = i - 1
            break;
        if (st != -1) and (ed == 0) and (i == n-1):
            ed = i
            break;
    for i in range(st, ed+1):
        ans[i] -= 1
    count += 1
    
print(count)

Solution (Python):
def p_c():
    n = int(input())
    *H, = map(int, input().split())
    ans = 0
    while sum(H) > 0:
        bf = False
        st = 0
        while H[st] == 0:
            st += 1
        for i in range(st, n):
            if H[i] == 0:
                if bf:
                    ans += 1
                bf = False
            else:
                H[i] -= 1
                bf = True
                if i == n - 1:
                    ans += 1
    print(ans)
    
p_c()

Solution (Python):
N=int(input())
H=list(map(int,input().split()))
lst=[0 for i in range(N)]
count=0
flag=0
while H!=lst:
    for i in range(N):
        if H[i]>lst[i]:
            lst[i]+=1
            flag=1
        else:
            if flag:
                flag=0
                count+=1
    if flag:
        count+=1
        flag=0
print(count)

Solution (Python):
import sys

n, *h = map(int, sys.stdin.read().split())

def main():
    cnt = 0

    for _ in range(max(h)):
        prev_0 = True
        for i in range(n):
            if h[i] > 0:
                h[i] -= 1
                if prev_0:
                    cnt += 1
                    prev_0 = False
            else:
                prev_0 = True
    
    return cnt

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

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

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
call = 0
for i in range(max(h)):
    c = 0
    if h[0]<=i:
        
        for j in range(n-1):
            if h[j]<=i and h[j+1]>i:
                c += 1
    elif h[-1]<=i:
        
        for j in range(n-1):
            if h[j]>i and h[j+1]<=i:
                c += 1
         
    else:
        
        c = 1
        for j in range(n-1):
            if h[j]<=i and h[j+1]>i:
                c += 1
    
    call += c
print(call)

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

ans = 0
h_list.append(0)
while True:
    idx_left = 0
    idx_right = None
    for i in range(N):
        if h_list[i] == 0 and h_list[i+1] != 0:
            idx_left = i+1
        if h_list[i] != 0 and h_list[i+1] == 0:
            idx_right = i+1

        if idx_right is not None:
            if idx_right == idx_left:
                pour = h_list[idx_left]
                ans += pour
                h_list[idx_left] = 0
            else:
                pour = min(h_list[idx_left:idx_right])
                for j in range(idx_right - idx_left):
                    h_list[idx_left+j] = h_list[idx_left+j] - pour
                ans += pour
            break

    if all([h == 0 for h in h_list]):
        break

print(ans)

Solution (Python):
n=int(input())
H=[0]+list(map(int,input().split()))
S=[0]*(n+1)
r=0
while H!=S:
    for i in range(n):
        if H[i]==0 and H[i+1]!=0:
            r+=1
    for i in range(n):
        if H[i+1]!=0:
            H[i+1]-=1
print(r)

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

k=0
while(True):
    
    s=0
    t=n 
    c=False
    for i in range(0,n):
        if(not(c) and List[i]>0):
            s=i
            c=True
        elif(c and List[i]<=0):
            t=i
            break
    
    if(not(c) and t==n):
        print(k)
        exit()
    for i in range(s,t):
        List[i]-=1
    k+=1

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

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

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



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



    ans = 0
    while len(h) != 0:
        for i in range(len(h) - 1, 0, -1):
            if h[i] == h[i - 1]:
                h.pop(i)

        if len(h) == 1:
            ans += h[0]
            break

        ma = max(h)
        mai = h.index(ma)
        if mai == len(h) - 1:
            ans += ma - h[mai - 1]
        elif mai == 0:
            ans += ma - h[mai + 1]
        else:
            ans += min(ma - h[mai + 1], ma - h[mai - 1])
        h.pop(mai)

    print(ans)




if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input():
    return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    h=list(map(int,input().split()))
    for i in range(10**7):
        c=-1
        for j,x in enumerate(h):
            if c==-1 and x!=0:
                c=j
            elif c!=-1 and x==0:
                break
        else:
            j+=1
        if c==-1:
            print(i)
            exit()
        for k in range(c,j):
            h[k]-=1

if __name__ == '__main__':
    main()

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()))
w = h[0]
for i in range(n-1):
    if(h[i+1] > h[i]):
        w += h[i+1]-h[i]
print(w)

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

count=1
res=0
while True:
    if max(H)==0:
        break
    else:
        i=0
        try:
            while i<N:
                if H[i]==0:
                    i+=1
                else:
                    res+=1
                    while i<N and H[i]>0:
                        H[i]-=1
                        i+=1
        except:
            continue
print(res)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
x=0
ans=0
while sum(a)>0:
    while x<=n-1 and a[x]==0:
        x+=1
    while x<=n-1 and a[x]!=0:
        a[x]-=1
        x+=1
    ans+=1
    x=0
print(ans)

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

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

Solution (Python):
import sys
import math
import numpy as np

stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n = ni()
h = na()
bar = h[0]
s = h[0]
for hi in h[1:]:
    s += max(hi - bar, 0)
    bar = hi
print(s)

Solution (Python):
N = int(input())
H = list(map(int, input().split()))
def rec(H):
    ans = 0
    if H:
        hmin = min(H)
        ans += hmin
        K = [h - hmin for h in H]
        I = [i for i, k in enumerate(K) if not k]
        ans += rec(K[:I[0]])
        for i, j in zip(I, I[1:]):
            ans += rec(K[i+1:j])
        ans += rec(K[I[-1]+1:])
    return ans
print(rec(H))

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

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

for i in range(n):
    while h[i]!=0:
        if h[i:].count(0)==0:
            m=min(h[i:])
            for j in range(i,n):
                h[j]-=m
            ans+=m
        else:
            ind=h[i:].index(0)
            m=min(h[i:i+ind])
            for j in range(i,i+ind):
                h[j]-=m
            ans+=m
print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
s = [(0, n)]
ans = 0
while s:
    l, r = s.pop()
    if l == r:
        continue
    m = min(a[l:r])
    ans += m
    for i in range(l, r):
        a[i] -= m
    for i in range(l, r):
        if a[i] == 0:
            s.append((l, i))
            s.append((i + 1, r))
            break
print(ans)

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

print(ans)

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

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

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

print(ans)

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

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

print(ans-1)

Solution (Python):
n = int(input())
l = list(map(int, input().split())) + [0]
ans = 0
min_v = 1000
curr = 0
last = -1
count = 0

for _ in range(n+1):
    for i in range(n+1):
        curr = l[i]
        if curr == 0:
            for j in range(last+1, i):
                l[j] -= min_v

            if i > last + 1:
                count += min_v

            last = i
            min_v = 1000
            curr = 0
        elif curr < min_v:
            min_v = curr
    last = -1

print(count)

Solution (Python):
n = int(input())
H = [0]+list(map(int, input().split()))+[0]
ans = 0
while max(H)>0:
    Zero = []
    for i in range(n+2):
        if H[i] == 0:
            Zero.append(i)

    for i in range(len(Zero)-1):
        if Zero[i+1] == Zero[i] + 1:
            continue
        grw = min( H[Zero[i]+1:Zero[i+1]] )
        for j in range( Zero[i]+1, Zero[i+1] ):
            H[j] -= grw
        ans += grw
print(ans)

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

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

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

print(res)

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

v = list(map(int, input().split()))
v.append(0)

def dfs(l, r):
  
  if l == r:
    return 0

  for i in range(l, r):
    v[i] = max(0, v[i] - 1)

  last = l
  res = 1
  for i in range(l, r):
    if v[i] == 0:
      res += dfs(last, i)
      last = i + 1
  res += dfs(last, r)
  return res

last = 0
res = 0
for i in range(0, n + 1):
  if v[i] == 0:
    res += dfs(last, i)
    last = i + 1

print(res)

Solution (Python):
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


N = int(sys.stdin.buffer.readline())
H = list(map(int, sys.stdin.buffer.readline().split()))

H = np.array(H, dtype=int)

ans = 0
while H.max() > 0:
    l = 0
    r = 0
    while l < N:
        while l < N and H[l] <= 0:
            l += 1
        r = l
        while r < N and H[r] > 0:
            r += 1
        if l < N:
            ans += 1
        l = r
    H -= 1
print(ans)

Solution (Python):
def getNeighboringNumbers(numbers):
    cnt = 0
    flag = False
    pre = -100
    for n in numbers:
        if flag:
            if pre + 1 != n:
                cnt += 1
                flag = False
        else:
            if pre + 1 == n:
                flag = True
            else:
                cnt += 1
        pre = n
    return cnt

n = int(input())
height = list(map(int, input().split()))
M = max(height)
ans = 0
for i in range(M, 0, -1):
    indexes = [k for k, x in enumerate(height) if x == i]
    cont = getNeighboringNumbers(indexes)
    ans += cont
    for k in indexes:
        height[k] -= 1
print(ans)

Solution (Python):
N = int(input())
str_h = list(map(str, input().split()))
h_list = []
for i in range(len(str_h)):
    h_list.append(int(str_h[i]))
count = 0

while h_list.count(0) != len(h_list):
    if h_list.count(0) == 0:
        h_list = list(map(lambda x: x-1, h_list))
        count += 1
    else:
        switch = []
        for i in range(len(h_list)):
            if h_list[i] == 0:
                switch.append(0)
            else:
                switch.append(1)
        if switch[0] == 1:
            j = 0
            while switch[j] == switch[j+1] and j < len(switch)-1:
                j += 1
            h_list[0:j+1] = list(map(lambda x: x-1, h_list[0:j+1]))
            switch[0:j+1] = list(map(lambda x: x-1, switch[0:j+1]))
            count += 1
        for i in range(len(switch)-1):
            if switch[i] == 0 and switch[i+1] == 1:
                count += 1            
        for i in range(len(switch)):
            h_list[i] -= switch[i]
print(count)

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

ans = 0
for l in range(n):
    while H[l] > 0:
        r = l + 1
        while r < n:
            if H[r] > 0:
                r += 1
            else:
                break
    
        for j in range(l, r):
            H[j] += -1

        ans += 1

print(ans)

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

for i in range(100):
	prev = 0
	for j,h in enumerate(H):
		if prev == 0 and h != 0:
			ans+=1
		prev = h
		if h != 0:
			H[j]-=1
	if sum(H) == 0:
		break

print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(1000000)
n = int(input())
hs = list(map(int, input().split()))

def best(plants, counter):
    all0 = True
    started = False
    for i,p in enumerate(plants):    
        if p > 0:
            all0 = False
        if p == 0:
            if started:
                break
            else:
                continue
        plants[i] -= 1
        started = True

    if all0:
        return counter
    return best(plants, counter+1)
    
cnt = best(hs, 0)
print(cnt)

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

ans = 0
g = [0]*n
while h != g:
    t = []
    for _h, _g in zip(h, g):
        if _h != _g:
            t.append(1)
        else:
            t.append(0)

    g = list(map(lambda x: x[0]+x[1], zip(g, t)))

    t.append(0)
    c = t[0]
    for i in range(len(t)):
        if c != t[i] and t[i] == 0:
            ans += 1

        c = t[i]

print(ans)

Solution (Python):


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


counter = 0

def zero_count(L):
    ans = []
    for i in range(len(L)):
        if L[i] == 0:
            ans.append(i) 
    return ans

def change_number(i,j):
    for iii in range(i,j+1):
        flowers[iii] -= 1
    global counter
    counter += 1
    
    


zeros=zero_count(flowers)

while len(zeros) != n:
    if len(zeros) == 0:

        
        change_number(0,n-1)
        
        
    else:
        for i in range(len(zeros)):
            if i==0 and zeros[i] !=0:
                

                change_number(0,zeros[i]-1)
                
            elif i==len(zeros)-1:
                if zeros[i] == n-1:

                    break
                else:

                    change_number(zeros[i]+1,n-1)

            else:
                if zeros[i+1]-zeros[i] != 1:

                    change_number(zeros[i]+1,zeros[i+1]-1)

    
    zeros = zero_count(flowers)
    


print(counter)

Solution (Python):
import collections

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

d = collections.defaultdict(int)
count = 0
updated = True

while updated:
  updated = False

  for n in range(N):
    if H[n] > d[n]:
      d[n] += 1
      updated = True

      if n == N-1:
        count += 1
      elif H[n+1] <= d[n+1]:
        count += 1


print(count)