(Challenge) 300 IQ Ants

All submissions for this problem are available.
### Read problem statements in [Hindi](http://www.codechef.com/download/translated/MARCH20/hindi/ADANTS.pdf), [Bengali](http://www.codechef.com/download/translated/MARCH20/bengali/ADANTS.pdf), [Mandarin Chinese](http://www.codechef.com/download/translated/MARCH20/mandarin/ADANTS.pdf), [Russian](http://www.codechef.com/download/translated/MARCH20/russian/ADANTS.pdf), and [Vietnamese](http://www.codechef.com/download/translated/MARCH20/vietnamese/ADANTS.pdf) as well. There are $N$ ants (numbered $1$ through $N$) in a plane. For simplicity, we will represent the ants by points. For each valid $i$, initially, the position of the $i$th ant is $(X_i,Y_i)$. Ada wants to gather all ants at a single point. In order to do that, she wants to give instructions to the ants. In each instruction:  First, Ada chooses a simple convex polygon with $M$ vertices (numbered $1$ through $M$ clockwise) such that there is at least one ant in each of its vertices and no three of its vertices are collinear. The polygon may have area $0$, in which case it is a line segment with only two vertices.  Then, for each $i$ from $1$ to $M1$ (inclusive) in this order:  Let's denote the set of all ants currently standing at the $i$th vertex by $A_i$. Also, let $B_i$ denote its subset that consists of all ants that were standing at this vertex when Ada chose this polygon.  Ada chooses an ant from the set $B_i$ (let's denote it by $c_i$) and tells this ant, together with all other ants from the set $A_i$, to move to the nearest point $P$ with integer coordinates (different from the $i$th vertex) that belongs to the side of the polygon between vertices $i$ and $i+1$.  If the point $P$ already contains some other ants, then these ants and the ants from the set $A_i$ will never separate and they will move together from then on. In other words, whenever two ants $a$ and $b$ are at the same position and Ada tells ant $a$ to move, then ant $b$ will move together with ant $a$. Ants are very intelligent creatures (with an IQ around 300), so they can easily perform this instruction. However, ants are lazy, so the sum of $M$ over all instructions must not exceed $5 \cdot 10^5$. Help Ada minimise the number of instructions she needs to give to the ants in order to gather them at a single point. ### Input  The first line of the input contains a single integer $N$.  $N$ lines follow. For each valid $i$, the $i$th of these lines contains two spaceseparated integers $X_i$ and $Y_i$ denoting the position of the $i$th ant. ### Output First, print a line containing a single integer $Q$ ― the number of instructions. Then, print $Q$ lines; each of these lines should describe one instruction in the format `M c_1 c_2 ... c_M`. ### Example Input ``` 5 0 0 2 4 4 3 5 1 3 0 ``` ### Example Output ``` 2 4 1 2 3 4 3 1 3 5 ``` ### Explanation In the first instruction, ant A moves to the point $(1,2)$, then ant B moves to ant C, and then they move together to ant D. After the second instruction, the three ants end up at the point $(3,0)$. ### Test generation and constraints There are five test files.  In test file 1, the ants are placed in a chessboardlike pattern, i.e. at all points $(x, y)$ such that $0 \le x,y \le 500$ and $x+y$ is even.  In test file 2, the positions of the ants are generated in the following way:  Consider the square $S$ whose lower left corner is $(0,0)$ and upper right corner is $(2^{10}, 2^{10})$.  Repeat the following: Choose two points $P$ and $Q$ on the perimeter of $S$ uniformly randomly. Consider all points on the line segment $\mathsf{PQ}$ with integer coordinates that do not contain ants yet. Sort these points first by nondecreasing first coordinate and then by nondecreasing second coordinate. Add an ant at each of these points, in this order.  The process continues until we get $N = 2^{17}$ distinct points with ants.  In test file 3, the positions of the ants are generated similarly to test file 2, but the points $P$ and $Q$ are always chosen uniformly randomly among all points inside or on the perimeter of the square $S$.  In test files 4 and 5, the positions of the ants are $N = 2^{17}$ distinct points with coordinates chosen independently and uniformly randomly between $0$ and $2^{10}$ (inclusive). ### Scoring If any of your instructions are invalid, the sum of $M$ over all instructions exceeds $5 \cdot 10^5$ or the ants are not gathered at a single point after performing all instructions, you will receive the Wrong Answer verdict. Otherwise, the score of a test file is the number of performed instuctions. The score of a submission is the sum of scores of all test files. Your goal is to minimise the score of your submission. There are five test files. During the contest, the displayed score will account for exactly 3 test files, i.e. your score reflects your submission's performance on 60% of the test files. However, if your program gets a nonAC verdict on any test file, your submission's verdict will be nonAC. In other words, an AC verdict denotes that your program runs successfully on all the test files. After the end of the contest, your score will be changed to include the sum of your program's scores over the other 2 test files.Author:  alei 
Editorial  https://discuss.codechef.com/problems/ADANTS 
Tags  alei, challenge, march20, tmwilliamlin 
Date Added:  19022020 
Time Limit:  7 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, SQL, kotlin, PERL6, TEXT, CPP17, SCM chicken, PYP3, CLOJ, R, COB, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 