Question
Joy Surge

Alice holds an array B of M integers Bi (1 ≤ i ≤ M). In one move, he can swap any two elements. Determine the maximum joy of the array after any number of swaps, where joy is the count of indices j (1 ≤ j < M) such that Bj+1 > Bj.

Input
The first line of the input contains a single integer M, the size of the array.
The second line of the input contains M space-separated integers B1, B2,. , BN.

Constraints
1 ≤ M ≤ 105
1 ≤ Bi ≤ 109
Output
Print the maximum possible joy of array B.
Example
Sample Input
5
9 4 5 8 2
Sample Output
4
Explanation
Swap B1 and B5
The array becomes: [2, 4, 5, 8, 9]
Now, the indices 1, 2, 3 and 4 of the array contribute to its jolly value as their next integer is strictly greater.

Online