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
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Pii = pair<int,int>;
using Vi = vector<int>;
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define rep(i,b,e) for (int i = (b); i < (e); i++)
#define each(a,x) for (auto& a : (x))
#define all(x) (x).begin(),(x).end()
#define sz(x) int((x).size())
#define endl '\n'

int le[101];
int ri[101];

int prepare() {
    for (int i = 2; i <= 30; i++) {
        le[2*i] = 2*i - 2;
        ri[2*i] = 2*i - 1;
        le[2*i+1] = 2*i - 2;
        ri[2*i+1] = 2*i - 1;
    }
    return 1 + 2*30;
}

vector<Vi> adj;
vector<int> dp;
int dfs(int a) {
    if (dp[a] != -1) {
        return dp[a];
    }
    int res = 0;
    for (int v : adj[a]) {
        res += dfs(v);
    }
    dp[a] = res;
    return res;
}
void check(int n, int k) {
    adj.resize(n+1);
    dp.resize(n+1, -1);
    dp[n] = 1;
    for (int i = 1; i <= n; i++) {
        if (le[i] != 0 && ri[i] != 0) assert(le[i] != ri[i]);
        if (le[i] != 0) {
            adj[i].push_back(le[i]);
        }
        if (ri[i] != 0) {
            adj[i].push_back(ri[i]);
        }
    }
    int c = dfs(1);
    cout << c << endl;
    assert(c == k);

}

void solve() {
    int n = prepare();
    int k;
    cin >> k;
    int cur = 1;
    for (int i = 0; i < 30; i++) {
        if ((k >> i) & 1) {
            n++;
            le[cur] = 2*(i+1);
            ri[cur] = n;
            cur = n;
        }
    }
    n++;
    le[2] = n;
    le[3] = n;
    //check(n, k);
    cout << n << endl;
    for (int i = 1; i <= n; i++) {
        cout << (le[i] != 0 ? le[i] : -1) << " " << (ri[i] != 0 ? ri[i] : -1) << endl;
    }
}

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cout << fixed << setprecision(10);
    int t = 1; 
    //cin >> t;
    for (int i = 0; i < t; i++) {
        solve();
    }
}