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
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <unordered_set>


using namespace std;

int main(){
  int i;
  cin >> i;

  int curpow = 1;
  int nextNodeNumb = 1;
  vector<pair<int, int>> connections;
  while(curpow * 2 <= i) {
    curpow *= 2;
    connections.push_back({nextNodeNumb + 1, nextNodeNumb + 2});
    connections.push_back({nextNodeNumb + 3, - 1});
    connections.push_back({nextNodeNumb + 3, -1});
    nextNodeNumb += 3;
  }
  int cur = curpow;
  curpow = 1;
  int node = 2;
  while(cur != i) {
    if(i & curpow){
      cur += curpow;
      connections[node].second = -2;
    }
    curpow *= 2;
    node += 3;
  }
  nextNodeNumb ++;
  cout << nextNodeNumb << endl;
  for(auto a : connections){
    cout << a.first << " ";
    if(a.second != -2){
      cout << a.second;
    } else {
      cout << nextNodeNumb;
    }
    cout << endl;
  }
  cout << nextNodeNumb << " " << -1 << endl;
  cout << "-1 -1" << endl;
}