output_description: Print the minimum possible number of subarrays after division of A.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      A_1 A_2 ... A_N
attempt: #!/usr/bin/env python3
  # -*- coding: utf-8 -*-
  
  from random import *
  from functools import reduce, partial
  
  
  def readline():
      return list(map(int, input().split(" ")))
  
  
  def identity(x):
      """Return the input itself."""
      return x
  
  
  def constant(c):
      """Return an function which always
      returns the input constant c."""
  
      def const_function(const, *args):
          return const
  
      return partial(const_function, c)
  
  
  def inc(c=1):
      """Return a function which reads an input x and returns x + c as output.
      By default, c equals 1."""
      return lambda x: x + c
  
  
  def add(*args):
      """Return the sum of the input."""
  
      def add2(x, y):
          return x + y
  
      return reduce(add2, args)
  
  
  def mapv(f, *lst):
      """Return a vector of the result of map."""
      return list(map(f, *lst))
  
  
  def vector(*args):
      """Return a vector of input parameters."""
      return args
  
  
  def sequence(n, f=constant(0)):
      """Return a vector of length n, and initialize the i'th
      item with f(i).By default the vector will initialized with 0."""
      return [f(i) for i in range(0, n)]
  
  
  def matrix(n, m, f=constant(0)):
      """Return a 2-dim vector which contains n vectors with length m.
      The j's item of vector i will be initialized by f(i,j).By default,
      the vector will be initialized with 0."""
      return [[f(i, j) for j in range(0, m)] for i in range(0, n)]
  
  
  def flat(v):
      """Return a flat vector which contains the elements of v in their
      origin order.If the input is not a vector, return a vector which
      only contains the input."""
      if not isinstance(v, list):
          return [v]
      if not v:
          return []
      return reduce(add, mapv(flat, v))
  
  
  def partition(v, f=identity):
      """Partition vector v by f(v[i]).
      e.g. partition([1,2,3,1,2,3],identity()) == {1:[1,1,1], 2:[2,2], 3:[3]}
      By default, the vector will be partitioned by identity function."""
      result = {}
      for item in v:
          key = f(item)
          s = result.get(key)
          if s:
              s.append(item)
          else:
              result.update({key: [item]})
      return result
  
  
  def getValue(key):
      """Return a function which returns the value of key in a hash-map.
      If the key do not exist, it will throw an error."""
      return lambda x: x[key]
  
  
  def mapValue(f, m):
      """Replace each value in hash-map m with f(value).
      Return the new hash-map."""
      res = {}
      for key in m:
          res.update({key: f(m[key])})
      return res
  
  
  n = int(input())
  a = readline()
  f = sequence(n)
  g = sequence(n)
  f[0], g[0] = 1, 1
  for i in range(1, n):
      f[i] = min(f[i - 1], g[i - 1] + 1)
      g[i] = min(g[i - 1], f[i - 1] + 1)
      if a[i] > a[i - 1]:
          g[i] = min(f[i - 1] + 1, g[i - 1] + 1)
      if a[i] < a[i - 1]:
          f[i] = min(f[i - 1] + 1, g[i - 1] + 1)
  print(min(f[n - 1], g[n - 1]))
  
problem_description: Statement
  
  You are given an array A of length N. Your task is to divide it into several
  contiguous subarrays. Here, all subarrays obtained must be sorted in either
  non-decreasing or non-increasing order. At least how many subarrays do you
  need to divide A into?
samples: [{"input": "6\n    1 2 3 2 2 1", "output": "2\n    \n\nOne optimal solution is to divide the array into [1,2,3] and [2,2,1].\n\n* * *"}, {"input": "9\n    1 2 1 2 1 2 1 2 1", "output": "5\n    \n\n* * *"}, {"input": "7\n    1 2 3 2 1 999999999 1000000000", "output": "3"}]