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

int main() {
	int k;
	std::cin >> k;

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

	int highest_bit = 0;
	std::vector<bool> exists(31, false);
	for (int b = 0; b <= 30; ++b) {
		if (k&(1<<b)) {
			highest_bit = b;
			exists[b] = true;
		}
	}

	int nodes = 1 + 3 * highest_bit;
	if (highest_bit&&exists[highest_bit - 1]) {
		nodes++;	
	}
	std::cout << nodes << '\n';
	for (int i = 1; i < nodes - 1; i++) {
		int layer = i / 3;
		if (i % 3 == 1) {
			std::cout << i + 1 << " " << i + 2 << '\n';
		}
		if (i % 3 == 2) {
			std::cout << i + 2 << " ";
			std::cout << (exists[layer] ? nodes : -1) << '\n';
		}
		if (i % 3 == 0) {
			std::cout << i + 1 << " " << -1 << '\n';
		}
	}
	std::cout << nodes << " -1\n";
	std::cout << "-1 -1\n";
	return 0;
}