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

#define debug if(1)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

typedef long long int ll;

int k, maxbit, ilebitow, v = 1, n;
bitset <32> bit;
pair <int, int> E[105];

void ustaw_bity(int k) {
    int p = 1;
    int nr = 0;
    
    while (p <= k) {
        bit[nr] = (k & p);
        ilebitow = (k & p) ? ilebitow + 1 : ilebitow;
        p <<= 1;
        ++nr;
    }
    
    maxbit = nr - 1;
}

void krawedz(int x, int lewy, int prawy) {
    E[x] = {lewy, prawy};
}

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> k;
    
    if (k == 1) {
        printf ("2\n2 -1\n-1 -1");
        return 0;
    }
    
    ustaw_bity(k);
    
    n = 1 + ilebitow + 3 * maxbit;
    
    for (int i = 0; i < maxbit; ++i) {
        krawedz(3 * i + 1, 3 * i + 2, 3 * i + 3);
        krawedz(3 * i + 2, -1, 3 * i + 4);
        
        if (bit[i]) {
            krawedz(3 * i + 3, 3 * i + 4, n - ilebitow + 1);
            krawedz(n - ilebitow + 1, n, -1);
            --ilebitow;
        } else {
            krawedz(3 * i + 3, 3 * i + 4, -1);
        }
    }
    krawedz(3 * maxbit + 1, -1, n);
    krawedz(n, -1, -1);
    
    printf ("%d\n", n);
    for (int i = 1; i <= n; ++i) {
        printf ("%d %d\n", E[i].ff, E[i].ss);
    }

    return 0;
}