Language: C++

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

#define int long long

vector<pair<int, int>> apply(vector<pair<int, int>> v, int x) {
    int n = (int)v.size();
    vector<vector<int>> g(n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            int dx = v[i].first - v[j].first;
            int dy = v[i].second - v[j].second;
            if (dx * dx + dy * dy == x) {
                g[i].push_back(j);
            }
        }
    }
    vector<int> used(n);
    vector<int> cl(n);
    vector<int> lol(2);
    function<void(int, int)> dfs = [&](int cur, int c) {
        used[cur] = 1;
        cl[cur] = c;
        lol[c]++;
        for (auto t : g[cur]) {
            if (!used[t]) {
                dfs(t, c ^ 1);
            }
        }
    };
    for (int i = 0; i < n; i++) {
        if (!used[i]) {
            dfs(i, 0);
        }
    }
    int mx = 0;
    if (lol[1] > lol[0]) mx = 1;
    vector<pair<int, int>> tk;
    for (int i = 0; i < n; i++) {
        if (cl[i] == mx) {
            tk.push_back(v[i]);
        }
    }
    return tk;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    n *= 2;
    int d1, d2;
    cin >> d1 >> d2;
    if (d1 % 2 < d2 % 2) {
        swap(d1, d2);
    }
    if (d2 % 2 == 1) {
        for (int i = 0; i < n; i += 2) {
            for (int j = 0; j < n; j += 2) {
                cout << i << ' ' << j << endl;
            }
        }
        exit(0);
    }
    vector<pair<int, int>> v;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (d1 % 2) {
                if ((i + j) % 2 == 0) {
                    v.push_back({i, j});
                }
            } else {
                v.push_back({i, j});
            }
        }
    }
    if (d1 % 2 == 0) {
        v = apply(v, d1);
    }
    v = apply(v, d2);
    for (int i = 0; i < n * n / 4; i++) {
        cout << v[i].first << ' ' << v[i].second << '\n';
    }
}   


Compiler output:
a.cc: In function 'std::vector<std::pair<long long int, long long int> > apply(std::vector<std::pair<long long int, long long int> >, long long int)':
a.cc:41:5: error: 'function' was not declared in this scope
   41 |     function<void(int, int)> dfs = [&](int cur, int c) {
      |     ^~~~~~~~
a.cc:21:1: note: 'std::function' is defined in header '<functional>'; this is probably fixable by adding '#include <functional>'
   20 | #include <random>
  +++ |+#include <functional>
   21 | 
a.cc:41:27: error: expression list treated as compound expression in functional cast [-fpermissive]
   41 |     function<void(int, int)> dfs = [&](int cur, int c) {
      |                           ^
a.cc:41:14: error: expected primary-expression before 'void'
   41 |     function<void(int, int)> dfs = [&](int cur, int c) {
      |              ^~~~
a.cc:53:13: error: 'dfs' was not declared in this scope; did you mean 'ffs'?
   53 |             dfs(i, 0);
      |             ^~~
      |             ffs