Universal Cup Judging System

Universal Cup

Time Limit: 2.0 s Memory Limit: 1024 MB Total points: 100 Hackable ✓
Statistics

Description

Consider $n$ integer points on a plane, where $n$ is divisible by $3$. The $x$ coordinates are a permutation of integers from $1$ to $n$. The $y$ coordinates are also a permutation of integers from $1$ to $n$.

Construct a configuration of $n/3$ triangles with vertices in the given points: each point must appear as a vertex of one of the triangles. The triangles can be degenerate and can intersect freely.

The score of a configuration is the sum of the sizes of all triangles in it. The size of a triangle is the perimeter of its bounding rectangle. The bounding rectangle is the minimal rectangle with sides parallel to coordinate axes that contains the triangle.

Find a configuration that achieves the maximum possible score.

Input

The first line contains an integer $n$ ($3 \le n \le 99\,999$; $n$ is divisible by $3$).

Each of the next $n$ lines contains two integers $x$ and $y$: the coordinates of one of the points. Each integer from $1$ to $n$ appears once among the $x$ coordinates and once among the $y$ coordinates.

Output

On the first line, print the maximum possible score.

Next, print any configuration that achieves this score. For that, print $n/3$ lines with three integers in each: the numbers of points in the input that are the vertices of a triangle. The points are numbered from $1$ to $n$ in the input order. Triangles and their vertices can be printed in any order.

Example

6
6 5
3 6
5 3
2 4
1 1
4 2
32
2 3 5
6 1 4

Note

problem_17172_187b4365a0de3832ff3c189274998f76.png

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1223EditorialOpen题解jianglyView

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.