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

using namespace std;

const int N = 5007;
const int M = 5000;
const int MX = 1e9 + 7;

int n, k;
int out[N][2];

void add() {
	++n;
	out[n][0] = out[n][1] = -1;
}

int main() {
	scanf("%d", &k);
	add();
	add();
	
	out[1][0] = 2;
	
	int last = 2;
	int last_on_path = 1;
	
	if(k == 1) {
		puts("2");
		puts("2 -1");
		puts("-1 -1");
		exit(0);
	}
	
	vector <int> bits;
	while(k) {
		bits.push_back(k & 1);
		k /= 2;
	}
	
	bits.pop_back();
	reverse(bits.begin(), bits.end());
	
	for(auto v: bits) {
		if(v == 1) {
			add();
			out[last_on_path][1] = n;
			last_on_path = n;
		}

		add();
		add();
		
		out[last][0] = n - 1;
		out[last][1] = n;
		out[n - 1][0] = n;
		last = n;
		
		if(v == 1)
			out[last_on_path][0] = last;
	}
	
	printf("%d\n", n);
	for(int i = 1; i <= n; ++i)
		printf("%d %d\n", out[i][0], out[i][1]);
	return 0;
}