#P1254C. Point Ordering

    ID: 4002 Type: RemoteJudge 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: 8 Uploaded By: Tags>constructive algorithmsgeometryinteractivemath*2300

Point Ordering

Description

This is an interactive problem.

Khanh has nn points on the Cartesian plane, denoted by a1,a2,,ana_1, a_2, \ldots, a_n. All points' coordinates are integers between 109-10^9 and 10910^9, inclusive. No three points are collinear. He says that these points are vertices of a convex polygon; in other words, there exists a permutation p1,p2,,pnp_1, p_2, \ldots, p_n of integers from 11 to nn such that the polygon ap1ap2apna_{p_1} a_{p_2} \ldots a_{p_n} is convex and vertices are listed in counter-clockwise order.

Khanh gives you the number nn, but hides the coordinates of his points. Your task is to guess the above permutation by asking multiple queries. In each query, you give Khanh 44 integers tt, ii, jj, kk; where either t=1t = 1 or t=2t = 2; and ii, jj, kk are three distinct indices from 11 to nn, inclusive. In response, Khanh tells you:

  • if t=1t = 1, the area of the triangle aiajaka_ia_ja_k multiplied by 22.
  • if t=2t = 2, the sign of the cross product of two vectors aiaj\overrightarrow{a_ia_j} and aiak\overrightarrow{a_ia_k}.

Recall that the cross product of vector a=(xa,ya)\overrightarrow{a} = (x_a, y_a) and vector b=(xb,yb)\overrightarrow{b} = (x_b, y_b) is the integer xaybxbyax_a \cdot y_b - x_b \cdot y_a. The sign of a number is 11 it it is positive, and 1-1 otherwise. It can be proven that the cross product obtained in the above queries can not be 00.

You can ask at most 3n3 \cdot n queries.

Please note that Khanh fixes the coordinates of his points and does not change it while answering your queries. You do not need to guess the coordinates. In your permutation ap1ap2apna_{p_1}a_{p_2}\ldots a_{p_n}, p1p_1 should be equal to 11 and the indices of vertices should be listed in counter-clockwise order.

Interaction

You start the interaction by reading nn (3n10003 \leq n \leq 1\,000) — the number of vertices.

To ask a query, write 44 integers tt, ii, jj, kk (1t21 \leq t \leq 2, 1i,j,kn1 \leq i, j, k \leq n) in a separate line. ii, jj and kk should be distinct.

Then read a single integer to get the answer to this query, as explained above. It can be proven that the answer of a query is always an integer.

When you find the permutation, write a number 00. Then write nn integers p1,p2,,pnp_1, p_2, \ldots, p_n in the same line.

After printing a query do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:

  • fflush(stdout) or cout.flush() in C++;
  • System.out.flush() in Java;
  • flush(output) in Pascal;
  • stdout.flush() in Python;
  • see documentation for other languages.

Hack format

To hack, use the following format:

The first line contains an integer nn (3n10003 \leq n \leq 1\,000) — the number of vertices.

The ii-th of the next nn lines contains two integers xix_i and yiy_i (109xi,yi109-10^9 \le x_i, y_i \le 10^9) — the coordinate of the point aia_i.

Sample Input 1

6

15

-1

1

Sample Output 1

1 1 4 6

2 1 5 6

2 2 1 4

0 1 3 4 2 6 5

Note

The image below shows the hidden polygon in the example:

The interaction in the example goes as below:

  • Contestant reads n=6n = 6.
  • Contestant asks a query with t=1t = 1, i=1i = 1, j=4j = 4, k=6k = 6.
  • Jury answers 1515. The area of the triangle A1A4A6A_1A_4A_6 is 7.57.5. Note that the answer is two times the area of the triangle.
  • Contestant asks a query with t=2t = 2, i=1i = 1, j=5j = 5, k=6k = 6.
  • Jury answers 1-1. The cross product of A1A5=(2,2)\overrightarrow{A_1A_5} = (2, 2) and A1A6=(4,1)\overrightarrow{A_1A_6} = (4, 1) is 2-2. The sign of 2-2 is 1-1.
  • Contestant asks a query with t=2t = 2, i=2i = 2, j=1j = 1, k=4k = 4.
  • Jury answers 11. The cross product of A2A1=(5,2)\overrightarrow{A_2A_1} = (-5, 2) and A2A4=(2,1)\overrightarrow{A_2A_4} = (-2, -1) is 11. The sign of 11 is 11.
  • Contestant says that the permutation is (1,3,4,2,6,5)(1, 3, 4, 2, 6, 5).