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 <stdio.h>

#define BITOW 32

int main() {
	int k;
	scanf("%d", &k);
	printf("%d\n", 3*BITOW);
	fprintf(stderr, "digraph {\n");

	for (int i = 1; i < BITOW; ++i) {
		int a = 2*i;
		int b = 2*i+1;
		int aBit = 2*BITOW - 1 - a;
		int bBit = 2*BITOW - 1 - b;
		int aZapalony = (aBit >= BITOW) || ((aBit < BITOW-1) && (k & (1 << aBit)));
		int bZapalony = (bBit >= BITOW) || ((bBit < BITOW-1) && (k & (1 << bBit)));
		//printf("a:%d, aBit:%d, aZap: %d\n", a, aBit, aZapalony);
		//printf("b:%d, bBit:%d, bZap: %d\n", b, bBit, bZapalony);
		if (aZapalony) {
			fprintf(stderr, "%d -> %d\n", i, a);
		}
		if (bZapalony) {
			fprintf(stderr, "%d -> %d\n", i, b);
		}
		printf("%d %d\n", (aZapalony? a:-1), (bZapalony? b: -1));
	}

	for (int i = BITOW; i < 2*BITOW-1; ++i) {
		int a = i + 1;
		int b = i + BITOW+1;
		if (a == 2*BITOW) {
			a = -1;
		}
		if (0 < a) {
			fprintf(stderr, "%d -> %d\n", i, a);
		}
		fprintf(stderr, "%d -> %d\n", i, b);
		printf("%d %d\n", a, b);
	}

	fprintf(stderr, "%d -> %d\n", 2*BITOW-1, 3*BITOW);
	printf("%d -1\n", 3*BITOW);

	for (int i = 2*BITOW; i < 3*BITOW-1; ++i) {
		int a = i + 1;
		int b = i - BITOW+1;
		if (a == 2*BITOW) {
			a = -1;
		}
		if (0 < a) {
			fprintf(stderr, "%d -> %d\n", i, a);
		}
		fprintf(stderr, "%d -> %d\n", i, b);
		printf("%d %d\n", a, b);
	}

	fprintf(stderr, "%d -> %d\n", 3*BITOW-1, 3*BITOW);
	printf("%d -1\n", 3*BITOW);
	printf("-1 -1\n");

	fprintf(stderr, "}\n");
}