Problem:
Score : 1200 points

Problem 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.

Constraints

3 \leq N \leq 3 × 10^5

p_1,p_2,...,p_N is a permutation of 1,2,...,N.

Input

Input is given from Standard Input in the following format:

N
p_1
:
p_N

Output

If the state where p_i=i for every i can be reached by performing the operation, print Yes; otherwise, print No.

Sample Input 1

5
5
2
1
4
3

Sample Output 1

Yes

The state where p_i=i for every i can be reached as follows:

Reverse the order of p_1,p_2,p_3. The sequence p becomes 1,2,5,4,3.

Reverse the order of p_3,p_4,p_5. The sequence p becomes 1,2,3,4,5.

Sample Input 2

4
3
2
4
1

Sample Output 2

No

Sample Input 3

7
3
2
1
6
5
4
7

Sample Output 3

Yes

Sample Input 4

6
5
3
4
1
2
6

Sample Output 4

No

Solution in Ruby (2.3.3) (judge verdict: Wrong Answer)

require 'pp'
# IS_DEBUG = true
IS_DEBUG = false
def dputs str
	if(IS_DEBUG)
		puts str
	end
end
def dpp str
	if(IS_DEBUG)
		pp str
	end
end

require 'pp'

N,_=gets.chomp.split(' ').map{|n| n.to_i}
A = Array.new(N)
0.upto(N-1){|d|
	A[d],_=gets.chomp.split(' ').map{|n| n.to_i}
}

mode = :NONE
start_i = nil
start_v_final = nil
start_v = nil
for i in 0..(N-1)
	v = A[i]
	v_final = i+1
	dputs "searching A[#{i}], #{A[i]}"
	case mode
	when :NONE
		dputs "NONE"
		if(v==v_final)
			next
		elsif(v==v_final+2)
			mode = :LEFT	# 3 5 7 9 1
			start_i = i
			start_v_final = v_final
			next
		elsif((v-v_final)%2==0)
			mode = :RIGHT	# 9 1 3 5 7
			start_i = i
			start_v = v
			next
		else
			puts "No"
			exit(0)
		end
	else
		dputs "mode = #{mode}"
		if((i-start_i) % 2 != 0)
			if(v==v_final)
				dputs "pivot ok"
				next
			else
				dputs "pivot NG"
				puts "No"
				exit(0)
			end
		else
			case mode
			when :LEFT
				if(v==v_final+2)
					dputs "LEFT ascendings ok"
					next
				elsif(v==start_v_final)
					dputs "LEFT terminate ok"
					# terminate
					mode = :NONE
				else
					puts "No"
					exit(0)
				end
			when  :RIGHT
				if(v==v_final-2)
					dputs "RIGHT ascendings ok"
					next
				elsif(start_v==v_final)
					dputs "RIGHT terminate ok"
					# terminate
					mode = :NONE
					next
				else
					puts "No"
					exit(0)
				end
			end
		end
	end
end
puts "Yes"