#ARC161A. [ARC161A] Make M

[ARC161A] Make M

Score : 300300 points

Problem Statement

Let NN be a positive odd number. A sequence of integers of length NN, S=(S1,S2,,SN)S = (S_1, S_2, \dots, S_N), is said to be M-type if "for each even number i=2,4,,N1i = 2, 4, \dots, N - 1, it holds that Si1<SiS_{i-1} < S_i and Si>Si+1S_i > S_{i+1}".

You are given a sequence of positive integers of length NN, A=(A1,A2,,AN)A = (A_1, A_2, \dots, A_N). Determine if it is possible to rearrange AA to be M-type.

Constraints

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • NN is an odd number.
  • 1Ai109  (1iN)1 \leq A_i \leq 10^9 \ \ (1 \leq i \leq N)

Input

The input is given from Standard Input in the following format:

NN

A1 A2  ANA_1 \ A_2 \ \dots \ A_N

Output

If it is possible to rearrange the given integer sequence AA to be M-type, print Yes; otherwise, print No.

5
1 2 3 4 5
Yes

The given sequence is A=(1,2,3,4,5)A = (1, 2, 3, 4, 5). After rearranging it, for example, to B=(4,5,1,3,2)B = (4, 5, 1, 3, 2),

  • for i=2i = 2, it holds that B1=4<5=B2B_1 = 4 < 5 = B_2 and B2=5>1=B3B_2 = 5 > 1 = B_3;
  • for i=4i = 4, it holds that B3=1<3=B4B_3 = 1 < 3 = B_4 and B4=3>2=B5B_4 = 3 > 2 = B_5.

Therefore, this sequence BB is M-type, and the answer is Yes.

5
1 6 1 6 1
Yes

The given sequence AA itself is M-type.

5
1 6 6 6 1
No

It is impossible to rearrange it to be M-type.