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
  
  N = int(input())
  p = [int(input()) for i in range(N)]
  
  s = list(range(1, N + 1))
  
  i = 1
  while i < N:
      x = p.index(i)
  
      # print(x)
  
      if i == x + 1:
          i += 1
          continue
      elif x < i - 1:
          break
  
      if (x - i + 1) % 2 != 0:
  
          break
  
      # print(s,i,x)
  
      for j in range(i - 1, x, 2):
          s[j], s[j + 2] = s[j + 2], s[j]
          i = x + 2
      # print(s,i)
  
  if s == p:
      print("Yes")
      sys.exit()
  
  # print(s)
  
  s = list(range(1, N + 1))
  i = N
  while i > 0:
      x = p.index(i)
      if i == x + 1:
          i -= 1
          continue
      elif x > i - 1:
          break
  
      if (x - i - 1) % 2 != 0:
  
          break
  
      # print(s,i,x)
  
      for j in range(i - 1, x, -2):
          s[j], s[j - 2] = s[j - 2], s[j]
          i = x
      # print(s,i)
  
  if s == p:
      print("Yes")
      sys.exit()
  
  else:
      print("No")
  
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"}]