Never trust Ivan (2) P46204


Statement
 

pdf   zip

Given nn points on the plane p1pnp_1 \dots p_n no three of which are collinear, find a permutation of the points pi1pinp_{i_1} \dots p_{i_n} such that the nn segments (pi1,pi2),(pi2,pi3),,(pin1,pin),(pin,pi1)(p_{i_1}, p_{i_2}), (p_{i_2}, p_{i_3}), \dots, (p_{i_{n-1}}, p_{i_n}), (p_{i_n}, p_{i_1}) form a non-degenerate polygon, that is, one that does not cross itself.

Input

Input consists of several cases, each one with nn followed by nn points with integer coordinates not larger than 10710^7 in absolute value. Assume 3n1043 \le n \le 10^4, and that no three given points are collinear.

Output

For every case, print a correct polygon constructed from the nn points. If there is more than one solution, print any of them. If there is no solution, print “Ivan is a troll”.

Public test cases
  • Input

    4  0 0  1 1  0 1  1 0
    3  0 0  10 10  15 20
    5  -1 -1  -3 -3  -1 1  1 -2  -2 0
    4  0 0  -1 1  0 -1  1 -2
    7  -9 -4  0 -5  2 3  1 7  0 0  5 -5  1 4
    

    Output

    1 4 2 3
    1 2 3
    2 4 1 3 5
    3 4 1 2
    1 2 6 5 3 7 4
    
  • Information
    Author
    Ivan Geffner
    Language
    English
    Official solutions
    C++
    User solutions
    C++