Order the sticks so each one slides straight down off the table without touching the sticks still on it, choosing the lexicographically smallest such order.
Medium7Topological sortGeometryHeapNo attempts yetTime limit1sMemory limit64 MBYou have probably heard the legend of King Arthur and the Knights of the Round Table. Most versions explain the round shape of the table by the equality of the knights. The real reason is different. Arthur chose a round table because of a chore he had as a child.
Young Arthur cleaned up square tables after games of pick-up sticks, a game in which players lift sticks one at a time without disturbing the others. After a game the table holds several sticks that do not touch each other. The organizers gave the cleaners a strict rule. The sticks must be removed one at a time, and each stick must be pulled along the shortest path toward the edge of the table nearest to where the cleaner sits. While a stick is being pulled it must not be rotated, and it must not touch any other stick, not even at an endpoint.
The table is the square in the coordinate plane whose opposite corners are (0,0) and (10000,10000), and each stick is a line segment lying inside that square. Arthur sits at the edge of the table on the x-axis, so removing a stick means translating its segment in the negative y direction until it leaves the table. A stick can be removed at a given moment only if that downward translation never touches a stick that is still on the table.
Find an order in which all sticks are removed.

The first line contains the integer N, the number of sticks (1≤N≤5000).
Each of the next N lines contains four integers x1, y1, x2, y2, the two endpoints of one stick (0≤x1,y1,x2,y2≤10000).
No two sticks touch each other. At least one order that removes every stick exists.
Print the labels of the sticks in the order they are taken off the table on one line, separated by single spaces. A stick's label is its position in the input.
If several orders are possible, print the lexicographically smallest one. Among all valid orders take the one whose first label is smallest, among those the one whose second label is smallest, and apply the same rule to every later position.