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


using namespace std;


const int B = 30;


int main() {
    ios_base::sync_with_stdio(false);

    int k;
    cin >> k;

    int n = 2;
    vector <pair<int,int>> edges = {{1, 0}};

    int i = B - 1;
    while (!(k & (1 << i))) i--;

    auto pathsDouble = [&]() {
        edges.push_back({n + 1, n});
        edges.push_back({n + 1, n - 1});
        edges.push_back({n, n - 1});

        n += 2;
    };

    auto pathsAddOne = [&]() {
        edges.push_back({n, 0});
        edges.push_back({n, n - 1});

        n++;
    };

    for (i--; i >= 0; i--) {
        pathsDouble();

        if (k & (1 << i)) {
            pathsAddOne();
        }
    }

    vector <vector<int>> g(n);
    for (auto &e : edges) {
        g[e.first].push_back(e.second);
    }

    cout << n << '\n';

    for (int v = n - 1; v >= 0; v--) {
        g[v].resize(2, -1);

        for (int u : g[v]) {
            cout << (u != -1 ? n - u : -1) << ' ';
        }

        cout << '\n';
    }

    return 0;
}