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
71
72
73
74
75
76
77
78
79
80
#include <iostream>
#include <climits>
#include <vector>

using namespace std;

const int N = 1 << 7;

int k;

int n = 0; 
int G[N][2];
vector<int> V;

void init() {
    cin >> k;
}
        
void solve() {
    if (k == 1) {
        n = 2;
        G[1][0] = 2;
        G[1][1] = -1;
        G[2][0] = -1;
        G[2][1] = -1;    
    } else {
        n = 1;
        
        if ((k & 1) == 1) {
            n = 2;
            G[1][0] = 2;
            V.push_back(1);
        }
        
        k >>= 1;
                
        while (k > 0) {
            G[n][0] = n + 1;
            G[n][1] = n + 2;
            G[n+1][0] = n + 3;
            G[n+1][1] = -1;
            G[n+2][0] = n + 3;
            G[n+2][1] = -1;
    
            if ((k & 1) == 0 || k == 1) {
                n += 3;
            } else {
                G[n+3][0] = n + 4;
                V.push_back(n+3);
                n += 4;
            }
            
            k >>= 1;
        }
        
        G[n][0] = -1;
        G[n][1] = -1;
        
        for (int i=0; i<V.size(); i++) {
            G[V[i]][1] = n;
        }
    }
    
    cout << n << '\n';

    for (int i=1; i<=n; i++) {
        cout << G[i][0] << ' ' << G[i][1] << '\n';    
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    init();
    solve();

    return 0;
}