Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/saralash-modul-boyicha

Sort by absolute value

Easy 1000 ms 128 MB 22%
Share

$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).

Numbers lined up by their distance from zero on the number line

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

Sign in to submit a solution

Signing up is free and takes a minute.