Language: C++

#include "bits/stdc++.h"
#define ff first
#define ss second
#define szof(_x) ((int) (_x).size())
#define TASK_NAME ""

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9 + 7;
const ll INFL = 1e18 + 123;
const double PI = atan2(0, -1);
mt19937 tw(960172);
ll rnd(ll x, ll y) { static uniform_int_distribution<ll> d; return d(tw) % (y - x + 1) + x; }


void solve() {
	/*
	int val = 0;
	for (int i = 1; i <= 200000; ++i) {
		int cur = 0;
		for (int j = 0; j <= 600 && j * j <= i; ++j) {
			int tmp = i - j * j;
			int l = max(0, (int) sqrt(tmp) - 3), r = l + 6;
			while (r - l > 1) {
				int mid = (l + r) / 2;
				if (mid * mid <= tmp) {
					l = mid;
				} else {
					r = mid;
				}
			}
			if (l * l == tmp) {
				++cur;
			}
		}
		val = max(val, cur * 4 - 4);
		if (i % 1000 == 0) {
			cerr << i << " " << val << endl;
		}
	}
	*/
	int n, d1, d2;
	cin >> n >> d1 >> d2;
	vector<vector<bool>> used(n * 2, vector<bool>(n * 2));
	vector<pii> shifts;
	for (int i = -n * 2 + 1; i < n * 2; ++i) {
		for (int j = -n * 2 + 1; j < n * 2; ++j) {
			if (i * i + j * j == d1 || i * i + j * j == d2) {
				shifts.push_back({i, j});
			}
		}
	}

	vector<vector<int>> cnt(n * 2, vector<int>(n * 2));
	//set<pair<int, pii>> st;
	vector<vector<pii>> here(szof(shifts) + 1);
	for (int i = 0; i < n * 2; ++i) {
		for (int j = 0; j < n * 2; ++j) {
			for (auto p : shifts) {
				int nx = i + p.ff;
				int ny = j + p.ss;
				if (0 <= nx && nx < n * 2 && 0 <= ny && ny < n * 2) {
					++cnt[i][j];
				}
			}
			here[cnt[i][j]].push_back({i, j});
		}
	}
	
	set<int> have;
	for (int i = 0; i < szof(here); ++i) {
		//shuffle(here[i].begin(), here[i].end(), tw);
		if (szof(here[i])) {
			have.insert(i);
		}
	}

	vector<pii> arr;

	while (szof(have)) {
		auto it = *have.begin();
		if (szof(have) > 1 && rnd(0, 10) == 0) {
			++it;
		}
		int lvl = *it;
		int x, y;
		tie(x, y) = here[lvl].back();
		here[lvl].pop_back();
		if (!szof(here[lvl])) {
			have.erase(lvl);
		}
		if (used[x][y]) {
			continue;
		}
		used[x][y] = true;
		arr.push_back({x, y});
		if (szof(arr) == n * n) {
			break;
		}
		for (auto p : shifts) {
			int nx = x + p.ff;
			int ny = y + p.ss;
			if (0 <= nx && nx < n * 2 && 0 <= ny && ny < n * 2 && !used[nx][ny]) {
				used[nx][ny] = true;
				for (auto t : shifts) {
					int nnx = nx + t.ff;
					int nny = ny + t.ss;
					if (0 <= nnx && nnx < n * 2 && 0 <= nny && nny < n * 2 && !used[nnx][nny]) {
						--cnt[nnx][nny];
						if (!szof(here[cnt[nnx][nny]])) {
							have.insert(cnt[nnx][nny]);
						}
						here[cnt[nnx][nny]].push_back({nnx, nny});
					}
				}
			}
		}
	}
	assert(szof(arr) == n * n);
	for (auto p : arr) {
		cout << p.ff << " " << p.ss << "\n";
	}
}


int main() {
	//freopen(TASK_NAME ".in", "r", stdin);
	//freopen(TASK_NAME ".out", "w", stdout);
	cerr << fixed << setprecision(15);
	cout << fixed << setprecision(15);
	ios::sync_with_stdio(false);

	int tests = 1;
	// cin >> tests;
	for (int it = 1; it <= tests; ++it) {
		solve();
	}
	
	#ifdef LOCAL
		cerr << "time: " << clock() << " ms\n";
	#endif
	return 0;
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:86:27: error: invalid type argument of unary '*' (have 'int')
   86 |                 int lvl = *it;
      |                           ^~~