cho.sh
Notes
Loading...

Smallest Unmeasurable Weight

Time limit

1s

Memory limit

128 MB

Problem

You want to measure the weight of an object using one two-pan balance scale. The two arms have the same length, and each end has a pan for placing either an object or weights. In this problem, only weights may be placed on one pan, and only the object to be measured may be placed on the other pan.

You are given N weights whose masses are positive integers. By choosing some of the given weights and placing them on the weight pan, find the smallest positive integer weight that cannot be measured.

For instance, if the seven weights have masses 3, 1, 6, 2, 7, 30, and 1, then the smallest positive integer weight that cannot be measured with them is 21.

Input

The first line contains the number of weights N. N is between 1 and 1,000, inclusive. The second line contains N positive integers, separated by spaces, representing the masses of the weights. Each mass is between 1 and 1,000,000, inclusive.

Output

Print the smallest positive integer weight that cannot be measured using the given weights.