#P2041. 分裂游戏

分裂游戏

Description

There is an infinite board. In the lower-left corner, there is a staircase-shaped region of size nn, and there is a single piece in the very bottom-left cell of this staircase. Each time, you may “split” one piece into two pieces, placing them in the cell one square above and the cell one square to the right of the original position, respectively. (However, if a target cell already contains a piece, you cannot perform this operation.) Your goal is to, after finitely many operations, make the entire staircase contain no pieces. The figure below shows one solution when n=2n = 2.

We number rows from bottom to top and columns from left to right, and denote a piece by (row, column), both starting from 11.

For example, in the third step, the three pieces are at coordinates (3,1)(3, 1), (2,2)(2, 2), (1,2)(1, 2).

Given nn, you need to output a suitable sequence of operations.

Input Format

Input a single positive integer nn.

Output Format

If there is a solution, the first line should contain a positive integer mm, the total number of operations.

In the next mm lines, each line contains two positive integers xi,yix_i, y_i, indicating that in the ii-th operation you split the piece at row xix_i, column yiy_i.

If there is no solution, output 1-1 on the first line.

1
1
1 1
2
4
1 1
2 1
2 2
1 2

Hint

  • Constraints: For 40%40\% of the testdata, n8n \leq 8.
  • Constraints: For 100%100\% of the testdata, n1000n \leq 1000.

Translated by ChatGPT 5