output_description: Print the minimum number of watering operations required to satisfy the
  condition.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      h_1 h_2 h_3 ...... h_N
attempt: from itertools import zip_longest
  from collections import deque
  
  N = int(input())
  heights = tuple(map(int, input().split(" ")))
  heights = [
      h1 for h1, h2 in zip_longest(heights, heights[1:], fillvalue=None) if h1 != h2
  ]
  
  if len(heights) <= 2:
      print(max(heights))
  else:
      tops = deque()
      bottoms = deque()
  
      if heights[0] > heights[1]:
          tops.append(heights[0])
  
      for i in range(1, len(heights) - 1):
          if heights[i - 1] < heights[i] and heights[i] > heights[i + 1]:
              tops.append(heights[i])
          elif heights[i - 1] > heights[i] and heights[i] < heights[i + 1]:
              bottoms.append(heights[i])
  
      if heights[-1] > heights[-2]:
          tops.append(heights[-1])
  
      if len(bottoms) == 0:
          print(tops[0])
      else:
          bottoms.appendleft(bottoms[0])
          bottoms.append(bottoms[-1])
  
          cost = min(bottoms)
          for index, top in enumerate(tops):
              left = bottoms[index]
              right = bottoms[index + 1]
              cost += top - min(left, right)
  
          print(cost)
  
problem_description: 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.
samples: [{"input": "4\n    1 2 2 1", "output": "2\n    \n\nThe minimum number of watering operations required is 2. One way to achieve it\nis:\n\n  * Perform the operation with (l,r)=(1,3).\n  * Perform the operation with (l,r)=(2,4).\n\n* * *"}, {"input": "5\n    3 1 2 3 1", "output": "5\n    \n\n* * *"}, {"input": "8\n    4 23 75 0 23 96 50 100", "output": "221"}]