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())

list = [int(i) for i in input().split()]
count = 0

for i in range(n-1):
    if list[i+1] - list[i] > 0:
        count += list[i+1] - list[i]
count += list[0]
print(count)

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

ans = 0

for i in range(N+1):
    if(h_list[i] - h_list[i-1] > 0):
        ans += (h_list[i] - h_list[i-1])

print(ans)

Solution (Python):
def main():
    n = int(input())
    hs = list(map(int, input().split()))
    res = hs[0]
    for i in range(1, n):
        if hs[i] > hs[i - 1]:
            res += hs[i] - hs[i - 1]
    print(res)


if __name__ == "__main__":
    main()

Solution (Python):
l = input()
a = [int(i) for i in input().split()] 
n = 0
num = a[0]
for i in a:
  max = a[0]
  
  
  if i > a[n-1] and n > 0:
    num += (i-a[n-1])
  n += 1
print(num)

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

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

print(count)

Solution (Python):



if __name__ == '__main__':
    n=int(input())
    l=list(map(int, input().split()))
    
    ans,v=0,0
    for i in range(1,n):
        v+=min(l[i-1],l[i])
    print(sum(l)-v)

Solution (Python):
N = int(input())
height = [0] + [int(i) for i in input().split()]
count = 0
for i in range(N):
  if height[i+1] > height[i]:
    count += height[i+1] - height[i]
print(count)

Solution (Python):
n = int(input())
h = [int(i) for i in input().split()]
c,h = 0,h+[0]
while sum(h):
	f = 0
	for i in range(n+1):
		if f and h[i]==0:
			m,f = min(h[l:i]),0
			for j in range(l,i): h[j]-=m
			c+=m
		elif 1-f and h[i]: f,l = 1,i
print(c)

Solution (Python):
n = int(input())
A = [0] + [int(i) for i in input().split()]
cnt = 0
for i in range(n):
    if A[i + 1] > A[i]:
        cnt += A[i + 1] - A[i]
print(cnt)

Solution (Python):
N = int(input())
hs = [0] + input().split()
cnt = 0

for i in range(1, len(hs)):
  cnt += max(int(hs[i]) - int(hs[i-1]), 0)
print(cnt)

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

ans = h[0]

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

print(ans)

Solution (Python):
import numpy as np

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

ans = 0
for i in range(100 + 1):
	
	for j in range(n+1):
		ishigher = h > i
		if(j==0):
			if ishigher[j] == True:
				ans += 1
		elif j==n:
			if ishigher[j-1] == True:
				ans += 1
		elif (ishigher[j] != ishigher[j-1]):
			ans += 1


print (ans//2)

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

ans = 0
for c_h in range(0, max_h):
    continueing = False
    for h_i in h:
        if not continueing and h_i > c_h:
            ans += 1
            continueing = True
        elif h_i <= c_h:
            continueing = False

print(ans)

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

Solution (Python):
n=int(input())
h=list(map(int, input().split()))
a=[0]*n
ans=0
roop=max(h)
for i in range(roop):
    flag=False
    for j in range(n):
        if h[j]==a[j]:
            flag=False
        elif flag:
            a[j]+=1
        else:
            ans+=1
            a[j]+=1
            flag=True
print(ans)

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

cnt = 0
parts = [h]

while True:
    found = False
    new_parts = []
    for part in parts:
        min_v = min(part)
        cnt += min_v
        if part:
            new_part = []
            for v in part:
                if v > min_v:
                    new_part.append(v - min_v)
                elif new_part:
                    new_parts.append(new_part)
                    new_part = []
            if new_part:
                new_parts.append(new_part)
            found = True
    if not found:
        break
    parts = new_parts

print(cnt)

Solution (Python):
import numpy as np

N = int(input())
h = [int(a) for a in input().split()]
h = np.array([0] + h + [0]) 

diff = np.diff(h)

print(np.sum(diff[diff>0]))

Solution (Python):



N = int(input())
h =  [int(i) for i in input().split()]
h += [0]
ans = 0
add = False

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

print(ans)

Solution (Python):
N = int(input())
h = list(map(int,input().split()))
h += [0]
add = False
ans = 0
for n in range(100):
    for i in range(N+1):
        if h[i] != 0:
            h[i] -= 1
            add = True
        else:
            if add:
                ans += 1
            add = False
print(ans)

Solution (Python):
def a(l):
  if len(l) == 0:
    return 0
  elif len(l) == 1:
    return l[0]
  else:
    m = min(l)
    for j in range(len(l)):
      if m == l[j]:
        return l[j] + a(map(lambda x: x-m,l[0:j])) + a(map(lambda x: x-m,l[j+1:]))
        

i = int(input())
l = raw_input().split()
l = map(lambda x: int(x),l)

print a(l)

Solution (Python):
N = int(input())
h = list(map(int,input().split()))
h += [0]
add = False
ans = 0
for n in range(100):
    for i in range(N+1):
        if h[i] != 0:
            h[i] -= 1
            add = True
        else:
            if add:
                ans += 1
            add = False
print(ans)

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

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

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

print(ans)

Solution (Python):
n = int(input())
c_l = list(map(int, input().split()))
p_l = [0]*n
ans = 0
is_prev_correct = True
while True:
  for i in range(n):
    if c_l[i] == p_l[i]:
      is_prev_correct = True
    elif is_prev_correct:
      p_l[i] += 1
      ans += 1
      is_prev_correct = False
    else:
      p_l[i] += 1
  is_prev_correct = True
  if p_l == c_l:
    break
print(ans)

Solution (Python):


import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
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()
aN = LIST()

ans = 0
for i in range(1, max(aN)+1):
    l = r = 0
    
    while l < N:
        
        while r < N and aN[r] >= i:
            r += 1
        if l != r:
            ans += 1
            l = r
        else:
            l += 1
            r += 1
print(ans)

Solution (Python):


def calc(h):
    N = len(h)
    r = 0
    min_h = min(h)
    if 0 < min_h:
        r += min_h
        for i in range(N):
            h[i] -= min_h

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

    if N == 1:
        return r
    else:
        return r + calc(h[1:])


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

    r = calc(h)

    print(r)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
hs = list(map(int, input().split()))
flags = [i >= 1 for i in hs]

flags.append(False)

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

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

cnt = 0
while True:
    flag = True
    prev = -1
    
    for i in range(n):
        h = hs[i]
        if h == 0:
            
            if prev == -1:
                continue
            
            else:
                cnt += 1
                prev = -1
        else:
            
            if prev == -1:
                flag = False
                hs[i] -= 1
                prev = 0
            
            else:
                hs[i] -= 1
    if prev != -1:
        cnt += 1
    if flag:
        break
print(cnt)

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

ans = 0
k = 1

flags = [li[i] >= k for i in range(N)]
flags.append(False)

while any(flags):
    cnt = 0
    for i in range(N):
        if flags[i] and not flags[i + 1]:
            cnt += 1

    k += 1
    ans += cnt
    flags = [li[i] >= k for i in range(N)]
    flags.append(False)

print(ans)

Solution (Python):
N = int(input())
A = [[int(h) for h in input().split()]]
m = 0
while A != []:
    for i in range(len(A[0])):
        if A[0][i] == 0:
            if i == 0:
                if A[0] == [0]:
                    del A[0]
                else:
                    del A[0][0]
            elif i != 0 and i == len(A[0]) - 1:
                del A[0][i]
            else:
                A.append([A[0][j] for j in range(i)])
                A.append([A[0][j] for j in range(i + 1, len(A[0]))])
                del A[0]
            break
    else:
        m = m + 1
        A.append([A[0][i] - 1 for i in range(len(A[0]))])
        del A[0]
print(m)

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

ans = 0

while len(L) :
    if L[0] == 0 :
        L.pop(0)
    else :
        ans += 1
        for i in range(len(L)) :
            if L[i] != 0 :
                L[i] -= 1
            else :
                break
print(ans)

Solution (Python):
N=int(input())
H=[int(i) for i in input().split()]
W=[0]*N
num=0
i=0
while i<N:
    if W[i]==H[i]:
        i+=1
        continue
    for j in range(i,N):
        if W[j]>=H[j]:
            break
        W[j]+=1
    num+=1
    
print(num)

Solution (Python):
import sys

def main():
    sys.setrecursionlimit(1000000) 
    buf = input()
    N = int(buf)
    buf = input()
    buflist = buf.split()
    h = list(map(int, buflist))
    done = []
    height = []
    for i in range(N):
        if h[i] == 0:
            done.append(True)
        else:
            done.append(False)
        height.append(0)
    print(recursion_water(h, done, height, 0))

def recursion_water(h, done, height, count):
    for i in range(len(h)):
        if done[i]:
            continue
        else:
            count += 1
            for j in range(i, len(h)):
                if not done[j]:
                    height[j] += 1
                    if height[j] == h[j]:
                        done[j] = True
                else:
                    break
            return recursion_water(h, done, height, count)
    return count

if __name__ == '__main__':
    main()

Solution (Python):
def garden(fw):
    if len(fw) == 0:
        return 0
    if len(fw) == 1:
        return fw[0]
    else:
        fwmin = min(fw)
        fwmin_idx = fw.index(fwmin)
        fwl = [x - fwmin for x in fw[:fwmin_idx]]
        fwr = [x - fwmin for x in fw[fwmin_idx + 1:]]
        return garden(fwl) + fwmin + garden(fwr)

N = int(input())
h = [int(x) for x in input().split()]
print(garden(h))

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

def watering(num_list):
    num_list_ = []
    l_ = [str(l-1) for l in map(int, num_list)]
    num_list_.extend(list_split(l_, '0'))

    return num_list_

def list_split(num_list, s):
    list_ = [n if n != s else 'x' for n in num_list]
    return [_.split() for _ in ' '.join(list_).split('x')  if _ is not '' and _ is not ' ']

h_ = list_split(h, '0') 

i = 0
while(1):
    if len(h_) == 0:
        break
    else:
        new_h = []
        for _ in h_:
            new_h.extend(watering(_))
            i += 1
        h_ = new_h
            
print(i)

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

def watering(num_list):
    num_list_ = []
    l_ = [str(l-1) for l in map(int, num_list)]
    num_list_.extend(list_split(l_, '0'))

    return num_list_

def list_split(num_list, s):
    if '0' not in num_list:
        return [num_list]
    else:
        new_list = []
        
        n0 = num_list[:num_list.index(s)]
        n1 = num_list[num_list.index(s)+1:]
        
        for _ in [n0, n1]:
            if _ == []:
                continue
            else:
                new_list.extend(list_split(_, '0'))

        return new_list    

h_ = list_split(h, '0') 

i = 0
while(1):
    if len(h_) == 0:
        break
    else:
        new_h = []
        for _ in h_:
            new_h.extend(watering(_))
            i += 1
        h_ = new_h
            
print(i)

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

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

count = a[0]

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

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

def f(H):
    if len(H) <= 1:
        return sum(H)
    v = min(H)
    i = H.index(v)
    X = [h - v for h in H]
    return f(X[:i]) + v + f(X[i+1:])

print(f(H))

Solution (Python):
import numpy as np

N = int(input())
h_list = np.array(list(map(int, input().split())))
count = 0

def count_mountain(h_list):
    pre = -1000
    count = 0
    for h in h_list:
        if pre <= 0 and h > 0:
            count += 1
        pre = h
    return count


for i in range(np.max(h_list)):
    count += count_mountain(h_list)
    h_list -= 1

print(count)

Solution (Python):
n= int(input())
h = [int(i) for i in input().split()]
import numpy as np
h = np.array(h)
zero = np.array([int(0) for i in range(len(h))])

def calc(h, zero, minus):
    for k in range(len(h)):
        if minus[k] != 0:
            if k == len(h) - 1:
                zero[k] = zero[k] + 1
                return
            for w in range(k+1, len(h)):
                if minus[w] == 0:
                    zero[k:w] = zero[k:w] + 1
                    return
                elif w == len(h) - 1:
                    zero[k::] = zero[k::] + 1
                    return

def main(h, zero):
    for i in range(1, 1000001):
        minus = h - zero
        if np.sum(minus) == 0:
            print(i-1)
            return
        calc(h ,zero, minus)
main(h, zero)

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

for i in range(N):
  if h[i] > prev:
    ans += h[i] - prev
  prev = h[i]
print(ans)

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

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

print(c)

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

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

print(sum(h))

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

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

print(s)

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

while(sum(h) != 0):
  l = -1
  r = -1
  min_h = 0
  
  
  
  for i in range(h_len):
    if h[i] > 0:
      l = i
      break
  if l == -1:
    
    break
  
  
  for j in range(l,h_len):
    if h[j] > 0:
      r = j+1
      
    else:
      break
  if r == -1:
    
    break
  
  
  min_h = min(h[l:r])
  h[l:r] = [h[k] - min_h for k in range(l,r)]
  count += min_h

print(count)

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

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

ans = 0
while True:
    l,r = 0,0

    for i in range(len(h)):
        if h[i] != 0:
            l = i
            break

    if h.count(0) == len(h):
        break

    for i in range(l+1,len(h)):
        if h[i] == 0:
            r = i
            break
        if i + 1 == len(h):
            r = i+1

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



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

    if l == r:
        h[l] -= 1

    ans += 1


print(ans)

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

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

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

ans = 0

while True:
    if not any(h):
        break
    flag = False
    for i, e in enumerate(h):
        if e != 0:
            flag = True
            h[i] -= 1
            if i == len(h) - 1:
                ans += 1
        else:
            if flag == True:
                ans += 1
                flag = False
    
print(ans)

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

Solution (Python):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
h = list(li())
h.append(0)


haveleft = False
ans = 0

while any([hk > 0 for hk in h]):
    for k in range(len(h)):
        if not haveleft:
            if h[k] == 0:
                continue
            else:
                haveleft = True
                h[k] -= 1
                
        else:
            if h[k] == 0:
                ans += 1
                haveleft = False
            else:
                h[k] -= 1
            
print(ans)

Solution (Python):


import numpy as np
N = int(input())
L = np.array(list(map(int, input().split())))

cnt = 0
while np.any(L > 0):
    for i in range(N):
        if L[i] > 0:
            start = i
            end = i + 1
            for j in range(start+1, N):
                end = j
                if not L[j] > 0:
                    break
                end += 1
            break
        
    
    cnt += L[start:end].min()
    L[start:end] -= L[start:end].min()

print(cnt)

Solution (Python):
from  numpy  import *

N=int(input())
a=list(map(int,input().split(" ")))
s=0
while True :
  curr=""
  pos=0
  for index,item in enumerate(a):  
    if item==0:
      curr+='-'
    else:
      pos+=1
      curr+=str(item)
      a[index]=item-1
  if pos==0:
    break
  s+=count_nonzero([len(x) for x in curr.split("-")])
  
print(s)

Solution (Python):
from functools import reduce

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

prev = 0
count = 0

for i in range(N):
    count += h[i] - prev if h[i] > prev else 0
    prev = h[i]

print(count)

Solution (Python):
n = int(input())
li = list(map(int,input().split())) + [0]
counter = 0
while (max(li) > 0):
  for r in range(len(li)):
    if li[r] > 0:
      break
  
  for l in range(r, len(li)):
    if li[l] == 0:
      break

  li = [li[i]-1 if i >= r and i < l else li[i] for i in range(len(li))]

  counter += 1

print(counter)

Solution (Python):
def run(N, h):
    start_flg = False
    ret = 0
    for i in range(max(h)):
        start_flg = False
        for j in range(N):
            if h[j] > 0:
                h[j] -= 1
                if not start_flg:
                    start_flg = True
                    ret += 1
            else:
                start_flg = False
    return ret


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


if __name__ == '__main__':
    main()

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

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

ans = 0
for i in range(N):
  dec = A[i]
  ans += dec
  for j in range(i+1,N):
    if A[j] == 0:
      break
    dec = min(dec, A[j])
    A[j] -= dec
  
print(ans)

Solution (Python):
N = int(input())
h = list(map(int, input().split()))
answer = 0
while sum(h):
    min = 1000
    sta = 0
    for i, hi in enumerate(h):
        if hi != 0:
            if hi < min:
                min = hi
            if i == N-1:
                if sta <= i:
                    for j in range(sta, i+1):
                        h[j] -= min
                    answer += min
        else:
            if sta < i:
                for j in range(sta, i):
                    h[j] -= min
                answer += min
                min = 1000
            sta = i+1
print(answer)

Solution (Python):
def solve(h):
    n = len(h)
    res = 0
    for y in range(1, max(h)+1):
        x = 0
        while x < n:
            if (h[x] >= y):
                res += 1
                while (x < n) and (h[x] >= y):
                    x += 1
            x += 1
    return res

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

Solution (Python):
import numpy as np

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

count = 0
def recur(array):
    global count
    if len(array) == 0 :
        pass
    else:
        count += min(array)
        array = array - min(array)
        for i in range(len(array)):
            if array[i] == 0:
                array_1 = array[:i]
                array_2 = array[i+1:]
                break
        recur(array_1)
        recur(array_2)
    return count

print(recur(array))

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


def solver(array):
    cnt = 0
    if array == [0] or not array:
        return 0
    while True:
        aarray = []

        for num in array:
            if num != 0:
                aarray.append(num)
            else:
                cnt += solver(aarray)
                aarray = []
        else:
            if aarray:
                cnt += 1
                cnt += solver([max(0, x-1) for x in aarray])
            break

    return cnt

print(solver(h_array))

Solution (Python):
n = int(input())
h_array = [0]+[int(x) for x in input().split()]
hh_array = []
res = 0
tmp = 0
for i, j in enumerate(h_array[:-1]):
    if h_array[i] < h_array[i + 1]:
        hh_array.append(h_array[i+1] - h_array[i])
    else:
        hh_array.append(0)

print(sum(hh_array))

Solution (Python):
ans = 0


def dfs(h):
    global ans

    if len(h) == 0:
        return None

    mi = min(h)
    ans += mi
    h = list(map(lambda i: i - mi, h))

    while True:
        r = h.index(0)
        dfs(h[:r])
        h = h[r+1:]
        if 0 not in h:
            dfs(h)
            break


if __name__ == "__main__":
    N = int(input())
    H = [int(i) for i in input().split()]
    dfs(H)
    print(ans)

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

print(ans)

Solution (Python):
from itertools import groupby

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

l = H
count = 0
for i in range(max(H), 0, -1):
    count += sum(key for key, _ in groupby(l, key=lambda x: x==i))
    l = [l_i-1 if l_i == i else l_i for l_i in l]
    

print(count)

Solution (Python):
input()
def gg(a):
	if len(a)==0:
		return 0
	m=0
	s = min(a)
	for i in range(len(a)):
		a[i] -= s
		if a[i] == 0:
			m=i
	return s + gg(a[:m]) + gg(a[m+1:])
print(gg(list(map(int,input().split()))))

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


n = input()
h2 = list(map(int, input().split()))
j2 = -2
count2 = 0


def maax(count, j, h):
    if max(h) == 0:
        print(count)
        return
    k = max(h)
    
    for i in range(len(h)):
        if h[i] == k:
            if j+1 != i:
                count = count+1
    
            j = i
            h[i] = k-1
            maax(count, j, h)
    

maax(count2, j2, h2)

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

count = li[0]

for k in range(len(li)- 1):
    if li[k] < li[k + 1]:
        count += li[k + 1] - li[k]
print(count)

Solution (Python):
N=int(input())
b=input()
arr=[int(n) for n in b.split()]
ans=0
for i in range(N):
  while(arr[i]):
    ans+=1
    for j in range(i,N):
      if not arr[j]:
        break
      arr[j]-=1
print(ans)

Solution (Python):
N = int(input())
h = [int(s) for s in input().split()]
ans = 0
for i in range(N):
    while h[i]:
        ans += 1
        j = i
        for j in range(i, N):
            if not h[j]:
                break
            h[j] -= 1
print(ans)

Solution (Python):
import numpy as np

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

def water_and_split(h_list):
    if h_list.shape[0] <= 2:
        counter = max(h_list)
    else:
        if np.argmin(h_list) == 0:
            counter = min(h_list)
            counter += water_and_split(h_list[1:]-min(h_list))
        elif np.argmin(h_list) == h_list.shape[0]-1:
            counter = min(h_list)
            counter += water_and_split(h_list[:-1]-min(h_list))
        else:
            counter = min(h_list)
            min_idx = np.argmin(h_list)
            counter += water_and_split(h_list[:min_idx]-min(h_list)) + water_and_split(h_list[min_idx+1:]-min(h_list))
    return counter

count = water_and_split(h_list)
print(count)

Solution (Python):

"""
Created on Sun Jan 20 11:25:20 2019
ABC116C
@author: maezawa
"""

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

h.append(0)
cnt = 0
finished = False
while True:
    
    i = 0
    while True:
        if not h:
            break
        elif h[i] == 0:
            h.pop(0)
        else:
            break
    if not h:
        break
    l = 0
    r = 0
    minh = 101
    while True:
        if h[r] == 0 and r != l and minh != 0:
            for i in range(l,r):
                h[i] -= minh
            cnt += minh
            
            l = r+1
            if l > len(h):
                break
        elif h[r] < minh:
            minh = h[r]
        r += 1
        if r >= len(h):
            break
    if not h:
        break

print(cnt)

Solution (Python):
def find_zeros(a):
    res = []
    for i in range(len(a)):
        if a[i] == 0:
            res.append(i)
    return res


def solve():
    N = input()
    h = [int(n) for n in input().split()]

    cnt = 0
    while sum(h) != 0:
        idx_zeros = find_zeros(h)
        idx_zeros = [-1] + idx_zeros + [len(h)]
        for l, r in zip(idx_zeros[:-1], idx_zeros[1:]):
            for i in range(l+1,r):
                h[i] -= 1
            if l+1<r:
                cnt += 1
    return cnt 


def main():
    ans = solve()
    print(ans)


if __name__ == '__main__':
    main()

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

Solution (Python):
def f(l):
    sta = True
    for i,j in enumerate(l):
        if sta:
            if j!=0:
                sta=False
                l[i]-=1
        else:
            if j==0:
                break
            else:
                l[i]-=1
    return l



N =int(input())
h =[int(i) for i in input().split()]
m = 0
while h != [0]*N:
    h =f(h)
    m += 1
print(m)

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

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

def parse(inp):
    N=int(next(inp))
    H=np.array(next(inp).split(),dtype=int)
    return H
  
def split(H):
    Splited=np.array([],dtype=int)
    SplitPoint=[]
    for i in range(len(H)):
        if(H[i]==0):
            SplitPoint.append(i)
    
    if(SplitPoint==[]):
        Splited=np.array([H])
        return Splited
            
    Splited=np.split(H,SplitPoint)
    
            
    
    for i in range(len(Splited)):
        if(Splited[i].size==0):
             continue
        elif(Splited[i][0]==0):
            Splited[i]=np.delete(Splited[i],[0])
    
    return Splited
                
def main(H):
    H=collections.deque(H)


    answer=0
    
    while H:
        Hnow=H.popleft()
        if(Hnow.size==0):
            continue

        Hnowmin=Hnow.min()
        answer+=Hnowmin
        for i in range(len(Hnow)):
            Hnow[i]=Hnow[i]-Hnowmin

        for i in range(len(split(Hnow))):
            if(split(Hnow)[i].size!=0):

                H.append(split(Hnow)[i])

    return answer

print(main(split(parse(sys.stdin))))

Solution (Python):
i=input;i();s=p=0
for x in map(int,i().split()):s+=max(x-p,0);p=x
print(s)

Solution (Python):
N=int(input())
a=list(input().split())
a=[int(S) for S in a]
mini=min(a)
count=0

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

count+=a[0]
print(count)

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

count = 0
for _ in range(100):
    flag = 1
    for i in range(n):
        if H[i] > 0:
            H[i] -= 1
            if flag:
                count += 1
                flag = 0
        else:
            flag = 1
            
print(count)

Solution (Python):
n = int(input())
h_list = [int(_) for _ in input().split()]
ans = 0
while sum(h_list) != 0:
    
    
    if h_list.count(0) == 0:
        ans += 1
    else:
        for i in range(1, n):
            
            if h_list[i] == 0 and h_list[i - 1] != 0:
                ans += 1
            elif i == n - 1 and h_list[i] != 0:
                ans += 1
    
    for i in range(n):
        if h_list[i] != 0:
            h_list[i] -= 1

print(ans)