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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include<iostream>
#include<vector>
#include<algorithm>
#include<climits>

using namespace std;

#define LL           long long
#define ULL          unsigned long long
#define PII          pair< int, int >
#define PLI          pair< long long, int >
#define VPII         vector< PII >
#define VPLI         vector< PLI >
#define MP           make_pair
#define REP(i,n)     for (int i=0;i<(n);++i)
#define FOR(i,a,b)   for (int i=(a); i<(b); ++i)
#define FORD(i,a,b)  for (int i=(a)-1; i>=(b); --i)
#define EACH(a, x)   for (auto& a : (x))
#define ALL(x)       (x).begin(), (x).end()

#define INF INT_MAX
#define MAXN 101

int k;
vector<int> neighbors[MAXN];

int main() {
    ios_base::sync_with_stdio(0);
    cin >> k;
    vector<int> powers;
    int power = 1;
    int helper_cnt = -2;
    while (k >= power) {
        if (k & power) {
            powers.push_back(power);
            helper_cnt++;
        }
        power *= 2;
    }
    power /= 2;
    int current_node = 1;
    FOR(i, 2, helper_cnt + 2) {
        neighbors[current_node].push_back(i);
        current_node++;
    }
    
    int current_helper = 1;
    int current_ladder = current_node + 1;
    while (power > 0) {
        while (neighbors[current_helper].size() > 1) {
            current_helper++;
        }
        current_ladder += 2;
        if (k & power) {
            neighbors[current_helper].push_back(current_ladder - 2);
        }
        neighbors[current_ladder - 1].push_back(current_ladder);
        neighbors[current_ladder - 2].push_back(current_ladder);
        neighbors[current_ladder - 1].push_back(current_ladder + 1);
        neighbors[current_ladder - 2].push_back(current_ladder + 1);
        power /= 2;
    }
    cout << current_ladder + 1 << endl;
    FOR(i, 1, current_ladder + 2) {
        while (neighbors[i].size() < 2) {
            neighbors[i].push_back(-1);
        }
        cout << neighbors[i][0] << ' ' << neighbors[i][1] << endl;
    }
}