#P15141. [SWERC 2025] Git Gud

[SWERC 2025] Git Gud

题目描述

You are an adventurer working for the futuristic corporation RoboCorp. Your initial skill level is an integer in the range [1,n][1, n], but you don't know its exact value. Your goal is to reach a skill level of at least nn by completing missions for RoboCorp, but each mission costs precious robocoins.

You can choose missions of any difficulty and any positive integer duration (in hours). However, the cost depends both on the new mission's length, and on how the new mission's difficulty compares to your most recent one.

Let xx be the difficulty of your most recent mission. If you want to undertake a new mission of difficulty yy and duration ll:

  • If it is your first mission, or yxy \le x, the cost is ll robocoins.
  • If y>xy > x, the cost is 1000+l1000 + l robocoins.

Your skill improves only when you take on a mission whose difficulty yy exactly matches your current skill ss:

  • If y=sy = s, then your skill increases by ll.
  • Otherwise, your skill does not change.

After each mission, you still don't know your actual skill value.

You start with 10610^6 robocoins. Find a strategy (a sequence of missions) that does not exceed your budget and guarantees your skill becomes at least nn, no matter what your initial skill was.

输入格式

The input contains a single line with an integer nn (1n2500001 \le n \le 250000) — the target skill level (that is, by the end, your skill must be greater or equal to nn).

输出格式

In the first line, print a single integer kk (0k1060 \le k \le 10^6) — the number of missions you plan to complete.

Then, print kk lines. The ii-th line must contain two integers yy and ll (1y,l1061 \le y, l \le 10^6) — the difficulty and duration (in hours) of the ii-th mission, respectively.

4
4
1 4
3 1
2 1
3 1

提示

Explanation of sample 1.

In the example, your target skill is n=4n = 4. You can use the following strategy:

  • Take a mission of difficulty y=1y = 1 and duration l=4l = 4. It's your first mission, so you pay l=4l = 4 robocoins.
  • Take a mission of difficulty y=3y = 3 and duration l=1l = 1. The previous mission had difficulty x=1x = 1, so since y>xy > x, you pay l+1000=1001l + 1000 = 1001 robocoins.
  • Take a mission of difficulty y=2y = 2 and duration l=1l = 1. Now x=3x = 3, and since yxy \le x, you pay l=1l = 1 robocoin.
  • Take a mission of difficulty y=3y = 3 and duration l=1l = 1. Now x=2x = 2, and since y>xy > x, you pay l+1000=1001l + 1000 = 1001 robocoins.

In total, you spend 20072007 robocoins, which is within your 10610^6-robocoin budget.

Now we verify that this strategy always works:

  • If your initial skill was 11, after the first mission it becomes 55.
  • If your initial skill was 22, after the third mission it becomes 33, and after the fourth mission it becomes 44.
  • If your initial skill was 33, after the second mission it becomes 44.
  • If your initial skill was 44, it stays 44.

So no matter what your starting skill is, you end with skill n\ge n.