This page is still under construction.

Parts of this page are still being built. What you see may change.

Farm

Time limit1sMemory limit1024 MB

Summary
Find a longest route of trees Mr. P can visit by driving straight left, right, up, or diagonally up, and the fewest road rollers that cover the non-horizontal ruts.
Level

Hard9 of 10

Topics
Graph, Sorting, Greedy
Solved
No attempts yet

Statement

The farm can be treated as a two-dimensional Euclidean plane. There are nn trees, numbered 1,2,…,n1, 2, \dots, n. Each tree is a point on the plane, and tree ii has coordinates (xi,yi)(x_i, y_i). All tree coordinates are pairwise distinct.

Mr. P starts at the origin (0,0)(0,0) and drives. In each round, he chooses one of five directions: left, right, up, 45 degrees upper left, or 45 degrees upper right. A direction can be chosen only if driving that way reaches a tree he has never visited. He drives straight in the chosen direction and stops at the nearest unvisited tree in that direction. If no direction is available, he stops. Mr. P follows an optimal route, meaning one that visits the most trees. If several optimal routes exist, he may choose any of them.

Mr. S found that Mr. P's car leaves a rut on the farm. A rut is a line segment between two trees, or between the origin and a tree. Mr. S considers ruts in directions other than left and right (up, 45 degrees upper left, and 45 degrees upper right) unsightly. He will rent road rollers to reinforce the areas that might have such ruts. Formally, these areas are the segments contained in at least one optimal route.

A road roller works as follows:

  • It starts at the origin or at any tree.
  • It may move up, 45 degrees upper left, or 45 degrees upper right. It may stop or change direction only at a tree.
  • It may pass only through areas that might have non-horizontal ruts. An area may be passed by several road rollers.

Mr. P and Mr. S ask two questions: (1) find an optimal route for Mr. P, and (2) find the minimum number of road rollers needed.

Input

The first line contains an integer nn, the number of trees. Each of the next nn lines contains two integers xix_i and yiy_i, separated by a single space, the coordinates of the ii-th tree.

Output

The output has three lines. The first line is mm, the maximum number of trees Mr. P may visit. The second line contains the mm trees Mr. P visits, separated by single spaces. The third line is the minimum number of road rollers required.

Constraints

Test CasennCoordinate RangeAdditional Constraints
1n=5n=5∥xi∥≤100\|x_i\| \le 100, 0<yi≤1000 < y_i \le 100
2n=10n=10
3n=100n=100∥xi∥≤10 000\|x_i\| \le 10\,000, 0<yi≤10 0000 < y_i \le 10\,000
4n=1000n=1000
5n=5000n=5000∥xi∥≤1 000 000\|x_i\| \le 1\,000\,000, 0<yi≤1 000 0000 < y_i \le 1\,000\,000The optimal route is unique.
6
7n=50 000n=50\,000
8n=5000n=5000∥xi∥≤1 000 000\|x_i\| \le 1\,000\,000, 0<yi≤1 000 0000 < y_i \le 1\,000\,000All yiy_i are unique.
9n=50 000n=50\,000
10
11n=5000n=5000∥xi∥≤1 000 000\|x_i\| \le 1\,000\,000, 0<yi≤1 000 0000 < y_i \le 1\,000\,000For any integer YY, at most 10001000 trees satisfy yi=Yy_i = Y. Additionally, there exists an optimal solution such that the road rollers won't pass through the same place twice.
12
13n=50 000n=50\,000
14
15n=10 000n=10\,000∥xi∥≤1 000 000 000\|x_i\| \le 1\,000\,000\,000, 0<yi≤1 000 000 0000 < y_i \le 1\,000\,000\,000For any integer YY, at most 10001000 trees satisfy yi=Yy_i = Y.
16
17n=30 000n=30\,000
18
19n=50 000n=50\,000
20

Examples2

  1. Example 1

    Input
    6
    -1 1
    1 1
    -2 2
    0 8
    0 9
    0 10
    
    Expected output
    3
    2 1 3
    3
    
  2. Example 2

    Input
    4
    0 1
    -2 1
    2 1
    3 2
    
    Expected output
    4
    1 2 3 4
    2