시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
2 초 512 MB 8 5 5 62.500%

문제

You are gathering readings of acidity level in a very long river in order to determine the health of the river. You have placed N sensors (2 ≤ N ≤ 2 000 000) in the river, and each sensor gives an integer reading R (1 ≤ R ≤ 1 000). For the purposes of your research, you would like to know the frequency of each reading, and find the absolute difference between the two most frequent readings.

If there are more than two readings that have the highest frequency, the difference computed should be the largest such absolute difference between two readings with this frequency. If there is only one reading with the largest frequency, but more than one reading with the second largest frequency, the difference computed should be the largest absolute difference between the most frequently occurring reading and any of the readings which occur with second-highest frequency

입력

The first line of input will be the integer N (2 ≤ N ≤ 2 000 000), the number of sensors. The next N lines each contain the reading for that sensor, which is an integer R (1 ≤ R ≤ 1 000). You should assume that there are at least two different readings in the input.

출력

Output the positive integer value representing the absolute difference between the two most frequently occurring readings, subject to the tie-breaking rules outlined above.

예제 입력 1

5
1
1
1
4
3

예제 출력 1

3

예제 입력 2

4
10
6
1
8

예제 출력 2

9