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
#include <iostream>
#include <vector>
#include <string>
#include <utility>




int main() {
    std::ios::sync_with_stdio(false);

    int k;
    std::cin >> k;

    std::vector<std::vector<int>> dag(103, std::vector<int>(2, -1));
    int n = 1;

    std::vector<int> digits(40, 0);
    int pow = 2;
    for(int i = 0; i < 40; i++) {
        if((k % pow) / (pow/2) == 1)
            digits[i] = 1;
        else
            digits[i] = 0;
        if(pow > k)
            break;
        pow *= 2;
    }

    int first_digit_index = 39;
    while(digits[first_digit_index] == 0)
        first_digit_index--;
    
    int index = first_digit_index - 1;
    while(index >= 0) {
        if(digits[index] == 0) {
            n += 2;
            dag[n][0] = n-2;
            dag[n][1] = n-1;
            dag[n-1][0] = n-2;
        } else {
            n += 3;
            dag[n-1][0] = n-3;
            dag[n-1][1] = n-2;
            dag[n-2][0] = n-3;
            
            dag[n][0] = n-1;
            dag[n][1] = 1;
        }       
        index--;
    }


    if(n == 1) {
        n = 2;
        dag[2][0] = 1;
    }
    for(auto& vec : dag)
        for(auto& val : vec)
            if(val == -1)
                val = n+2;


    std::cout << n << "\n";
    for(int i = n; i > 0; i--) {
        std::cout << n + 1 - dag[i][0] << " " << n + 1 - dag[i][1] << "\n";
    }

    std::cout << std::flush;

    return 0;
}