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: Wrong Answer)

#include<bits/stdc++.h>
#define N 805
using namespace std;
int n,d1,d2,kk,pos[N][N],head[N*N],col1[N*N],col2[N*N],color[N*N];
bitset<N*N>bt1,bt2,bt3,bt4,tmp1,tmp2,tmp3,tmp4;
struct Node{int x,y;}p[N*N];
struct Edge{int nxt,to;}e[N*N*8];
vector<Node>G[3];
map<int,int>mp[N*N];
inline int getid(int x,int y){x++;y++;return (x-1)*(2*n)+y;}
inline int up(int x,int y){return x+y;}
inline int down(int x,int y){return x-y;}
inline void link(int x,int y){e[++kk].nxt=head[x];e[kk].to=y;head[x]=kk;}
inline void add(int x,int y){if(x==y)return;if(!mp[x][y])mp[x][y]=1,link(x,y);if(!mp[y][x])mp[y][x]=1,link(y,x);}
void dfs(int u,int col){
	color[u]=col;
	for (int i=head[u];i;i=e[i].nxt){
		int v=e[i].to;
		if (color[v]) continue;
		dfs(v,3-col);
	}
}
inline void print(bitset<N*N> xx){
	int tot=0;
	for (int i=1;i<=4*n*n;i++){
		//cerr<<i<<endl;
		if (xx[i]) printf("%d %d\n",p[i].x,p[i].y),tot++;
		//cerr<<tot<<endl;
		if (tot==n*n) return;
	}
}
inline int pd(int x,int y){return (x<2*n&&x>=0&&y<2*n&&y>=0);}
inline void debug(){
	for (int i=1;i<=4*n*n;i++)
		printf("%d %d %d\n",p[i].x,p[i].y,col1[i]);
	
	int u=1;printf("sta %d %d\n",p[u].x,p[u].y);
	for (int i=head[u];i;i=e[i].nxt){
		int v=e[i].to;
		printf("wtf %d %d\n",p[v].x,p[v].y);
	}
}
int main(){
	//freopen("get.out","w",stdout);
	scanf("%d%d%d",&n,&d1,&d2);
	for (int i=0;i<2*n;i++)
		for (int j=i;j<2*n;j++){
			if (i*i+j*j==d1) G[1].push_back((Node){i,j});
			else if (i*i+j*j==d2) G[2].push_back((Node){i,j});
		}
	//printf("%d %d\n",G[1].size(),G[2].size());return 0;
	for (int i=0;i<2*n;i++)
		for (int j=0;j<2*n;j++) pos[i][j]=getid(i,j),p[getid(i,j)]=(Node){i,j};
	for (int i=0;i<2*n;i++){
		for (int j=0;j<2*n;j++){
			for (int k=0;k<(int)G[1].size();k++){
				int tx=G[1][k].x;int ty=G[1][k].y;
				int x=up(i,tx);int y=up(j,ty);
				if (pd(x,y)) add(pos[i][j],pos[x][y]);
				x=up(i,tx);y=down(j,ty);
				if (pd(x,y)) add(pos[i][j],pos[x][y]);
				x=down(i,tx);y=up(j,ty);
				if (pd(x,y)) add(pos[i][j],pos[x][y]);
				x=down(i,tx);y=down(j,ty);
				if (pd(x,y)) add(pos[i][j],pos[x][y]);
			}
		}
	}
	for (int i=1;i<=n*n*4;i++) mp[i].clear();
	for (int i=1;i<=4*n*n;i++) if (!color[i]) dfs(i,1);
	for (int i=1;i<=4*n*n;i++) col1[i]=color[i];
	//debug();
	memset(head,0,sizeof(head));kk=0;
	for (int i=0;i<2*n;i++){
		for (int j=0;j<2*n;j++){
			for (int k=0;k<(int)G[2].size();k++){
				//cerr<<"now:"<<kk<<endl;
				int tx=G[2][k].x;int ty=G[2][k].y;
				int x=up(i,tx);int y=up(j,ty);
				if (pd(x,y)) add(pos[i][j],pos[x][y]);
				//cerr<<"now1:"<<kk<<endl;
				x=up(i,tx);y=down(j,ty);
				if (pd(x,y)) add(pos[i][j],pos[x][y]);
				//cerr<<"now2:"<<kk<<endl;
				x=down(i,tx);y=up(j,ty);
				if (pd(x,y)) add(pos[i][j],pos[x][y]);
				//cerr<<"now3:"<<kk<<endl;
				x=down(i,tx);y=down(j,ty);
				if (pd(x,y)) add(pos[i][j],pos[x][y]);
				//cerr<<"now4:"<<kk<<endl;
			}
			//if (i==0) cerr<<kk<<endl;
		}
		//cerr<<kk<<endl;
	}
	memset(color,0,sizeof(color));
	for (int i=1;i<=4*n*n;i++) if (!color[i]) dfs(i,1);
	for (int i=1;i<=4*n*n;i++) col2[i]=color[i];
	for (int i=1;i<=4*n*n;i++){
		if (col1[i]==1) bt1[i]=1;
		else bt2[i]=1;
	}
	for (int i=1;i<=4*n*n;i++){
		if (col2[i]==1) bt3[i]=1;
		else bt4[i]=1;
	}
	tmp1=bt1&bt3;tmp2=bt1&bt4;tmp3=bt2&bt3;tmp4=bt2&bt4;
	if ((int)tmp1.count()>=n*n) print(tmp1);
	else if ((int)tmp2.count()>=n*n) print(tmp2);
	else if ((int)tmp3.count()>=n*n) print(tmp3);
	else if ((int)tmp4.count()>=n*n) print(tmp4);
	//cerr<<kk<<endl;
	return 0;
}