cswork / OAOpen practice workspace

AmazonOA #202

Get Max Increments

Estimated MediumJudge-ready

Topics (AI-labelled)HashingGreedy

Rearrange all the integers in any order to maximize the number of adjacent positions with a[i]<a[i+1]. This is not the longest increasing subsequence.

Input

The first line contains n; the second line contains the scores. 2≤n≤200000, 1≤score≤200000.

Output

Output a single integer, the answer.

Example 1

Input:

3
2 1 3

Output:

2

Example 2

Input:

4
2 1 1 2

Output:

2

Example 3

Input:

2
5 5

Output:

0

Example notes

The answers are 2, 2 and 0; in the second example the arrangement 1,2,1,2 rises at positions 0 and 2, and the source's 0 and 1 is wrong.

Editorial

Loading solution…