Penultimate Processing
We had a line of nicely sorted numbers on the table, but Shahid accidentally knocked them over and now they are randomly spread on the floor. Many of these numbers were repeated, and we need you to find the number of duplicates of the second greatest number among them. Help Shahid out!
Input
The first line is a number , detailing the amount of numbers that were dropped.
The next line contains space-separated integers
, possibly containing duplicates. There will always be at least two distinct integers among them (i.e., there will always be a second-greatest number).
Output
Output the frequency of the second-greatest number among all those spilt.
Example
Input 1
11
1 5 2 7 2 1 9 7 3 7 9
Output 1
3
The greatest number is 9, and the second greatest is 7. There are 3 occurrences of 7 in the pile, so that's what we output.
Input 2
5
1 9 1 9 9
Output 2
2
There will always be an output as there are at least 2 distinct integers in the input. In this case, 9 is the greatest and 1 is the second greatest, which shows up twice.
Comments