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

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

    int n;
    std::cin >> n;

    if (n == 1) {
        std::cout << "2\n2 -1\n-1 -1\n";
        return 0;
    }

    std::vector<bool> V;
    while (n > 0) {
        V.push_back(n & 1);
        n >>= 1;
    }

    std::vector<std::vector<int>> G(3 * V.size() - 2);
    for (int i = 0; i < V.size() - 1; i++) {
        G[i].push_back(i + 1);
        if (V[i]) {
            G[i].push_back(V.size() - 1 + (V.size() - i - 1) * 2);
        }
    }
    for (int i = 0; i < V.size() - 1; i++) {
        G[V.size() - 1 + i * 2].push_back(V.size() - 1 + i * 2 + 1);
        G[V.size() - 1 + i * 2].push_back(V.size() - 1 + i * 2 + 2);
        G[V.size() - 1 + i * 2 + 1].push_back(V.size() - 1 + i * 2 + 2);
    }

    std::cout << G.size() << "\n";
    for (auto const& v : G) {
        if (v.size() == 0) std::cout << "-1 -1\n";
        else if (v.size() == 1) std::cout << v[0] + 1 << " -1\n";
        else std::cout << v[0] + 1 << " " << v[1] + 1 << "\n";
    }

    return 0;
}