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
#include <bits/stdc++.h>
using namespace std;
const int nax = 1 << 14;
bitset<nax> pion[nax], poziom[nax];
int query[100123];
int main() {
	pion[1][2] = pion[3][2] = true;
	poziom[2][3] = true;
	int n;
	scanf("%d", &n);
	int side = 4;
	for(int rep = 0; rep < n - 1; ++rep) {
		//printf("rep = %d, side = %d\n", rep, side); fflush(stdout);
		for(int i = 1; i < side; ++i)
			for(int j = 1; j < side; ++j) {
				pion[i][j+side] = pion[i+side][j+side] = pion[i][j];
				poziom[i][j+side] = poziom[i+side][j+side] = poziom[i][j];
				pion[side+(side-j)][i] = poziom[i][j];
				poziom[side+(side-j)][i] = pion[i][j];
			}
		for(int i = 1; i < side; ++i)
			for(int j = 1; j < side; ++j) {
				pion[i][j] = pion[2*side-i][side-j];
				poziom[i][j] = poziom[2*side-i][side-j];
			}
		pion[1][side] = pion[2*side-1][side] = poziom[side][side+1] = true;
		side *= 2;
	}
	
	/*for(int y = side; y >= 0; --y) {
		for(int x = 0; x <= side; ++x) {
			if(poziom[x][y]) printf("-");
			else if(pion[x][y]) printf("|");
			else printf(" ");
		}
		puts("");
	}*/
	int x = 1, y = 0;
	int dx = 1, dy = 1;
	int q;
	scanf("%d", &q);
	for(int i = 0; i < q; ++i) scanf("%d", &query[i]);
	int pointer = 0;
	for(int i = 0; true; ++i) {
		while(i == query[pointer]) {
			printf("%d %d\n", x, y);
			++pointer;
			if(pointer == q) return 0;
		}
		x += dx;
		y += dy;
		if(pion[x][y] || x == 0 || x == side) dx *= -1;
		else if(poziom[x][y] || y == 0 || y == side) dy *= -1;
	}
}