407439: GYM102791 E Numbers on Whiteboard

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

E. Numbers on Whiteboardtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Numbers $$$1, 2, 3, \dots n$$$ (each integer from $$$1$$$ to $$$n$$$ once) are written on a board. In one operation you can erase any two numbers $$$a$$$ and $$$b$$$ from the board and write one integer $$$\frac{a + b}{2}$$$ rounded up instead.

You should perform the given operation $$$n - 1$$$ times and make the resulting number that will be left on the board as small as possible.

It's easy to see that after $$$n - 1$$$ operations, there will be left only one number. Your goal is to minimize it.

Input

The first line contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of integers written on the board initially.

Output

In the first line, print the minimum possible number left on the board after $$$n - 1$$$ operations. Each of the next $$$n - 1$$$ lines should contain two integers — numbers $$$a$$$ and $$$b$$$ chosen and erased in each operation.

ExampleInput
4
Output
2
2 4
3 3
3 1
Note

In the first sample, numbers $$$[1, 2, 3, 4]$$$ are written on the board initially. In the first operation, numbers $$$2$$$ and $$$4$$$ are erased and number $$$3$$$ are written instead. So, after the first operation, the numbers $$$[1, 3, 3]$$$ will be written. After the second operation, the numbers $$$[1, 3]$$$ will be written. Finally, after the third operation, the only number left is $$$2$$$.

加入题单

上一题 下一题 算法标签: