output_description: If the state where p_i=i for every i can be reached by performing the
  operation, print `Yes`; otherwise, print `No`.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      p_1
      :
      p_N
attempt: import sys
  
  read = sys.stdin.buffer.read
  readline = sys.stdin.buffer.readline
  readlines = sys.stdin.buffer.readlines
  
  N = int(readline())
  P = [0] + list(map(int, read().split()))
  
  # permutationになっている極小区間に分ける
  
  intervals = []
  left = 0
  right = -1
  for i, p in enumerate(P):
      if right < p:
          right = p
      if i == right:
          intervals.append((left, right))
          left = i + 1
          right = -1
  
  
  def check(L, R):
      if L == R:
          return True
      to_left = []
      fixed = []
      to_right = []
      for i, p in enumerate(P[L : R + 1], L):
          if i > p:
              to_left.append(p)
          elif i == p:
              fixed.append(p)
          else:
              to_right.append(p)
  
      if fixed != list(range(L + 1, R + 1, 2)):
          return False
      if any(x > y for x, y in zip(to_left, to_left[1:])):
          return False
      if any(x > y for x, y in zip(to_right, to_right[1:])):
          return False
      return True
  
  
  answer = "Yes" if all(check(L, R) for L, R in intervals) else "No"
  print(answer)
  
problem_description: Statement
  
  You are given a permutation of 1,2,...,N: p_1,p_2,...,p_N. Determine if the
  state where p_i=i for every i can be reached by performing the following
  operation any number of times:
  
    * Choose three elements p_{i-1},p_{i},p_{i+1} (2\leq i\leq N-1) such that p_{i-1}>p_{i}>p_{i+1} and reverse the order of these three.
samples: [{"input": "5\n    5\n    2\n    1\n    4\n    3", "output": "Yes\n    \n\nThe state where p_i=i for every i can be reached as follows:\n\n  * Reverse the order of p_1,p_2,p_3. The sequence p becomes 1,2,5,4,3.\n  * Reverse the order of p_3,p_4,p_5. The sequence p becomes 1,2,3,4,5.\n\n* * *"}, {"input": "4\n    3\n    2\n    4\n    1", "output": "No\n    \n\n* * *"}, {"input": "7\n    3\n    2\n    1\n    6\n    5\n    4\n    7", "output": "Yes\n    \n\n* * *"}, {"input": "6\n    5\n    3\n    4\n    1\n    2\n    6", "output": "No"}]