Hide

Problem D
Walrus Weights

Wallace the Weightlifting Walrus is training for a contest where it will have to lift $1\, 000$ kg. Wallace has some weight plates lying around, possibly of different weights, and its goal is to add some of the plates to a bar so that it can train with a weight as close as possible to $1\, 000$ kg.

In case there exist two such numbers which are equally close to $1\, 000$ (e.g. $998$ and $1\, 002$), Wallace will pick the greater one (in this case $1\, 002$).

Help Wallace the Weightlifting Walrus and tell it which weight it will have to lift.

Input

The first line of the input contains the number of plates $n$ ($1 \leq n \leq 1\, 000$). Each of the following $n$ lines contains one positive integer less than or equal to $1\, 000$, denoting the weight of each plate.

Output

Output one integer, the combined weight closest to $1\, 000$.

Sample Input 1 Sample Output 1
4
900
500
498
4
1002
Sample Input 2 Sample Output 2
1
1
1

Please log in to submit a solution to this problem

Log in