Language: C++

//#pragma comment(linker, "/STACK:1024000000,1024000000")
/* vim: set fdm=marker */
//{{{
#define __ return
int ATTENTION() {
	/* pls IGNORE this function and go down and HACK me
	 * read this AFTER contest
	 * this function is empty and it will not be called !
	 */

	http://codeforces.com/group/Pmz2A2x7ES
	/* I created a group there.
	 * I hope with the group, people can finish
	 * past contests, which is important for 
	 * increasing rating.
	 * I am still getting familiar with this function.
	 */
	 __ 0;
}
// deprecated because mac doesn't support this...
/* #include <bits/stdc++.h> */
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iomanip>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int iinf = 0x7fffffff;
const ll linf = ~(1LL<<63);
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef map<ll, int> mli;
typedef map<ll, ll> mll;
template<typename T>
inline T gcd(T a, T b) {
	if(a < 0) return gcd(-a, b);
	if(b < 0) return gcd( a,-b);
	if(a < b) return gcd(b, a);
	if(b == 0) return a;
	return gcd(b, a%b);
}

ll qpow(ll a, ll n, ll mod) {
	a %= mod;
	ll ans = 1LL;
	while(n) {
		if(n & 1) ans = (ans*a % mod);
		a = (a*a % mod);
		n >>= 1;
	}
	return ans;
}

inline ll rev(ll a, ll p) {
	return qpow(a, p - 2, p);
}

#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define rep(x, st, en) for(int x = st; x < en; x++)
#define rer(x, st, en) for(int x = st; x >= en; x--)
#define pb push_back
#define mp make_pair
#define dbgm(msg, var) cerr<<#msg<<" "<<#var<<" = "<<var<<endl; 
#define dbg(var) cerr<<#var<<" = "<<var<<endl;
#define X first
#define Y second
// build prefix sum
template<typename T>
inline void BPS(T* DST, T* SRC, int N, int s = 0) {
	DST[s] = SRC[s];
	rep(i, 1, N) DST[s + i] = DST[s + i - 1] + SRC[s + i];
}
inline int in() { int x; cin>>x; return x; }
#ifdef ALNDBG
namespace alndbg {
	clock_t s, e;
}
#endif

inline void tic() {
#ifdef ALNDBG
	alndbg::s = clock();
#endif
}

inline void toc() {
#ifdef ALNDBG
	alndbg::e = clock();
	cerr<<1000.0 * (alndbg::e - alndbg::s) / CLOCKS_PER_SEC<<" ms"<<endl;
#endif
}



//}}}

// -------------------- Spliters ------------------------
// BFS求最短路小心vis可能访问过
const int maxn = 300;

vector<int> E1[4*maxn*maxn];
vector<int> E2[4*maxn*maxn];
bool vis[4*maxn*maxn];
int color[4*maxn*maxn];

int encode(int x, int y, int N) {
  return x * N + y;
}

void build_graph(int D, int N, int bit, vector<int> E[4*maxn*maxn]) {
for(int x = 0; x < 2 * N; x++) {
    for(int y = 0; y < 2 * N; y++) {
      for(int X = x; X < 2 * N; X++) {
        // (X - x)^2 + (Y - y)^2 = D1
        int dx2 = (X - x) * (X - x);
        if(D < dx2) continue;
        int dy2 = D - dx2;

        int dy = sqrt(dy2);

        if(dy * dy != dy2) continue;

        int Y = y + dy;

        if(Y >= 2 * N) continue;

        int u = encode(x, y, 2*N);
        int v = encode(X, Y, 2*N);

        //E[u].pb(v);
        //E[v].pb(u);
        if((color[u] & (1<<bit)) == 0 && (color[v] & (1 << bit) == 0) {
          color[v] |= 1 << bit;
        }
        
      }
    }
  }
}

void dfs(int n, int c0, int c1, int c, vector<int> E[4*maxn*maxn]) {
  vis[n] = 1;
  if(c == 0) color[n] |= c0;
  else color[n] |= c1;
  for(auto to : E[n]) {
    if(vis[to]) continue;
    dfs(to, c0, c1, c ^ 1, E);
  }
}

int main() {
  int N, D1, D2;
  scanf("%d%d%d", &N, &D1, &D2);
  build_graph(D1, N, 0, E1);
  build_graph(D2, N, 1, E2);
  /*
  rep(i,0,2) {
    memset(vis, 0, sizeof(vis));
    rep(n,0,4*N*N) {
      if(!vis[n]) {
        if(i == 0) dfs(n, 0, 1, 0, E1);
        else dfs(n, 0, 2, 0, E2);
      }
    }
  }
  */

  int cnt[4] = {0, 0, 0, 0};

  int c = -1;
  for(int i = 0; i < 4*N*N; i++) {
    cnt[color[i]]++;
    if(cnt[color[i]] >= N * N) {
      c = color[i];
      break;
    }
  }
  for(int i = 0, cnt = 0; cnt < N * N; i++) {
    if(color[i] == c) {
      printf("%d %d\n", i / (2*N), i % ( 2 * N ));
      cnt++;
    }
  }

	return 0;
}
// --USE C++11
// *-USE O2



Compiler output:
a.cc: In function 'void build_graph(int, int, int, std::vector<int>*)':
a.cc:155:70: error: expected ')' before '{' token
  155 |         if((color[u] & (1<<bit)) == 0 && (color[v] & (1 << bit) == 0) {
      |           ~                                                          ^~
      |                                                                      )
a.cc:159:7: error: expected primary-expression before '}' token
  159 |       }
      |       ^