#P16557. [ICPC 2026 LAC] Kitten Greetings

[ICPC 2026 LAC] Kitten Greetings

题目描述

Catarina loves all cats that live in her neighborhood. Her lifelong dream is to design a large cat-seeing circuit, so that every day she can go out and greet the cats while doing some exercise. Catarina's neighborhood can be represented as the 2D plane, with the North-South direction aligned with the yy-axis. A cat-seeing circuit that visits mm cats consists of exactly mm steps. Catarina chooses a starting position (x0,y0)(x_0, y_0) and faces one of the four cardinal directions. For each step i=1,2,,mi = 1, 2, \ldots, m the following occurs:

  • Catarina chooses a value ki>0k_i > 0 and walks kik_i units from (xi1,yi1)(x_{i-1}, y_{i-1}) straight ahead in her current direction, stopping at the location of a cat that she has not greeted during any previous step.
  • Catarina greets the cat, taking some time to appreciate its beauty.
  • Without turning around, Catarina walks another kik_i units straight ahead in her current direction, stopping at a position (xi,yi)(x_i, y_i).
  • Catarina turns 9090^\circ either clockwise or counterclockwise, facing again one of the four cardinal directions.

After completing all mm steps, Catarina must be back to her starting position (x0,y0)(x_0, y_0), facing her initial direction. Notice that the length of the cat-seeing circuit is i=1m2ki\sum_{i=1}^m 2k_i. When m=0m = 0, the cat-seeing circuit has length 00.

Catarina knows the location of the NN cats that live in her neighborhood. Surprisingly, no two cats have the same xx-coordinate or the same yy-coordinate. Your task is to determine the maximum length that a cat-seeing circuit can have.

输入格式

The first line contains an integer NN (1N40001 \le N \le 4000) indicating the number of cats.

Each of the next NN lines describes a cat with two integers XX and YY (108X,Y108-10^8 \le X, Y \le 10^8), representing that the cat has coordinates (X,Y)(X, Y).

No two cats have the same xx-coordinate or yy-coordinate (they differ in both of them).

输出格式

Output a single line with an integer indicating the maximum length that a cat-seeing circuit can have.

5
1 2
2 1
0 0
-1 -2
-2 -1
0
6
4 0
0 4
2 -1
-1 2
-4 3
3 -4
32
7
2 1
0 -1
5 5
3 0
4 4
6 2
1 -2
24

提示

Explanation of Sample 1:

In this case there is a circuit of length 1616 that visits all the cats, but it is not a cat-seeing circuit because the cat at coordinates (0,0)(0, 0) is greeted twice.

Explanation of Sample 2:

The picture below shows the location of the cats with small circles, together with a maximum-length cat-seeing circuit that visits all of them. The length of the circuit is 3232.

:::align{center} :::

Explanation of Sample 3:

It is possible to visit m=6m = 6 of the N=7N = 7 cats with a cat-seeing circuit of length 2424.

:::align{center} :::