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

~/algor $ cat problems/qutb-burchagi-saralash

Sorting by angle

Medium 1000 ms 128 MB 60%
Share

$n$ points are given on the plane, none of them at the origin. For each point, take the angle in $[0^{\circ}; 360^{\circ})$ measured counterclockwise from the positive direction of the $Ox$ axis to the ray from the origin to the point. Print the points in increasing order of this angle; points with equal angles go in increasing order of their distance to the origin (equal points stand next to each other).

Rays from the origin to the points; the points are numbered counterclockwise

Input

The first line contains a positive integer $n$. Each of the next $n$ lines contains two integers: $x_{i}$ and $y_{i}$.

Output

$n$ lines — the coordinates of the sorted points.

Note

$1 \le n \le 10^{5}$
$-10^{4} \le x_{i}, y_{i} \le 10^{4}$, $(x_{i}; y_{i}) \ne (0; 0)$

Examples

Input #1
6
-2 1
3 0
1 1
0 -4
2 2
-3 0
Output #1
3 0
1 1
2 2
-2 1
-3 0
0 -4
Input #2
1
0 5
Output #2
0 5

Sign in to submit a solution

Signing up is free and takes a minute.