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
#include <iostream>
#include <vector>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int k;
    cin >> k;

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

    int head=1;
    vector<vector<int>> G(2);

    while(k>1){
        if(k%2==1){
            G.emplace_back();
            G[head].push_back(-42);
            G[head].push_back(head+1);
            head++;
            k--;
        }
        else{
            G.emplace_back();
            G.emplace_back();
            G[head].push_back(head+1);
            G[head].push_back(head+2);
            G[head+1].push_back(head+2);
            head+=2;
            k/=2;
        }
    }

    cout << head << "\n";
    for(int i=1;i<=head;i++){
        for(int j=0;j<2;j++)
            if(j>=(int)G[i].size())
                cout << "-1 ";
            else if(G[i][j]==-42)
                cout << head << " ";
            else
                cout << G[i][j] << " ";
        cout << "\n";
    }

    return 0;
}