QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 32 MB Total points: 10

#11646. Segments

統計

Lets consider a set $ S $ of $ n $ vertical segments on the plain (segments include their end points). None of the elements of $ S $ have a point in common. Two segments are said to "see each other" if there exists a horizontal segment, which connects them and does not have any common points with other segments from $ S $.

On the figure below, there is an example set of segments. Pairs of segments that can see each other, are: 1-2, 1-3, 2-3, 1-5 and 4-5. The segments 1 and 4 do not see each other.

problem_11646_1.png

For a given number $ n $, we search for a set $ S $ of $ n $ vertical segments such that the number of pairs of segments which can see each other is as big as possible.

Write a program which:

  • reads the number $ n $ from the standard input,
  • computes locations of $ n $ vertical segments, such that
  • none of them have a point in common,
  • the number of pairs of segments which can see each other is as big as possible,
  • writes the answer to the standard output.

Input Format

The first and only line of the standard input contains one integer $ n $ ($1 ≤ n ≤ 20\,000$).

Output Format

The first line of the standard output should contain one integer - maximal number of pairs of segments that can see each other. Each of the following $ n $ lines should identify the coordinates of one segment. Line $ i + 1 $ (for $ i = 1, 2, \ldots, n $) consists of three integers: $ x_{i} $, $ d_{i} $ and $ g_{i} $ ($0 ≤ x_{i} ≤ 1\,000\,000\,000$, $0 ≤ d_{i} < g_{i} ≤ 1\,000\,000\,000$), separated by a single space. They represent the segment which connects the points $( x_{i}, d_{i})$ and $(x_{i}, g_{i})$.

If there are more than one correct arrangement of $ n $ segments, your program can write out any of them.

Example

Input

4

Output

6
1 1 5
2 2 4
3 3 5
4 1 4
problem_11646_2.png
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.