X Marks the Spot (Small)
Time limit5sMemory limit512 MB
Decide whether two perpendicular lines split 4N mines into four groups of N and print the lexicographically smallest grouping.
- Level
Medium7 of 10
- Topics
- Geometry, Brute force
- Solved
- No attempts yet
Problem
King Tyrone and his four sons conquered the nation of Carrania. The sons started arguing about how to split the land right away, and the argument was really about the gold mines: no son was willing to end up with fewer mines than a brother.
There are mines in all. The king spread out a map, drew one large X on it, and declared that each son would get one of the four pieces the X cuts the country into. The map he drew on was not a map of Carrania. His first minister hid that map and now has to draw the same kind of X on the real map so that every son gets the same number of mines. All four sons watched the king draw, so the borders must again be two perpendicular straight lines.
You are given the coordinates of the mines. Decide whether two perpendicular lines can be drawn so that no mine lies on a border and each of the four regions holds exactly mines.
Several pairs of lines can satisfy the condition, and two different pairs can cut the mines into the very same four groups, so report the division instead of the lines. Describe a division by a sequence , where is the group of the -th mine in input order. Number the groups in the order in which they first appear in the sequence, so is always . If more than one division is possible, print the sequence that is smallest in lexicographic order.
Input
The first line has the number of test cases . Each test case starts with a line holding , the number of mines every son must get. The next lines each hold two integers and , the coordinates of one mine. All mines sit at different positions and no three of them lie on one straight line.
Limits
Output
For each test case print one line in the form Case #x: g_1 g_2 ... g_4N, where is the test case number starting from and the terms of the sequence are separated by single spaces. If no pair of perpendicular lines meets the condition, print Case #x: IMPOSSIBLE instead.