#P7921. [Kubic] Division

[Kubic] Division

Description

You have a multiset. Initially, it contains only one positive integer nn.

Each time, you may choose a positive integer xx currently in the multiset and remove it, then specify a positive integer yy (it does not need to be in the multiset) such that x>yx>y, and insert yy and xyx-y into the multiset.

You must ensure that at any moment, the maximum value in the multiset is strictly less than 22 times the minimum value in the multiset.

Find the maximum number of operations you can perform, and output a construction.

The input guarantees that the maximum number of operations does not exceed 10610^6.

Input Format

A single line containing one integer nn.

Output Format

The first line contains one integer mm, the number of operations in your constructed plan.

The next mm lines each contain two integers x,yx,y, describing one operation (the meanings of x,yx,y are the same as in the statement).

You must ensure that x>yx>y and that xx has appeared in the current multiset.

8
2
8 3
5 2
30
5
30 12
18 8
12 6
10 5
8 4

Hint

For 100%100\% of the testdata, 1n1091\le n\le 10^9.

Constraints

Score nn
Subtask1\operatorname{Subtask}1 1010 10\le 10
Subtask2\operatorname{Subtask}2 2020 100\le 100
Subtask3\operatorname{Subtask}3 3030 106\le 10^6
Subtask4\operatorname{Subtask}4 4040 No special limits

Scoring

In the following cases, you will get 00 points on that test point:

  • The output format does not meet the requirements.

  • Extra information is printed (including spaces and newline characters).

  • The number of operations in your construction is different from the standard answer.

  • Your construction does not satisfy the requirements of the problem.

  • Time limit exceeded.

If none of the above happens, you will get full score on that test point.

It is guaranteed that the SPJ uses no more than 100ms,10MB100\operatorname{ms},10\operatorname{MB}.

Sample Explanation 1

One possible sequence of operations is as follows:

8

3 5

2 3 3

It can be proven that there is no better plan.

Sample Explanation 2

One possible sequence of operations is as follows:

30

12 18

8 10 12

6 6 8 10

5 5 6 6 8

4 4 5 5 6 6

It can be proven that there is no better plan.

Translated by ChatGPT 5