~/algor $ cat problems/saralash-modul-boyicha
Sort by absolute value
Easy
1000 ms
128 MB
22%
$n$ integers are given. Sort them by increasing absolute value ($|a_{i}|$). If the absolute values are equal, the negative number comes first (that is, the smaller one).
Input
The first line contains a positive integer $n$. The second line contains $n$ integers $a_{i}$.
Output
$n$ numbers separated by spaces — in sorted order.
Note
$1 \le n \le 2 \cdot 10^{5}$
$-10^{9} \le a_{i} \le 10^{9}$
Examples
Input #1
6 3 -1 -3 2 0 1
Output #1
0 -1 1 2 -3 3
Input #2
1 7
Output #2
7