1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <bitset>
#include <iostream>

using i32 = int32_t;

i32 find_msb(std::bitset<32> &bs)
{
  for (i32 i = 31; i >= 0; --i) {
    if (bs.test(i))
      return i;
  }
}

#define EDGES(x, y) std::cout << (x) << ' ' << (y) << std::endl;

int main()
{
  std::ios::sync_with_stdio(false);

  i32 k_;
  std::cin >> k_;
  std::bitset<32> k{ k_ };

  i32 core = find_msb(k);
  i32 last = 2 * (core + 1);
  std::cout << last << std::endl;

  for (i32 i = 2; i <= core + 1; ++i) {
    EDGES(i, core + i);
  }
  EDGES(last, -1);
  for (i32 i = 0; i < core; ++i) {
    EDGES(i + 2, (k.test(i) ? last : -1));
  }
  EDGES(-1, -1);

  return 0;
}