407310: GYM102759 H Alchemy

Memory Limit:1024 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

H. Alchemytime limit per test1 secondmemory limit per test1024 megabytesinputstandard inputoutputstandard output

Jeyeon the alchemist has obtained the philosopher's stone which can transform one or more materials into a single material of a different type. Now he is trying to obtain the most valuable material in the universe. Every material in the world has a value corresponding to some nonnegative integer, and two materials are different in type if and only if they differ in value.

The philosopher's stone can consume $$$k$$$ ($$$k \geq 1$$$) materials, the $$$i$$$th having value $$$x_i$$$, and generates a material that was not among the consumed values. Over all such materials, the philosopher's stone will generate the material with minimum value, also known as the mex of the original values. It is allowed to consume multiple materials of the same value.

Jeyeon starts out with some elements with values varying from $$$0$$$ to $$$N-1$$$. Specifically, he has $$$c_i$$$ materials with value $$$i$$$. He will use the philosopher's stone zero or more times. In the end, Jeyeon wants to own exactly one material. Jeyeon wants to maximize the value of this single material. Can you calculate this value for him? Note that the value of this material may be greater than or equal to $$$N$$$.

Input

The first line contains the single integer $$$N$$$. ($$$1 \le N \le 100\,000$$$)

The next line contains $$$N$$$ space-separated integers $$$c_0, c_1, \cdots, c_{N-1}$$$. ($$$0 \le c_{i} \le 10^{9}$$$, $$$c_{0} + c_{1} + \cdots + c_{N-1} \ge 1$$$)

Output

Print the maximum possible value of the single remaining material.

ExamplesInput
1
1
Output
1
Input
2
0 1
Output
1
Input
6
1 0 0 0 0 1
Output
2
Input
5
0 0 0 0 1
Output
4
Input
5
1 0 1 0 1
Output
3

加入题单

算法标签: