405153: GYM101807 E Error
Description
Percy is a primary school student. He is learning how to do addition and subtraction. Being a smart boy, he decided to use a calculator instead of doing it by hand.
The calculator can only store and display non-negative integers of up to 8 digits, i.e. integers between 0 and 99999999 inclusive. If at any time the result of an operation exceeds this range, the calculator will display Error and stops functioning. Therefore, Percy tries to rearrange the terms in the expression he is trying to calculate.
Specifically, the expression contains $$$N$$$ numbers between -99999999 and 99999999 and Percy needs to sum them up using the calculator one by one. Since numbers can be summed up in any order, help Percy find an order that won't cause any error.
InputThe first line contains an integer $$$N$$$, the number of integers that Percy needs to sum up ($$$1 \le N \le 10$$$).
Each of the next $$$N$$$ lines contains an integer between -99999999 and 99999999 inclusive.
OutputIf it is not possible to calculate the sum of the integers without causing calculator error, output Error.
Otherwise, in separate lines output ANY order of the $$$N$$$ integers that would not cause calculator error. The integers shall be added to / subtracted from the calculator one by one from top to bottom.
ExamplesInput4Output
33334444
87654321
-10000000
-20000000
33334444Input
-10000000
-20000000
87654321
3Output
-100
-200
-300
ErrorInput
3Output
-400
10000
-7000
10000Note
-7000
-400
In sample 1, one of the possible order is +33334444 → -10000000 → -20000000 → +87654321. The results after the operations are 33334444, 23334444, 3334444 and 90988765. All of them are between 0 and 99999999 inclusive. Note that +87654321 → -20000000 → -10000000 → +33334444 is also acceptable. However, +87654321 → -20000000 → +33334444 → -10000000 is not an acceptable answer because the result after +33334444 is 100988765 which exceeds 99999999.
In sample 2, it will cause Error no matter how Percy reorders the operations.