Language: C++

#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=600+10;
struct point{int x,y;}li[maxn*maxn];
int tmp;
int co[2][maxn][maxn],n,d1,d2;
void dfs(int x,int y,int l){
	REP(i,1,tmp){
		int u=x+li[i].x,v=y+li[i].y;
		if(u>=2*n || v>=2*n || u<0 || v<0) continue;
		if(co[l][u][v]==-1) co[l][u][v]=co[l][x][y]^1,dfs(u,v,l);
	}
}
int main(){
	n=read(),d1=read(),d2=read();
	for(int i=0;i*i<=d1;++i){
		int j=sqrt(d1-i*i);
		while(j*j+i*i>d1) --j;
		while(j*j+i*i<d1) ++j;
		if(i*i+j*j!=d1) continue;
		li[++tmp]=(point){i,j};
		li[++tmp]=(point){-i,j};
		li[++tmp]=(point){i,-j};
		li[++tmp]=(point){-i,-j};
	}
	REP(l,0,1) REP(i,0,2*n-1) REP(j,0,2*n-1) co[l][i][j]=-1;
	REP(i,1,2*n-1) REP(j,0,2*n-1) if(co[0][i][j]==-1) co[0][i][j]=0,dfs(i,j,0);
	tmp=0;
	for(int i=0;i*i<=d2;++i){
		int j=sqrt(d2-i*i);
		while(j*j+i*i>d2) --j;
		while(j*j+i*i<d2) ++j;
		if(i*i+j*j!=d2) continue;
		li[++tmp]=(point){i,j};
		li[++tmp]=(point){-i,j};
		li[++tmp]=(point){i,-j};
		li[++tmp]=(point){-i,-j};
	}
	REP(i,0,2*n-1) REP(j,0,2*n-1) if(co[1][i][j]==-1) co[1][i][j]=0,dfs(i,j,1);
	REP(u,0,1) REP(v,0,1){
		int sum=0;
		REP(i,0,2*n-1) REP(j,0,2*n-1) if(co[0][i][j]==u && co[1][i][j]==v) ++sum;
		if(sum>=n*n){
			sum=n*n;
			REP(i,0,2*n-1) REP(j,0,2*n-1) if(co[0][i][j]==u && co[1][i][j]==v){
				printf("%d %d\n",i,j);
				--sum;
				if(!sum) return 0;
			}
		}
	}
	return 0;
}
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=600+10;
struct point{int x,y;}li[maxn*maxn];
int tmp;
int co[2][maxn][maxn],n,d1,d2;
void dfs(int x,int y,int l){
	REP(i,1,tmp){
		int u=x+li[i].x,v=y+li[i].y;
		if(u>=2*n || v>=2*n || u<0 || v<0) continue;
		if(co[l][u][v]==-1) co[l][u][v]=co[l][x][y]^1,dfs(u,v,l);
	}
}
int main(){
	n=read(),d1=read(),d2=read();
	for(int i=0;i*i<=d1;++i){
		int j=sqrt(d1-i*i);
		while(j*j+i*i>d1) --j;
		while(j*j+i*i<d1) ++j;
		if(i*i+j*j!=d1) continue;
		li[++tmp]=(point){i,j};
		li[++tmp]=(point){-i,j};
		li[++tmp]=(point){i,-j};
		li[++tmp]=(point){-i,-j};
	}
	REP(l,0,1) REP(i,0,2*n-1) REP(j,0,2*n-1) co[l][i][j]=-1;
	REP(i,1,2*n-1) REP(j,0,2*n-1) if(co[0][i][j]==-1) co[0][i][j]=0,dfs(i,j,0);
	tmp=0;
	for(int i=0;i*i<=d2;++i){
		int j=sqrt(d2-i*i);
		while(j*j+i*i>d2) --j;
		while(j*j+i*i<d2) ++j;
		if(i*i+j*j!=d2) continue;
		li[++tmp]=(point){i,j};
		li[++tmp]=(point){-i,j};
		li[++tmp]=(point){i,-j};
		li[++tmp]=(point){-i,-j};
	}
	REP(i,0,2*n-1) REP(j,0,2*n-1) if(co[1][i][j]==-1) co[1][i][j]=0,dfs(i,j,1);
	REP(u,0,1) REP(v,0,1){
		int sum=0;
		REP(i,0,2*n-1) REP(j,0,2*n-1) if(co[0][i][j]==u && co[1][i][j]==v) ++sum;
		if(sum>=n*n){
			sum=n*n;
			REP(i,0,2*n-1) REP(j,0,2*n-1) if(co[0][i][j]==u && co[1][i][j]==v){
				printf("%d %d\n",i,j);
				--sum;
				if(!sum) return 0;
			}
		}
	}
	return 0;
}


Compiler output:
a.cc: In function 'void dfs(int, int, int)':
a.cc:31:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   31 |         REP(i,1,tmp){
      |             ^
a.cc:3:39: note: in definition of macro 'REP'
    3 | #define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
      |                                       ^
a.cc:31:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   31 |         REP(i,1,tmp){
      |             ^
a.cc:3:44: note: in definition of macro 'REP'
    3 | #define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
      |                                            ^
a.cc: In function 'int main()':
a.cc:49:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   49 |         REP(l,0,1) REP(i,0,2*n-1) REP(j,0,2*n-1) co[l][i][j]=-1;
      |             ^
a.cc:3:39: note: in definition of macro 'REP'
    3 | #define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
      |                                       ^
a.cc:49:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   49 |         REP(l,0,1) REP(i,0,2*n-1) REP(j,0,2*n-1) co[l][i][j]=-1;
      |             ^
a.cc:3:44: note: in definition of macro 'REP'
    3 | #define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
      |                                            ^
a.cc:49:24: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   49 |         REP(l,0,1) REP(i,0,2*n-1) REP(j,0,2*n-1) co[l][i][j]=-1;
      |                        ^
a.cc:3:39: note: in definition of macro 'REP'
    3 | #define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
      |                                       ^
a.cc:49:24: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   49 |         REP(l,0,1) REP(i,0,2*n-1) REP(j,0,2*n-1) co[l][i][j]=-1;
      |                        ^
a.cc:3:44: note: in definition of macro 'REP'
    3 | #define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
      |                                            ^
a.cc:49:39: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   49 |         REP(l,0,1) REP(i,0,2*n-1) REP(j,0,2*n-1) co[l][i][j]=-1;
      |                                       ^
a.cc:3:39: note: in definition of macro 'REP'
    3 | #define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
      |                                       ^
a.cc:49:39: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   49 |         REP(l,0,1) REP(i,0,2*n-1) REP(j,0,2*n-1) co[l][i][j]=-1;
      |                                       ^
a.cc:3:44: note: in definition of macro 'REP'
    3 | #define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
      |                                            ^
a.cc:50:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   50 |         REP(i,1,2*n-1) REP(j,0,2*n-1) if(co[0][i][j]==-1) co[0][i][j]=0,dfs(i,j,0);
      |             ^
a.cc:3:39: note: in definition of macro 'REP'
    3 | #define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
      |                                       ^
a.cc:50:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   50 |         REP(i,1,2*n-1) REP(j,0,2*n-1) if(co[0][i][j]==-1) co[0][i][j]=0,dfs(i,j,0);
      |             ^
a.cc:3:44: note: in definition of macro 'REP'
    3 | #define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
      |                                            ^
a.cc:50:28: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   50 |         REP(i,1,2*n-1) REP(j,0,2*n-1) if(co[0][i][j]==-1) co[0][i][j]=0,dfs(i,j,0);
      |                            ^
a.cc:3:39: note: in definition of macro 'REP'
    3 | #define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
      |                                       ^
a.cc:50:28: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   50 |         REP(i,1,2*n-1) REP(j,0,2*n-1) if(co[0][i][j]==-1) co[0][i][j]=0,dfs(i,j,0);
      |                            ^
a.cc:3:44: note: in definition of macro 'REP'
    3 | #define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
      |                                            ^
a.cc:62:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   62 |         REP(i,0,2*n-1) REP(j,0,2*n-1) if(co[1][i][j]==-1) co[1][i][j]=0,dfs(i,j,1);
      |             ^
a.cc:3:39: note: in definition of macro 'REP'
    3 | #define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
      |                                       ^
a.cc:62:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   62 |         REP(i,0,2*n-1) REP(j,0,2*n-1) if(co[1][i][j]==-1) co[1][i][j]=0,dfs(i,j,1);
      |             ^
a.cc:3:44: note: in definition of macro 'REP'
    3 | #define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
      |                                            ^
a.cc:62:28: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   62 |         REP(i,0,2*n-1) REP(j,0,2*n-1) if(co[1][i][j]==-1) co[1][i][j]=0,dfs(i,j,1);
      |                            ^
a.cc:3:39: note: in definition of macro 'REP'
    3 | #define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
      |                                       ^
a.cc:62:28: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   62 |         REP(i,0,2*n-1) REP(j,0,2*n-1) if(co[1][i][j]==-1) co[1][i][j]=0,dfs(i,j,1);
      |                            ^
a.cc:3:44: note: in definition of macro 'REP'
    3 | #define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
      |                                            ^
a.cc:63:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   63 |         REP(u,0,1) REP(v,0,1){
      |             ^
a.cc:3:39: note: in definition of macro 'REP'
    3 | #define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
      |                                       ^
a.cc:63:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   63 |         REP(u,0,1) REP(v,0,1){
      |             ^
a.cc:3:44: note: in definition of macro 'REP'
    3 | #define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
      |                                            ^
a.cc:63:24: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   63 |         REP(u,0,1) REP(v,0,1){
      |                        ^
a.cc:3:39: note: in definition of macro 'REP'
    3 | #define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
      |                                       ^
a.cc:63:24: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   63 |         REP(u,0,1) REP(v,0,1){
      |                        ^
a.cc:3:44: note: in definition of macro 'REP'
    3 | #define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
      |                                            ^
a.cc:65:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   65 |                 REP(i,0,2*n-1) REP(j,0,2*n-1) if(co[0][i][j]==u && co[1][i][j]==v) ++sum;
      |                     ^
a.cc:3:39: note: in definition of macro 'REP'
    3 | #define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
      |                                       ^
a.cc:65:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   65 |                 REP(i,0,2*n-1) REP(j,0,2*n-1) if(co[0][i][j]==u && co[1][i][j]==v) ++sum;
      |                     ^
a.cc:3:44: note: in definition of macro 'REP'
    3 | #define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
      |                                            ^
a.cc:65:36: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   65 |                 REP(i,0,2*n-1) REP(j,0,2*n-1) if(co[0][i][j]==u && co[1][i][j]==v) ++sum;
      |                                    ^
a.cc:3:39: note: in definition of macro 'REP'
    3 | #define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
      |                                       ^
a.cc:65:36: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   65 |                 REP(i,0,2*n-1) REP(j,0,2*n-1) if(co[0][i][j]==u && co[1][i][j]==v) ++sum;
      |                                    ^
a.cc:3:44: note: in definition of macro 'REP'
    3 | #define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
      |                                            ^
a.cc:68:29: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   68 |                         REP(i,0,2*n-1) REP(j,0,2*n-1) if(co[0][i][j]==u && co[1][i][j]==v){
      |                             ^
a.cc:3:39: note: in definition of macro 'REP'
    3 | #define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
      |                                       ^
a.cc:68:29: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   68 |                         REP(i,0,2*n-1) REP(j,0,2*n-1) if(co[0][i][j]==u && co[1][i][j]==v){
      |                             ^
a.cc:3:44: note: in definition of macro 'REP'
    3 | #define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
      |                                            ^
a.cc:68:44: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   68 |                         REP(i,0,2*n-1) REP(j,0,2*n-1) if(co[0][i][j]==u && co[1][i][j]==v){
      |                                            ^
a.cc:3:39: note: in definition of macro 'REP'
    3 | #define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
      |                                       ^
a.cc:68:44: wa