406175: GYM102299 K Poor Folk

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

K. Poor Folktime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Russian writers are known worldwide. One of the main Russian authors is Fyódor Dostoyévskiy. The influence of his works outgrew literature itself and reached other areas such as Philosophy, Psychology, and Theology. His first successful book was "Poor Folk", published in 1846.

This broad and impacting influence is due in part to the deep psychological description of his characters. However, some have criticized him for writing stories which are too long and even weary. Even though he is considered a great writer, Dostoyévskiy's life was not easy. In many occasions he had to write under pressure to make a living and perhaps his prolificacy came from such moments of needs.

Dostoyévskiy's only way to obtain money is by selling chapters of his books. Moreover, he knows the editor would buy each and every chapter he wrote — after all, he is a great writer. However, he wants more than just selling all the chapters he is writing. He noted that his financial woes are cause by his lack of financial discipline. That is why Dostoyévskiy decided that whenever he needs to pay his debts, he will choose some chapters to sell so that the money earned is exactly the amount owed. In this way, he will never have any savings and he will have no need to be disciplined about spending.

Of course he understands there could be some debts he will not be able to pay if he insists on this rule. Thus, knowing the value in rubles for each chapter he already wrote, one of the questions he raised was: what is the smallest debt that he would not be able to pay with previously written chapters? Your task is to answer this question.

Input

You should read an integer (n) in the first line, the number of chapters already written by Dostoyévskiy. The second line has (n) integers, $$$p_1, p_2, \ldots, p_n$$$, the price in rubles for each of the (n) chapters.

Constraints

  • $$$1 \leq n \leq 5 \cdot 10^5$$$.
  • $$$1 \leq p_i \leq 10^{12}$$$, for all $$$i$$$.
Output

A single positive integer, the value of the smallest amount of debt as described above.

ExamplesInput
3
2 1 10000000000
Output
4
Input
1
2
Output
1

Source/Category

加入题单

算法标签: