Under construction

Still being built. Things may change

Longest increasing pub-sequence

Time limit3sMemory limit1024 MB

Summary
Given N integer points, find the longest route whose consecutive Euclidean step lengths strictly increase, with no point repeated back to back.
Level

Medium6 of 10

Topics
Dynamic programming, Sorting, Geometry
Solved
No attempts yet

Problem

Elise has just started at Stackköpings Tekniska Högskola (STH), and as part of the freshman welcome there is a traditional pub crawl. A pub crawl means visiting every section room and having a drink at each one. Elise and her friends do not drink alcohol, but they like long walks. So they want to plan a route with as many visits as possible, where the distances they walk between rooms are strictly increasing. Find the maximum number of visits they can make.

The section rooms are points in the plane with integer coordinates. Elise and her friends always walk the shortest distance between two rooms. The distance is the usual Euclidean distance, (x1−x2)2+(y1−y2)2\sqrt{(x_1 - x_2)^2 + (y_1 - y_2)^2}. They may start at any room. They may visit the same room more than once, and each visit counts separately. However, they may not visit the same place twice in a row.

Starting at (1,0)(1,0) and following the red arrows gives a route with 66 visits, which is also the maximum.

Input

The first line contains an integer NN, the number of section rooms (2≤N≤20002 \leq N \leq 2000). Each of the next NN lines contains two integers xi,yix_i, y_i, the coordinates of a section room (0≤xi,yi≤1090 \leq x_i, y_i \leq 10^9).

Output

Print one integer, the maximum number of visits Elise and her friends can make when the distances between consecutive rooms are strictly increasing.

Examples4

  1. Example 1

    Input
    4
    0 0
    1 0
    0 2
    2 3
    
    Expected output
    6
    
  2. Example 2

    Input
    2
    4 5
    1 7
    
    Expected output
    2
    
  3. Example 3

    Input
    3
    1000000000 1000000000
    0 0
    44444444 55555555
    
    Expected output
    4
    
  4. Example 4

    Input
    9
    0 0
    0 1
    0 2
    1 0
    1 1
    1 2
    2 0
    2 1
    2 2
    
    Expected output
    6