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
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <iostream>
#include <vector>

using namespace std;

int vertices;
std::vector<std::vector<int>> g;

int paths;

void count_until(int s, int d) {
    if (s == d) {
        paths++;
    } else {
        for (auto i: g[s]) {
            count_until(i, d);
        }
    }
}


int last_free;
void generate(int k) {
//    printf("%d\n", k);
    if (k == 1) {
        return;
    }
    if (k % 2 == 0) {
        g.at(last_free).push_back(last_free + 1);
        g.at(last_free).push_back(last_free + 2);
        g.at(last_free + 1).push_back(last_free + 2);
        last_free += 2;
        generate(k / 2);
    } else {
        int remember = last_free;
        g.at(last_free).push_back(last_free + 1);
        last_free += 1;
        generate(k - 1);

        g.at(remember).push_back(last_free);
    }
}

int main() {
    int required = 100139007;
    cin >> required;
//    for (int required = 1; required <= 1000000000; ++required) {
        g.clear();
        g.resize(105);

        g.at(1).push_back(2);
        last_free = 2;
        generate(required);

        vertices = last_free;

        printf("%d\n", last_free);
//        if (last_free < 2 || last_free > 100) {
//            printf("%d\n", last_free);
//            printf("%d\n", required);
//            exit(1);
//        }
        for (int i = 1; i <= vertices; ++i) {
            if (g[i].size() > 2) {
                exit(1);
            }
            if (g[i].size() == 0) {
                printf("-1 -1\n");
            } else if (g[i].size() == 1) {
                printf("%d -1\n", g[i][0]);
            } else if (g[i].size() == 2) {
                printf("%d %d\n", g[i][0], g[i][1]);
            } else {
                printf("yyyyyyyyyyyyy\n");
                exit(1);
            }
        }

//    paths = 0;
//    count_until(1, vertices);
//
//    if (paths % 100 == 0) {
////            cout << "count: ";
//        cout << paths << endl;
//    }
//
//    if (paths != required) {
//        exit(1);
//    }

//    }
    return 0;
}