405153: GYM101807 E Error

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

Description

E. Errortime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

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.

Input

The 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.

Output

If 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.

ExamplesInput
4
33334444
87654321
-10000000
-20000000
Output
33334444
-10000000
-20000000
87654321
Input
3
-100
-200
-300
Output
Error
Input
3
-400
10000
-7000
Output
10000
-7000
-400
Note

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.

加入题单

上一题 下一题 算法标签: