#P10177. 似巨龙高歌

似巨龙高歌

Background

Thanks to whk, a top-tier expert, and Fan Ju (bx).

Although Fanfan is very strong in academic subjects, during the New Year he does not want to put too much pressure on other students of the same age, so he plans to tamper with his exam results over the year.

Problem Description

Looking at his grades soaring like a giant dragon, when the New Year arrives, Fanfan cannot help but sing Love You.

This year he has a total of nn exams, and in the ii-th exam his rank is aia_i.

This creates pressure for other classmates, so he wants to reorder his nn ranks so that the exam with the largest improvement has the smallest possible improvement in rank, so that he can hide his true strength.

For the ii-th and the (i+1)(i+1)-th exams (1i<n1\le i < n), his improvement in rank is aiai+1a_i-a_{i+1}. If this value is negative, it means he got worse.

Please help him.

Input Format

There are two lines of input.

The first line contains an integer nn.

The second line contains nn integers, separated by spaces. The ii-th integer is aia_i.

Output Format

Output one line containing one integer, which is the answer.

2
1 1
0
4
2 4 1 3
-1

Hint

Sample 1 Explanation

If Fanfan does not change the original exam sequence, then from the first to the second exam he improves by 00 places (the rank does not change).

Sample 2 Explanation

Fanfan can reorder his exam ranks as 1,2,3,41,2,3,4. Then for every exam he improves by 1-1, so the answer is 1-1.

This problem uses bundled testdata.

Constraints

  • For 30%30\% of the testdata, n10n\le 10 is guaranteed.

  • For 50%50\% of the testdata, n5000n\le 5000 is guaranteed.

  • For the remaining 20%20\% of the testdata, ai2a_i\le 2 is guaranteed.

  • For 100%100\% of the testdata, 2n1062\le n\le 10^6 and 1ai1091\le a_i\le 10^9 are guaranteed.

Translated by ChatGPT 5