Hide

Problem G
The Seventh Dragon Ball

/problems/seventhdragonball/file/statement/en/img-0001.png
Source: Pixabay

In an alternate Dragon Ball universe, Earth has been destroyed. Luckily, you are among a group of survivors who made it out to a new planet with six dragon balls and a mysterious machine sealing the seventh dragon ball. If you unlock enough levels of the machine, you will have all seven dragon balls needed to summon Shenron and wish for Earth back!

From your observation and reading the machine manual, you deducted that:

  • The machine operates on the concept of “Ki” (energy). Each level requires a specific amount of Ki to unlock, starting from $1$ Ki for the first level, and each subsequent level requires $1$ unit of Ki more than the previous one. Levels must be unlocked one by one.

  • To unlock a level, the sum of Ki transferred by the survivors must exactly match the required Ki for that level.

  • The machine immediately absorbs all the Ki from each person who attempts to transfer.

  • Once a person transfers their Ki to unlock a level, they cannot transfer again for that particular level due to slow Ki recovery. Luckily, each survivor regains all their Ki for subsequent levels.

  • You discovered a magic code to unlock a level without matching the exact Ki requirement. However, you may use this code only once, that is, for exactly one level.

Output the maximum number of levels you can unlock, including possibly using your magic code.

Input

The input consists of:

  • The first line with one integer $k$ ($1 \le k \le 1\, 000\, 000$) represents number of people on the new planet.

  • The following $k$ lines each contain an integer $k_ i$ ($1 \le k_ i \le 2\, 147\, 483\, 647$) representing number of Ki the $i^{\text {th}}$ person possesses.

Output

Output the maximum number of levels you can unlock.

Sample Output Explanation

In Sample Input 1, it is possible to unlock levels $1$ through $11$ by combining Ki and use the magic code on $12$. Thus, $12$ levels can be unlocked. In Sample Input 2, it is possible to unlock levels $1$ through $3$ by combining Ki, use the magic code on $4$, and unlock levels $5$ through $8$. Thus, $8$ levels can be unlocked in total.

Sample Input 1 Sample Output 1
4
1
2
3
5
12
Sample Input 2 Sample Output 2
3
2
1
5
8

Please log in to submit a solution to this problem

Log in