Problem:
Score : 800 points

Problem Statement

Takahashi is doing a research on sets of points in a plane.
Takahashi thinks a set S of points in a coordinate plane is a good set when S satisfies both of the following conditions:

The distance between any two points in S is not \sqrt{D_1}.

The distance between any two points in S is not \sqrt{D_2}.

Here, D_1 and D_2 are positive integer constants that Takahashi specified.

Let X be a set of points (i,j) on a coordinate plane where i and j are integers and satisfy 0 ≤ i,j < 2N.

Takahashi has proved that, for any choice of D_1 and D_2, there exists a way to choose N^2 points from X so that the chosen points form a good set.
However, he does not know the specific way to choose such points to form a good set.
Find a subset of X whose size is N^2 that forms a good set.

Constraints

1 ≤ N ≤ 300

1 ≤ D_1 ≤ 2×10^5

1 ≤ D_2 ≤ 2×10^5

All values in the input are integers.

Input

Input is given from Standard Input in the following format:

N D_1 D_2

Output

Print N^2 distinct points that satisfy the condition in the following format:

x_1 y_1
x_2 y_2
:
x_{N^2} y_{N^2}

Here, (x_i,y_i) represents the i-th chosen point.
0 ≤ x_i,y_i < 2N must hold, and they must be integers.
The chosen points may be printed in any order.
In case there are multiple possible solutions, you can output any.

Sample Input 1

2 1 2

Sample Output 1

0 0
0 2
2 0
2 2

Among these points, the distance between 2 points is either 2 or 2\sqrt{2}, thus it satisfies the condition.

Sample Input 2

3 1 5

Sample Output 2

0 0
0 2
0 4
1 1
1 3
1 5
2 0
2 2
2 4

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <bits/stdc++.h>
using namespace std;
#define I(x,y) ((x)*R+(y))
#define rint register int
inline int read(){int r;int s=0,c;for(;!isdigit(c=getchar());s=c);for(r=c^48;isdigit(c=getchar());(r*=10)+=c^48);return s^45?r:-r;}
int n, R, N, S, _, d[2], c[360005]; vector<int> C[2], e[2][360005]; inline void Add(int a, int b){e[_][a].push_back(b), e[_][b].push_back(a);}
void DFS(int p, int t){c[p] ^= 4<<_; t?c[p]|=1<<_:0; for(int v:e[_][p]) if(c[v]&4<<_) DFS(v,!t);}
int main()
{
	n = read(); R = n<<1; N = n*n; S = R*R; d[0] = read(); d[1] = read(); fill(c,c+S,12);
	for(rint i = 0, l, s; i < R; i++) for(_ = 0; _ < 2; l = d[_]-i*i, l>=0&&(s=sqrt(l+.5),s*s==l)&&s<R ? C[_].push_back(i),0 : 0, _++);
	for(rint i = 0, j, k, s; i < R; i++) for(j = 0; j < R; j++) for(_ = 0; _ < 2; _++)
		for(int l:C[_]) s = sqrt(d[_]-l*l+.5), j+s<R ? i+l<R?Add(I(i,j),I(i+l,j+s)),0:0, i>=l?Add(I(i,j),I(i-l,j+s)),0:0 : 0;
	_ = 0; for(rint i = 0; i < S; c[i]&4<<_?DFS(i,0),0:0, i++); _ = 1; for(rint i = 0; i < S; c[i]&4<<_?DFS(i,0),0:0, i++);
	for(rint i = 0, j; i < 4; i++) if(count(c,c+S,i) >= N){for(j = 0; j < S; c[j]==i&&(N-->0)?printf("%d %d\n",j/R,j%R),0:0, j++); return 0;}
}