Repovive
  • Dashboard
  • Ranking
  • Submissions
  • Discussion
  1. Contests
  2. Starter Round 8Rated: < 1700
  3. 23D
Sponsor
Abhishek Choudhary

My submissions

/
/
/
/

Announcements

My submissions

/
/
/
/

Announcements

Solve
Author

23D. Two-Way Vote Count

2000 pts·1s·256 MB

Constraints

Input

Output

Samples

Input
9
1 1 1 1 1 2 2 3 3
Explanation
Output
Yes
Input
4
1 1 1 2
Explanation
Output
No
Input
1
1
Explanation
Output
Yes

There are nnn votes, represented by the array a1,a2,…,ana_1, a_2, \ldots, a_na1​,a2​,…,an​. Vote iii is for candidate aia_iai​.

You may rearrange the votes in any order. Determine whether there is an arrangement satisfying the following condition:

Whether the votes are counted from left to right or from right to left, after each vote is counted, exactly one candidate has strictly more counted votes than every other candidate.

The two counts are independent: all candidates start with zero counted votes in each direction.

  • 1≤n≤2×1051 \le n \le 2 \times 10^51≤n≤2×105
  • 1≤ai≤n1 \le a_i \le n1≤ai​≤n for all 1≤i≤n1 \le i \le n1≤i≤n.
  • All input values are integers.
na1a2…an\begin{array}{l} n \\ a_1 \quad a_2 \quad \ldots \quad a_n \end{array}na1​a2​…an​​

The first line contains the number of votes nnn.

The second line contains the votes a1,a2,…,ana_1, a_2, \ldots, a_na1​,a2​,…,an​.

Yes / No\text{Yes / No}Yes / No

Print Yes if a valid arrangement exists, and No otherwise.

You may print the answer in any combination of uppercase and lowercase letters. For example, Yes, YES, and YeS are all accepted.

One valid arrangement is [1,1,2,3,1,2,3,1,1][1,1,2,3,1,2,3,1,1][1,1,2,3,1,2,3,1,1].

From left to right, candidate 111 has strictly more counted votes than every other candidate after each vote. The same is true from right to left.

Any valid arrangement must begin and end with a vote for candidate 111; otherwise, candidate 222 would lead initially but would not lead after all votes are counted.

The vote for candidate 222 would then be in one of the two middle positions. Counting from the closer end, the first two votes would give one vote to each candidate, causing a tie.

The only vote is for candidate 111. After counting it from either direction, candidate 111 is the unique leader.