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
#include <bits/stdc++.h>
using namespace std;

int main() {
  int x;
  cin >> x;
  if (x == 1) {
      cout << "2" << endl;
      cout << "2 -1" << endl;
      cout << "-1 -1" << endl;
      return 0;
  }
  int n = 0;
  int x2 = x;
  while (x2) {
    if (x2) {
      n++;
    }
    x2 /= 2;
  }
  n = 3 * (n - 1) + 1;
  cout << n << endl;
  for (int i = 1; i < n; i++) {
    if (i % 3 == 0) {
      cout << "-1 " << i + 1 << endl;
    } else if (i % 3 == 2) {
      cout << i + 1 << " " << i + 2 << endl;
    } else { // i % 3 == 1
      int second_neighbour = -1;
      if (1 << (i / 3) & x && second_neighbour != i + 1) {
        second_neighbour = n;
      }
      cout << i + 1 << " " << second_neighbour << endl;
    }
  }
  cout << "-1 -1" << endl;
}