prithivMLmods/Coder-Stat huggingface dataset:
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
/// Code By t_bone_289 (Tushar Singh)
/// An Immature Programmer.... I'm still developing !!
#include <bits/stdc++.h>
using namespace std;
#define pll pair<ll, ll>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef double d;
ll M = 998244353;
ll fact[300100] = {0};

ll powmod(ll a, ll b) {
  a = a % M;
  if (b == 0) {
    return 1;
  }

  else if (b == 1) {
    return a;
  }
  ll ans = 1;
  while (b > 0) {
    if (b & 1) {
      ans = (ans * a) % M;
    }
    b = b >> 1;
    a = (a * a) % M;
  }
  return ans;
}
ll C(ll a, ll b) {
  if (b == 0 || b == a) {
    return 1;
  } else if (b == 1 || (b == (a - 1))) {
    return a;
  }
  ll ans = fact[a] % M;
  ans = ((ans % M) * (powmod(fact[a - b], M - 2) % M)) % M;
  ans = ((ans % M) * (powmod(fact[b], M - 2) % M)) % M;
  return ans;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  fact[0] = 1;
  for (ll i = 1; i <= 300099; i++) {
    fact[i] = ((fact[i - 1] % M) * (i)) % M;
  }
  ll n, a, b, k;
  cin >> n >> a >> b >> k;
  ll ans = 0;
  // cout<<C(4,1)<<endl;
  // cout<<(C(5,3))<<endl;
  for (ll i = 0; i <= n; i++) {
    // cout<<i<<endl;
    ll j = k - (i * a);
    if (j % b == 0) {
      j = j / b;
      // cout<<i<<" "<<j<<endl;

      if ((j) <= n) {
        // cout<<n<<" "<<i<<"--"<<n<<" "<<j<<endl;
        // cout<<((C(n,i)%M)*(C(n,j)))%M<<endl;
        ans = (ans + ((C(n, i) % M) * (C(n, j) % M))) % M;
        // cout<<ans<<endl;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
/// Code By t_bone_289 (Tushar Singh)
/// An Immature Programmer.... I'm still developing !!
#include <bits/stdc++.h>
using namespace std;
#define pll pair<ll, ll>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef double d;
ll M = 998244353;
ll fact[300100] = {0};

ll powmod(ll a, ll b) {
  a = a % M;
  if (b == 0) {
    return 1;
  }

  else if (b == 1) {
    return a;
  }
  ll ans = 1;
  while (b > 0) {
    if (b & 1) {
      ans = (ans * a) % M;
    }
    b = b >> 1;
    a = (a * a) % M;
  }
  return ans;
}
ll C(ll a, ll b) {
  if (b == 0 || b == a) {
    return 1;
  } else if (b == 1 || (b == (a - 1))) {
    return a;
  }
  ll ans = fact[a] % M;
  ans = ((ans % M) * (powmod(fact[a - b], M - 2) % M)) % M;
  ans = ((ans % M) * (powmod(fact[b], M - 2) % M)) % M;
  return ans;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  fact[0] = 1;
  for (ll i = 1; i <= 300099; i++) {
    fact[i] = ((fact[i - 1] % M) * (i)) % M;
  }
  ll n, a, b, k;
  cin >> n >> a >> b >> k;
  ll ans = 0;
  // cout<<C(4,1)<<endl;
  // cout<<(C(5,3))<<endl;
  for (ll i = 0; i <= n; i++) {
    // cout<<i<<endl;
    ll j = k - (i * a);
    if (j % b == 0 && j >= 0) {
      j = j / b;
      // cout<<i<<" "<<j<<endl;

      if ((j) <= n) {
        // cout<<n<<" "<<i<<"--"<<n<<" "<<j<<endl;
        // cout<<((C(n,i)%M)*(C(n,j)))%M<<endl;
        ans = (ans + ((C(n, i) % M) * (C(n, j) % M))) % M;
        // cout<<ans<<endl;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
using namespace std;
typedef long long int ll;
const ll mod = 998244353;
int main() {
  int n;
  ll a, b;
  ll k;
  scanf("%d%lld%lld%lld", &n, &a, &b, &k);
  ll inv[300010];
  ll jun[300010];
  ll gyaku[300010];
  inv[1] = 1;
  for (ll i = 2; i <= n; i++) {
    inv[i] = mod - (mod / i) * inv[mod % i] % mod;
  }
  for (ll i = 1; i <= n; i++) {
    if (i == 1) {
      jun[i] = 1;
      gyaku[i] = 1;
    } else {
      jun[i] = (jun[i - 1] * i) % mod;
      gyaku[i] = (gyaku[i - 1] * inv[i]) % mod;
    }
  }
  ll ans = 0;
  for (ll i = 0; i <= n; i++) {
    if (k - a * i >= 0 && (k - a * i) % b == 0) {
      ll j = (k - a * i) / b;
      ll l, r;
      if (i == 0 || i == n)
        l = 1;
      else
        l = ((jun[n] * gyaku[i]) % mod) * gyaku[n - i] % mod;
      if (j == 0 || j == n)
        r = 1;
      else
        r = ((jun[n] * gyaku[j]) % mod) * gyaku[n - j] % mod;
      ans += l * r % mod;
      ans %= mod;
    }
  }
  printf("%lld\n", ans);
}


Fixed submission:
#include <algorithm>
#include <cstdio>
using namespace std;
typedef long long int ll;
const ll mod = 998244353;
int main() {
  int n;
  ll a, b;
  ll k;
  scanf("%d%lld%lld%lld", &n, &a, &b, &k);
  ll inv[300010];
  ll jun[300010];
  ll gyaku[300010];
  inv[1] = 1;
  for (ll i = 2; i <= n; i++) {
    inv[i] = mod - (mod / i) * inv[mod % i] % mod;
  }
  for (ll i = 1; i <= n; i++) {
    if (i == 1) {
      jun[i] = 1;
      gyaku[i] = 1;
    } else {
      jun[i] = (jun[i - 1] * i) % mod;
      gyaku[i] = (gyaku[i - 1] * inv[i]) % mod;
    }
  }
  ll ans = 0;
  for (ll i = 0; i <= n; i++) {
    if (k - a * i >= 0 && (k - a * i) % b == 0) {
      ll j = (k - a * i) / b;
      if (j > n)
        continue;
      ll l, r;
      if (i == 0 || i == n)
        l = 1;
      else
        l = ((jun[n] * gyaku[i]) % mod) * gyaku[n - i] % mod;
      if (j == 0 || j == n)
        r = 1;
      else
        r = ((jun[n] * gyaku[j]) % mod) * gyaku[n - j] % mod;
      ans += l * r % mod;
      ans %= mod;
    }
  }
  printf("%lld\n", ans);
}
Problem p03333 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 100;
const int C = 1e5 + 10;

int a[N], b[N];

int main() {
  int n;
  scanf("%d", &n);
  a[C]++;
  b[C]++;
  for (int i = 0; i < n; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    l += C;
    r += C;
    a[l]++;
    b[r]++;
  }
  for (int i = N - 2; i >= 0; i--)
    a[i] += a[i + 1];
  for (int i = 1; i < N; i++)
    b[i] += b[i - 1];
  long long ans = 0;
  for (int i = 0; i < N; i++)
    ans += min(a[i + 1], b[i]);
  printf("%lld", ans * 2);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

const int N = 2e5 + 100;
const int C = 1e5 + 10;

int a[N], b[N];

int main() {
  int n;
  scanf("%d", &n);
  a[C]++;
  b[C]++;
  for (int i = 0; i < n; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    l += C;
    r += C;
    a[l]++;
    b[r]++;
  }
  for (int i = N - 2; i >= 0; i--)
    a[i] += a[i + 1];
  for (int i = 1; i < N; i++)
    b[i] += b[i - 1];
  long long ans = 0;
  for (int i = 0; i < N; i++)
    ans += min(a[i + 1], b[i]);
  printf("%lld", ans * 2);
  return 0;
}
Problem p03333 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <numeric>
#include <vector>
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, a) repi(i, 0, a)
#define all(a) (a).begin(), (a).end()

constexpr int MAX_N = 100000;

using ll = long long;

ll N;
ll L[MAX_N], R[MAX_N];
std::vector<ll> ls = {0}, rs = {0};

int main() {
  scanf("%lld", &N);
  rep(i, N) {
    scanf("%lld%lld", L + i, R + i);

    if (!(L[i] <= 0 && 0 <= R[i])) {
      ls.push_back(L[i]);
      rs.push_back(R[i]);
    }
  }

  std::sort(ls.rbegin(), ls.rend());
  std::sort(all(rs));

  // 5,3,1,0
  // 0,2,4,6

  ll rS = 0, lS = 0;
  ll ans = 0;
  rep(k, N) {
    if (ls[k] > rs[k]) {
      lS += ls[k];
      rS += rs[k];
    }

    ans = std::max(ans, 2 * (lS - rS));
  }

  printf("%lld\n", ans);

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <numeric>
#include <vector>
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, a) repi(i, 0, a)
#define all(a) (a).begin(), (a).end()

constexpr int MAX_N = 100000;

using ll = long long;

ll N;
ll L[MAX_N], R[MAX_N];
std::vector<ll> ls = {0}, rs = {0};

int main() {
  scanf("%lld", &N);
  rep(i, N) {
    scanf("%lld%lld", L + i, R + i);

    ls.push_back(L[i]);
    rs.push_back(R[i]);
  }

  std::sort(ls.rbegin(), ls.rend());
  std::sort(all(rs));

  // 5,3,1,0
  // 0,2,4,6

  ll rS = 0, lS = 0;
  ll ans = 0;
  rep(k, N) {
    if (ls[k] > rs[k]) {
      lS += ls[k];
      rS += rs[k];
    }

    ans = std::max(ans, 2 * (lS - rS));
  }

  printf("%lld\n", ans);

  return 0;
}
Problem p03334 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

const int N = 310;
int tot;
vector<pair<int, int>> ans[2][2];

void dfs(int c[N * 2][N * 2], int x, int y, int n, int d, int col) {
  if (x >= n || y >= n || x < 0 || y < 0 || c[x][y] != -1)
    return;
  c[x][y] = col;
  for (int i = 0; i * i <= d && i <= n; i++) {
    int j = sqrt(d + 0.0 - i * i);
    while (j * j <= d - i * i)
      j++;
    j--;
    if (i * i + j * j != d)
      continue;
    dfs(c, x + i, y + j, n, d, col ^ 1);
    dfs(c, x + i, y - j, n, d, col ^ 1);
    dfs(c, x - i, y + j, n, d, col ^ 1);
    dfs(c, x - i, y - j, n, d, col ^ 1);
  }
}

int c[2][N * 2][N * 2];
void solve(int n, int d, int t) {
  for (int i = 0; i < n * 2; i++)
    for (int j = 0; j < n * 2; j++)
      if (c[t][i][j] == -1)
        dfs(c[t], i, j, n * 2 - 1, d, 0);
}

int main() {
  int n, d1, d2;
  scanf("%d%d%d", &n, &d1, &d2);
  memset(c, -1, sizeof(c));
  solve(n, d1, 0);
  solve(n, d2, 1);
  for (int i = 0; i < 2 * n; i++)
    for (int j = 0; j < 2 * n; j++) {
      ans[c[0][i][j]][c[1][i][j]].push_back(make_pair(i, j));
    }
  tot = n * n;
  int maxn = 0, x = 0, y = 0;
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < 2; j++)
      if (ans[i][j].size() > maxn)
        maxn = ans[i][j].size(), x = i, y = j;
  for (int i = 0; i < ans[x][y].size() && i < tot; i++)
    printf("%d %d\n", ans[x][y][i].first, ans[x][y][i].second);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

const int N = 310;
int tot;
vector<pair<int, int>> ans[2][2];

void dfs(int c[N * 2][N * 2], int x, int y, int n, int d, int col) {
  if (x > n || y > n || x < 0 || y < 0 || c[x][y] != -1)
    return;
  c[x][y] = col;
  for (int i = 0; i * i <= d && i <= n; i++) {
    int j = sqrt(d + 0.0 - i * i);
    while (j * j <= d - i * i)
      j++;
    j--;
    if (i * i + j * j != d)
      continue;
    dfs(c, x + i, y + j, n, d, col ^ 1);
    dfs(c, x + i, y - j, n, d, col ^ 1);
    dfs(c, x - i, y + j, n, d, col ^ 1);
    dfs(c, x - i, y - j, n, d, col ^ 1);
  }
}

int c[2][N * 2][N * 2];
void solve(int n, int d, int t) {
  for (int i = 0; i < n * 2; i++)
    for (int j = 0; j < n * 2; j++)
      if (c[t][i][j] == -1)
        dfs(c[t], i, j, n * 2 - 1, d, 0);
}

int main() {
  int n, d1, d2;
  scanf("%d%d%d", &n, &d1, &d2);
  memset(c, -1, sizeof(c));
  solve(n, d1, 0);
  solve(n, d2, 1);
  for (int i = 0; i < 2 * n; i++)
    for (int j = 0; j < 2 * n; j++) {
      ans[c[0][i][j]][c[1][i][j]].push_back(make_pair(i, j));
    }
  tot = n * n;
  int maxn = 0, x = 0, y = 0;
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < 2; j++)
      if (ans[i][j].size() > maxn)
        maxn = ans[i][j].size(), x = i, y = j;
  for (int i = 0; i < ans[x][y].size() && i < tot; i++)
    printf("%d %d\n", ans[x][y][i].first, ans[x][y][i].second);
  return 0;
}
Problem p03334 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (a), _ed = (b); i <= _ed; ++i)
#define DREP(i, a, b) for (int i = (a), _ed = (b); i >= _ed; --i)
#define mp(x, y) make_pair((x), (y))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
inline int read() {
  register int x = 0, f = 1;
  register char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-')
      f = 0;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + (ch ^ '0');
    ch = getchar();
  }
  return f ? x : -x;
}

int n, col[305][305];

void paint(int d) {
  int cnt = 0;
  while (d % 4 == 0)
    d /= 4, ++cnt;
  if (d & 1) {
    REP(i, 0, n + n - 1)
    REP(j, 0, n + n - 1) col[i][j] |= ((i >> cnt) + (j >> cnt)) & 1;
  } else {
    REP(i, 0, n + n - 1) REP(j, 0, n + n - 1) col[i][j] |= (i >> cnt) & 1;
  }
}

int main() {
  // freopen("in.in","r",stdin);
  n = read();
  paint(read()), paint(read());
  int cnt = 0;
  REP(i, 0, n + n - 1) REP(j, 0, n + n - 1) {
    if (!col[i][j])
      printf("%d %d\n", i, j), ++cnt;
    if (cnt == n * n)
      return 0;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (a), _ed = (b); i <= _ed; ++i)
#define DREP(i, a, b) for (int i = (a), _ed = (b); i >= _ed; --i)
#define mp(x, y) make_pair((x), (y))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
inline int read() {
  register int x = 0, f = 1;
  register char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-')
      f = 0;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + (ch ^ '0');
    ch = getchar();
  }
  return f ? x : -x;
}

int n, col[605][605];

void paint(int d) {
  int cnt = 0;
  while (d % 4 == 0)
    d /= 4, ++cnt;
  if (d & 1) {
    REP(i, 0, n + n - 1)
    REP(j, 0, n + n - 1) col[i][j] |= ((i >> cnt) + (j >> cnt)) & 1;
  } else {
    REP(i, 0, n + n - 1) REP(j, 0, n + n - 1) col[i][j] |= (i >> cnt) & 1;
  }
}

int main() {
  // freopen("in.in","r",stdin);
  n = read();
  paint(read()), paint(read());
  int cnt = 0;
  REP(i, 0, n + n - 1) REP(j, 0, n + n - 1) {
    if (!col[i][j])
      printf("%d %d\n", i, j), ++cnt;
    if (cnt == n * n)
      return 0;
  }
  return 0;
}
Problem p03334 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define fo(i, a, b) for (int i = a, _e = b; i <= _e; ++i)
#define P pair<int, int>
#define fi first
#define se second
#define pb push_back
using namespace std;
const int N = 305;
int n, d1, d2;
int c[N][N], su[9];
bool vi[N][N];
vector<P> b[3];
void get(int x, vector<P> &b) {
  fo(i, 0, n * 2) {
    int a = x - i * i;
    if (x < 0)
      break;
    int c = sqrt(a);
    if (c * c == a) {
      b.pb(P(i, c));
      b.pb(P(i, -c));
      b.pb(P(-i, c));
      b.pb(P(-i, -c));
    }
  }
}
void go(int x, int y, int o, int o2) {
  vi[x][y] = 1;
  c[x][y] |= o2;
  for (P i : b[o]) {
    int xx = x + i.fi, yy = y + i.se;
    if (xx >= 0 && yy >= 0 && xx < n * 2 && yy < n * 2 && !vi[xx][yy])
      go(xx, yy, o, o - o2);
  }
}
int main() {
  cin >> n >> d1 >> d2;
  get(d1, b[1]);
  get(d2, b[2]);
  fo(i, 1, 2) {
    memset(vi, 0, sizeof vi);
    fo(j, 0, n * 2 - 1) fo(k, 0, n * 2 - 1) if (!vi[j][k]) go(j, k, i, 0);
  }
  fo(j, 0, n * 2 - 1) fo(k, 0, n * 2 - 1) su[c[j][k]]++;
  int mx = 0, cnt = 0;
  fo(i, 1, 3) if (su[i] > su[mx]) mx = i;
  fo(j, 0, n * 2 - 1) fo(k, 0, n * 2 - 1) if (c[j][k] == mx) {
    printf("%d %d\n", j, k);
    if (++cnt == n * n)
      return 0;
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define fo(i, a, b) for (int i = a, _e = b; i <= _e; ++i)
#define P pair<int, int>
#define fi first
#define se second
#define pb push_back
using namespace std;
const int N = 605;
int n, d1, d2;
int c[N][N], su[9];
bool vi[N][N];
vector<P> b[3];
void get(int x, vector<P> &b) {
  fo(i, 0, n * 2) {
    int a = x - i * i;
    if (x < 0)
      break;
    int c = sqrt(a);
    if (c * c == a) {
      b.pb(P(i, c));
      b.pb(P(i, -c));
      b.pb(P(-i, c));
      b.pb(P(-i, -c));
    }
  }
}
void go(int x, int y, int o, int o2) {
  vi[x][y] = 1;
  c[x][y] |= o2;
  for (P i : b[o]) {
    int xx = x + i.fi, yy = y + i.se;
    if (xx >= 0 && yy >= 0 && xx < n * 2 && yy < n * 2 && !vi[xx][yy])
      go(xx, yy, o, o - o2);
  }
}
int main() {
  cin >> n >> d1 >> d2;
  get(d1, b[1]);
  get(d2, b[2]);
  fo(i, 1, 2) {
    memset(vi, 0, sizeof vi);
    fo(j, 0, n * 2 - 1) fo(k, 0, n * 2 - 1) if (!vi[j][k]) go(j, k, i, 0);
  }
  fo(j, 0, n * 2 - 1) fo(k, 0, n * 2 - 1) su[c[j][k]]++;
  int mx = 0, cnt = 0;
  fo(i, 1, 3) if (su[i] > su[mx]) mx = i;
  fo(j, 0, n * 2 - 1) fo(k, 0, n * 2 - 1) if (c[j][k] == mx) {
    printf("%d %d\n", j, k);
    if (++cnt == n * n)
      return 0;
  }
}
Problem p03334 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int n, d1, d2, c;
int a[310][310];

void color(int d) {
  int w = 0;
  while (d % 4 == 0)
    d /= 4, w++;
  if (d & 1) {
    for (int i = 0; i < 2 * n; i++)
      for (int j = 0; j < 2 * n; j++)
        if ((((i >> w) & 1) ^ ((j >> w) & 1)))
          a[i][j] = 1;
  } else {
    for (int i = 0; i < 2 * n; i++)
      for (int j = 0; j < 2 * n; j++)
        if ((i >> w) & 1)
          a[i][j] = 1;
  }
}

int main() {
  scanf("%d%d%d", &n, &d1, &d2);
  color(d1);
  color(d2);
  for (int i = 0; i < 2 * n; i++)
    for (int j = 0; j < 2 * n; j++)
      if (c < n * n && !a[i][j])
        printf("%d %d\n", i, j), c++;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int n, d1, d2, c;
int a[610][610];

void color(int d) {
  int w = 0;
  while (d % 4 == 0)
    d /= 4, w++;
  if (d & 1) {
    for (int i = 0; i < 2 * n; i++)
      for (int j = 0; j < 2 * n; j++)
        if ((((i >> w) & 1) ^ ((j >> w) & 1)))
          a[i][j] = 1;
  } else {
    for (int i = 0; i < 2 * n; i++)
      for (int j = 0; j < 2 * n; j++)
        if ((i >> w) & 1)
          a[i][j] = 1;
  }
}

int main() {
  scanf("%d%d%d", &n, &d1, &d2);
  color(d1);
  color(d2);
  for (int i = 0; i < 2 * n; i++)
    for (int j = 0; j < 2 * n; j++)
      if (c < n * n && !a[i][j])
        printf("%d %d\n", i, j), c++;
  return 0;
}
Problem p03334 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

int x[333][333];
int main() {
  int n, d[2];
  cin >> n >> d[0] >> d[1];
  for (int i = 0; i < 2; i++) {
    int e = 0;
    for (; !(d[i] & 1); e++)
      d[i] >>= 1;
    for (int j = 0; j < n * 2; j++) {
      for (int k = 0; k < n * 2; k++)
        if ((j + k - e % 2 * k) >> e / 2 & 1)
          x[j][k] |= i + 1;
    }
  }
  int c[4] = {};
  for (int j = 0; j < n * 2; j++)
    for (int k = 0; k < n * 2; k++)
      c[x[j][k]]++;
  int m = 0;
  for (int i = 0; i < 4; i++)
    if (c[i] > c[m])
      m = i;
  int i = 0;
  for (int j = 0; j < n * 2; j++) {
    for (int k = 0; k < n * 2; k++) {
      if (x[j][k] != m)
        continue;
      if (i++ >= n * n)
        goto pnz;
      cout << j << ' ' << k << '\n';
    }
  }
pnz:
  cout << flush;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

int x[666][666];
int main() {
  int n, d[2];
  cin >> n >> d[0] >> d[1];
  for (int i = 0; i < 2; i++) {
    int e = 0;
    for (; !(d[i] & 1); e++)
      d[i] >>= 1;
    for (int j = 0; j < n * 2; j++) {
      for (int k = 0; k < n * 2; k++)
        if ((j + k - e % 2 * k) >> e / 2 & 1)
          x[j][k] |= i + 1;
    }
  }
  int c[4] = {};
  for (int j = 0; j < n * 2; j++)
    for (int k = 0; k < n * 2; k++)
      c[x[j][k]]++;
  int m = 0;
  for (int i = 0; i < 4; i++)
    if (c[i] > c[m])
      m = i;
  int i = 0;
  for (int j = 0; j < n * 2; j++) {
    for (int k = 0; k < n * 2; k++) {
      if (x[j][k] != m)
        continue;
      if (i++ >= n * n)
        goto pnz;
      cout << j << ' ' << k << '\n';
    }
  }
pnz:
  cout << flush;
  return 0;
}
Problem p03334 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define MAXN 500
using namespace std;

int n, m, cnt, d[5], col[MAXN][MAXN][2];
bool vis[MAXN][MAXN][2];

void dfs(int x, int y, int a, int b) {
  if (x < 0 || x > m || y < 0 || y > m || vis[x][y][a])
    return;
  vis[x][y][a] = true;
  col[x][y][a] = b;
  for (int i = 0; i * i <= d[a]; i++) {
    int j = sqrt(d[a] - i * i);
    if (i * i + j * j != d[a])
      continue;
    dfs(x + i, y + j, a, 3 - b);
    dfs(x - i, y + j, a, 3 - b);
    dfs(x + i, y - j, a, 3 - b);
    dfs(x - i, y - j, a, 3 - b);
  }
}

void debug() {
  for (int i = 0; i <= m; i++) {
    for (int j = 0; j <= m; j++)
      printf("%d ", col[i][j][0]);
    printf("\n");
  }
  printf("\n\n");
  for (int i = 0; i <= m; i++) {
    for (int j = 0; j <= m; j++)
      printf("%d ", col[i][j][1]);
    printf("\n");
  }
}

int main() {
  scanf("%d%d%d", &n, &d[0], &d[1]);
  m = n * 2 - 1;
  for (int i = 0; i <= m; i++)
    for (int j = 0; j <= m; j++) {
      if (!vis[i][j][0])
        dfs(i, j, 0, 1);
      if (!vis[i][j][1])
        dfs(i, j, 1, 1);
    }
  for (int i = 0; i <= m; i++)
    for (int j = 0; j <= m; j++) {
      if (col[i][j][0] == 1 && col[i][j][1] == 1) {
        printf("%d %d \n", i, j);
        if (++cnt == n * n)
          return 0;
      }
    }
}

Fixed submission:
#include <bits/stdc++.h>
#define MAXN 600
using namespace std;

int n, m, cnt, d[5], col[MAXN][MAXN][2];
bool vis[MAXN][MAXN][2];

void dfs(int x, int y, int a, int b) {
  if (x < 0 || x > m || y < 0 || y > m || vis[x][y][a])
    return;
  vis[x][y][a] = true;
  col[x][y][a] = b;
  for (int i = 0; i * i <= d[a]; i++) {
    int j = sqrt(d[a] - i * i);
    if (i * i + j * j != d[a])
      continue;
    dfs(x + i, y + j, a, 3 - b);
    dfs(x - i, y + j, a, 3 - b);
    dfs(x + i, y - j, a, 3 - b);
    dfs(x - i, y - j, a, 3 - b);
  }
}

void debug() {
  for (int i = 0; i <= m; i++) {
    for (int j = 0; j <= m; j++)
      printf("%d ", col[i][j][0]);
    printf("\n");
  }
  printf("\n\n");
  for (int i = 0; i <= m; i++) {
    for (int j = 0; j <= m; j++)
      printf("%d ", col[i][j][1]);
    printf("\n");
  }
}

int main() {
  scanf("%d%d%d", &n, &d[0], &d[1]);
  m = n * 2 - 1;
  for (int i = 0; i <= m; i++)
    for (int j = 0; j <= m; j++) {
      if (!vis[i][j][0])
        dfs(i, j, 0, 1);
      if (!vis[i][j][1])
        dfs(i, j, 1, 1);
    }
  for (int i = 0; i <= m; i++)
    for (int j = 0; j <= m; j++) {
      if (col[i][j][0] == 1 && col[i][j][1] == 1) {
        printf("%d %d \n", i, j);
        if (++cnt == n * n)
          return 0;
      }
    }
}
Problem p03334 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <cstdio>
#include <cstring>

const int Maxv = 305;
int Map[Maxv][Maxv][2], d[5], n, m, cnt;
bool vis[Maxv][Maxv][2];

inline void dfs(int x, int y, int a, int b) {
  if (x < 0 || x > m || y < 0 || y > m || vis[x][y][a]) {
    return;
  }
  vis[x][y][a] = true;
  Map[x][y][a] = b;
  for (int i = 0; i * i <= d[a]; i++) {
    int j = sqrt(d[a] - i * i);
    if (i * i + j * j != d[a]) {
      continue;
    }
    dfs(x + i, y + j, a, 3 - b);
    dfs(x - i, y + j, a, 3 - b);
    dfs(x + i, y - j, a, 3 - b);
    dfs(x - i, y - j, a, 3 - b);
  }
}

int main() {
  scanf("%d%d%d", &n, &d[0], &d[1]);
  m = 2 * n - 1;
  for (int i = 0; i <= m; i++) {
    for (int j = 0; j <= m; j++) {
      if (!vis[i][j][0]) {
        dfs(i, j, 0, 1);
      }
      if (!vis[i][j][1]) {
        dfs(i, j, 1, 1);
      }
    }
  }
  for (int i = 0; i <= m; i++) {
    for (int j = 0; j <= m; j++) {
      if (Map[i][j][0] == 1 && Map[i][j][1] == 1) {
        printf("%d %d\n", i, j);
        cnt++;
        if (cnt == n * n) {
          return 0;
        }
      }
    }
  }
}

Fixed submission:
#include <cmath>
#include <cstdio>
#include <cstring>

const int Maxv = 605;
int Map[Maxv][Maxv][2], d[5], n, m, cnt;
bool vis[Maxv][Maxv][2];

inline void dfs(int x, int y, int a, int b) {
  if (x < 0 || x > m || y < 0 || y > m || vis[x][y][a]) {
    return;
  }
  vis[x][y][a] = true;
  Map[x][y][a] = b;
  for (int i = 0; i * i <= d[a]; i++) {
    int j = sqrt(d[a] - i * i);
    if (i * i + j * j != d[a]) {
      continue;
    }
    dfs(x + i, y + j, a, 3 - b);
    dfs(x - i, y + j, a, 3 - b);
    dfs(x + i, y - j, a, 3 - b);
    dfs(x - i, y - j, a, 3 - b);
  }
}

int main() {
  scanf("%d%d%d", &n, &d[0], &d[1]);
  m = 2 * n - 1;
  for (int i = 0; i <= m; i++) {
    for (int j = 0; j <= m; j++) {
      if (!vis[i][j][0]) {
        dfs(i, j, 0, 1);
      }
      if (!vis[i][j][1]) {
        dfs(i, j, 1, 1);
      }
    }
  }
  for (int i = 0; i <= m; i++) {
    for (int j = 0; j <= m; j++) {
      if (Map[i][j][0] == 1 && Map[i][j][1] == 1) {
        printf("%d %d\n", i, j);
        cnt++;
        if (cnt == n * n) {
          return 0;
        }
      }
    }
  }
}
Problem p03334 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#define lol(i, n) for (ll i = 0; i < n; i++)
#define mod 1000000007
typedef long long ll;

using namespace std;
#define X 610
ll n;
class Con {
public:
  vector<pair<ll, ll>> g[X][X];
  ll s[X][X];
  void dfs(ll x, ll y, ll c) {
    if (~s[x][y])
      return;
    s[x][y] = c;
    for (auto t : g[x][y]) {
      dfs(t.first, t.second, 1 ^ c);
    }
  }
  void main(ll d) {
    vector<ll> x, y;
    for (int i = -X; i < X; i++)
      for (int j = -X; j < X; j++) {
        if (i * i + j * j == d) {
          x.push_back(i);
          y.push_back(j);
        }
      }
    lol(i, n) lol(j, n) {
      for (int k = 0; k < x.size(); k++) {
        ll xx = i + x[k], yy = j + y[k];
        if (xx < 0 || yy < 0 || xx == n || yy == n)
          continue;
        g[i][j].push_back(make_pair(xx, yy));
      }
    }
    lol(i, n) lol(j, n) s[i][j] = -1;
    lol(i, n) lol(j, n) dfs(i, j, 0);
  }
};
Con co[2];
int main() {
  cin >> n;
  n *= 2;
  lol(i, 2) {
    ll d;
    cin >> d;
    co[i].main(d);
  }
  vector<pair<ll, ll>> v[2][2];
  lol(i, n) lol(j, n) {
    v[co[0].s[i][j]][co[1].s[i][j]].push_back(make_pair(i, j));
  }
  lol(i, 2) lol(j, 2) if (v[i][j].size() >= n * n / 4) {
    for (int k = 0; k < n * n / 4; k++) {
      cout << v[i][j][k].first << " " << v[i][j][k].second << endl;
    }
    return 0;
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#define lol(i, n) for (ll i = 0; i < n; i++)
#define mod 1000000007
typedef long long ll;

using namespace std;
#define X 610
ll n;
class Con {
public:
  vector<pair<ll, ll>> g[X][X];
  ll s[X][X];
  void dfs(ll x, ll y, ll c) {
    if (~s[x][y])
      return;
    s[x][y] = c;
    for (auto t : g[x][y]) {
      dfs(t.first, t.second, 1 ^ c);
    }
  }
  void main(ll d) {
    vector<ll> x, y;
    for (int i = -X; i < X; i++)
      for (int j = -X; j < X; j++) {
        if (i * i + j * j == d) {
          x.push_back(i);
          y.push_back(j);
        }
      }
    lol(i, n) lol(j, n) {
      for (int k = 0; k < x.size(); k++) {
        ll xx = i + x[k], yy = j + y[k];
        if (xx < 0 || yy < 0 || xx >= n || yy >= n)
          continue;
        g[i][j].push_back(make_pair(xx, yy));
      }
    }
    lol(i, n) lol(j, n) s[i][j] = -1;
    lol(i, n) lol(j, n) dfs(i, j, 0);
  }
};
Con co[2];
int main() {
  cin >> n;
  n *= 2;
  lol(i, 2) {
    ll d;
    cin >> d;
    co[i].main(d);
  }
  vector<pair<ll, ll>> v[2][2];
  lol(i, n) lol(j, n) {
    v[co[0].s[i][j]][co[1].s[i][j]].push_back(make_pair(i, j));
  }
  lol(i, 2) lol(j, 2) if (v[i][j].size() >= n * n / 4) {
    for (int k = 0; k < n * n / 4; k++) {
      cout << v[i][j][k].first << " " << v[i][j][k].second << endl;
    }
    return 0;
  }
  return 0;
}
Problem p03334 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int n, d1, d2, a[333][333];

void solve(int d) {
  int sum = 0;
  while (d % 4 == 0) {
    sum++;
    d /= 4;
  }
  if (d & 1) {
    for (int i = 0; i < n + n; i++)
      for (int j = 0; j < n + n; j++)
        if (((i >> sum) + (j >> sum)) & 1)
          a[i][j] = 1; // 101010  010101
  } else {
    for (int i = 0; i < n + n; i++)
      for (int j = 0; j < n + n; j++)
        if ((i >> sum) & 1)
          a[i][j] = 1; // 111111 000000
  }
}

int main() {
  scanf("%d%d%d", &n, &d1, &d2);
  solve(d1);
  solve(d2);
  int cnt = 0;
  for (int i = 0; i < n + n; i++) {
    if (cnt == n * n)
      break;
    for (int j = 0; j < n + n; j++)
      if (!a[i][j]) {
        printf("%d %d\n", i, j);
        if (++cnt == n * n)
          break;
      }
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int n, d1, d2, a[1000][1000];

void solve(int d) {
  int sum = 0;
  while (d % 4 == 0) {
    sum++;
    d /= 4;
  }
  if (d & 1) {
    for (int i = 0; i < n + n; i++)
      for (int j = 0; j < n + n; j++)
        if (((i >> sum) + (j >> sum)) & 1)
          a[i][j] = 1; // 101010  010101
  } else {
    for (int i = 0; i < n + n; i++)
      for (int j = 0; j < n + n; j++)
        if ((i >> sum) & 1)
          a[i][j] = 1; // 111111 000000
  }
}

int main() {
  scanf("%d%d%d", &n, &d1, &d2);
  solve(d1);
  solve(d2);
  int cnt = 0;
  for (int i = 0; i < n + n; i++) {
    if (cnt == n * n)
      break;
    for (int j = 0; j < n + n; j++)
      if (!a[i][j]) {
        printf("%d %d\n", i, j);
        if (++cnt == n * n)
          break;
      }
  }
  return 0;
}
Problem p03334 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define mo 1000000007
#define ny 499122177
#define maxn 1000000000000000000LL
#define pi 3.1415926535898
#define eps 1e-9
using namespace std;
long long read() {
  long long xx = 0, flagg = 1;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-')
    ch = getchar();
  if (ch == '-') {
    flagg = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    xx = xx * 10 + ch - '0';
    ch = getchar();
  }
  return xx * flagg;
}
void pus(long long xx, long long flagg) {
  if (xx < 0) {
    putchar('-');
    xx = -xx;
  }
  if (xx >= 10)
    pus(xx / 10, 0);
  putchar(xx % 10 + '0');
  if (flagg == 1)
    putchar(' ');
  if (flagg == 2)
    putchar('\n');
  return;
}
int n, m, d1, d2, i, j, flag, cnt, book[305][305];
void ss(int x) {
  flag = 0;
  while ((x & 3) == 0) {
    x >>= 2;
    flag++;
  }
  if (x & 1) {
    for (i = 0; i < m; i++)
      for (j = 0; j < m; j++)
        if (((i >> flag) + (j >> flag)) & 1)
          book[i][j] = 1;
  } else {
    for (i = 0; i < m; i++)
      for (j = 0; j < m; j++)
        if ((i >> flag) & 1)
          book[i][j] = 1;
  }
}
int main() {
  //	freopen("number.in","r",stdin);
  //	freopen("number.out","w",stdout);
  n = read();
  d1 = read();
  d2 = read();
  m = n * 2;
  ss(d1);
  ss(d2);
  for (i = 0; i < m; i++)
    for (j = 0; j < m; j++) {
      if (book[i][j] == 0) {
        pus(i, 1);
        pus(j, 2);
        cnt++;
      }
      if (cnt == n * n)
        return 0;
    }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define mo 1000000007
#define ny 499122177
#define maxn 1000000000000000000LL
#define pi 3.1415926535898
#define eps 1e-9
using namespace std;
long long read() {
  long long xx = 0, flagg = 1;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-')
    ch = getchar();
  if (ch == '-') {
    flagg = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    xx = xx * 10 + ch - '0';
    ch = getchar();
  }
  return xx * flagg;
}
void pus(long long xx, long long flagg) {
  if (xx < 0) {
    putchar('-');
    xx = -xx;
  }
  if (xx >= 10)
    pus(xx / 10, 0);
  putchar(xx % 10 + '0');
  if (flagg == 1)
    putchar(' ');
  if (flagg == 2)
    putchar('\n');
  return;
}
int n, m, d1, d2, i, j, flag, cnt, book[605][605];
void ss(int x) {
  flag = 0;
  while ((x & 3) == 0) {
    x >>= 2;
    flag++;
  }
  if (x & 1) {
    for (i = 0; i < m; i++)
      for (j = 0; j < m; j++)
        if (((i >> flag) + (j >> flag)) & 1)
          book[i][j] = 1;
  } else {
    for (i = 0; i < m; i++)
      for (j = 0; j < m; j++)
        if ((i >> flag) & 1)
          book[i][j] = 1;
  }
}
int main() {
  //	freopen("number.in","r",stdin);
  //	freopen("number.out","w",stdout);
  n = read();
  d1 = read();
  d2 = read();
  m = n * 2;
  ss(d1);
  ss(d2);
  for (i = 0; i < m; i++)
    for (j = 0; j < m; j++) {
      if (book[i][j] == 0) {
        pus(i, 1);
        pus(j, 2);
        cnt++;
      }
      if (cnt == n * n)
        return 0;
    }
  return 0;
}
Problem p03334 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

const int MaxN = 300 + 30;
const int MOD = 1e9 + 7;
const long long INF = 1e18;

int d[2];
int c[2][MaxN][MaxN];

vector<pair<int, int>> v[2];
vector<pair<int, int>> ans[4];

int n;

void dfs(int k, int x, int y, int q) {
  c[k][x][y] = q;

  for (auto p : v[k]) {
    int xx = x + p.first;
    int yy = y + p.second;

    if (xx >= 0 && xx < n + n && yy >= 0 && yy < n + n && !c[k][xx][yy])
      dfs(k, xx, yy, 3 - q);
  }
}

int main() {
  //    freopen("output.txt", "r", stdin);

  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> n >> d[0] >> d[1];

  for (int i = -n - n; i <= n + n; ++i)
    for (int j = -n - n; j <= n + n; ++j)
      for (int k = 0; k < 2; ++k)
        if (i * i + j * j == d[k])
          v[k].push_back({i, j});

  for (int i = 0; i < n + n; ++i)
    for (int j = 0; j < n + n; ++j)
      for (int k = 0; k < 2; ++k)
        if (!c[k][i][j])
          dfs(k, i, j, 1);

  for (int i = 0; i < n + n; ++i)
    for (int j = 0; j < n + n; ++j)
      ans[2 * (c[0][i][j] - 1) + c[1][i][j] - 1].push_back({i, j});

  for (int i = 0; i < 4; ++i) {
    if (ans[i].size() >= n * n) {
      ans[i].resize(n * n);
      for (auto x : ans[i])
        cout << x.first << ' ' << x.second << '\n';
      return 0;
    }
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

const int MaxN = 300 + 30;
const int MOD = 1e9 + 7;
const long long INF = 1e18;

int d[2];
int c[2][2 * MaxN][2 * MaxN];

vector<pair<int, int>> v[2];
vector<pair<int, int>> ans[4];

int n;

void dfs(int k, int x, int y, int q) {
  c[k][x][y] = q;

  for (auto p : v[k]) {
    int xx = x + p.first;
    int yy = y + p.second;

    if (xx >= 0 && xx < n + n && yy >= 0 && yy < n + n && !c[k][xx][yy])
      dfs(k, xx, yy, 3 - q);
  }
}

int main() {
  //    freopen("output.txt", "r", stdin);

  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> n >> d[0] >> d[1];

  for (int i = -n - n; i <= n + n; ++i)
    for (int j = -n - n; j <= n + n; ++j)
      for (int k = 0; k < 2; ++k)
        if (i * i + j * j == d[k])
          v[k].push_back({i, j});

  for (int i = 0; i < n + n; ++i)
    for (int j = 0; j < n + n; ++j)
      for (int k = 0; k < 2; ++k)
        if (!c[k][i][j])
          dfs(k, i, j, 1);

  for (int i = 0; i < n + n; ++i)
    for (int j = 0; j < n + n; ++j)
      ans[2 * (c[0][i][j] - 1) + c[1][i][j] - 1].push_back({i, j});

  for (int i = 0; i < 4; ++i) {
    if (ans[i].size() >= n * n) {
      ans[i].resize(n * n);
      for (auto x : ans[i])
        cout << x.first << ' ' << x.second << '\n';
      return 0;
    }
  }

  return 0;
}
Problem p03334 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int a[305][305], n, d1, d2, z;
void doit(int x) {
  int y = 0;
  while (x % 4 == 0)
    x /= 4, y++;
  if (x % 2 == 1) {
    for (int i = 0; i < 2 * n; i++)
      for (int j = 0; j < 2 * n; j++)
        if (((i >> y) + (j >> y)) & 1)
          a[i][j] = 1;
  } else {
    for (int i = 0; i < 2 * n; i++)
      for (int j = 0; j < 2 * n; j++)
        if ((i >> y) & 1)
          a[i][j] = 1;
  }
}
int main() {
  scanf("%d%d%d", &n, &d1, &d2);
  doit(d1);
  doit(d2);
  for (int i = 0; i < 2 * n; i++)
    for (int j = 0; j < 2 * n; j++)
      if (!a[i][j] && z < n * n) {
        printf("%d %d\n", i, j);
        z++;
      }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int a[605][605], n, d1, d2, z;
void doit(int x) {
  int y = 0;
  while (x % 4 == 0)
    x /= 4, y++;
  if (x % 2 == 1) {
    for (int i = 0; i < 2 * n; i++)
      for (int j = 0; j < 2 * n; j++)
        if (((i >> y) + (j >> y)) & 1)
          a[i][j] = 1;
  } else {
    for (int i = 0; i < 2 * n; i++)
      for (int j = 0; j < 2 * n; j++)
        if ((i >> y) & 1)
          a[i][j] = 1;
  }
}
int main() {
  scanf("%d%d%d", &n, &d1, &d2);
  doit(d1);
  doit(d2);
  for (int i = 0; i < 2 * n; i++)
    for (int j = 0; j < 2 * n; j++)
      if (!a[i][j] && z < n * n) {
        printf("%d %d\n", i, j);
        z++;
      }
  return 0;
}
Problem p03334 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define LL long long
#define MAXN 310
LL n, d1, d2;
bool cannot[MAXN][MAXN];

void Set(LL d) {
  LL b = 0;
  while (!(d % 4))
    d >>= 2, ++b;
  if (d & 1) {
    for (int i = 0; i <= n << 1; ++i)
      for (int j = 0; j <= n << 1; ++j)
        if (((i >> b) + (j >> b)) & 1)
          cannot[i][j] = true;
  } else {
    for (int i = 0; i <= n << 1; ++i)
      for (int j = 0; j <= n << 1; ++j)
        if ((i >> b) & 1)
          cannot[i][j] = true;
  }
}
int main() {
  cin >> n >> d1 >> d2;
  Set(d1);
  Set(d2);
  /*for (int i = 0; i < n << 1; ++i, cout << endl)
          for (int j = 0;j < n << 1; ++j)
                  cout << cannot[i][j];*/
  int cnt = 0;
  for (int i = 0; i < n << 1; ++i)
    for (int j = 0; j < n << 1; ++j)
      if (cnt < n * n && !cannot[i][j]) {
        cout << i << " " << j << endl;
        ++cnt;
      }
  return 0;
}

Fixed submission:
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define LL long long
#define MAXN 610
LL n, d1, d2;
bool cannot[MAXN][MAXN];

void Set(LL d) {
  LL b = 0;
  while (!(d % 4))
    d >>= 2, ++b;
  if (d & 1) {
    for (int i = 0; i <= n << 1; ++i)
      for (int j = 0; j <= n << 1; ++j)
        if (((i >> b) + (j >> b)) & 1)
          cannot[i][j] = true;
  } else {
    for (int i = 0; i <= n << 1; ++i)
      for (int j = 0; j <= n << 1; ++j)
        if ((i >> b) & 1)
          cannot[i][j] = true;
  }
}
int main() {
  cin >> n >> d1 >> d2;
  Set(d1);
  Set(d2);
  /*for (int i = 0; i < n << 1; ++i, cout << endl)
          for (int j = 0;j < n << 1; ++j)
                  cout << cannot[i][j];*/
  int cnt = 0;
  for (int i = 0; i < n << 1; ++i)
    for (int j = 0; j < n << 1; ++j)
      if (cnt < n * n && !cannot[i][j]) {
        cout << i << " " << j << endl;
        ++cnt;
      }
  return 0;
}
Problem p03334 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int n, dis1, dis2, v[350][350];

void calc(int d) {
  int ti = 0;
  while (!(d & 3))
    d >>= 2, ti++;
  if ((d & 3) == 1) {
    for (int i = 0; i < n << 1; i++)
      for (int j = 0; j < n << 1; j++)
        if ((i >> ti) + (j >> ti) & 1)
          v[i][j] = 1;
  } else if ((d & 3) == 2) {
    for (int i = 0; i < n << 1; i++)
      for (int j = 0; j < n << 1; j++)
        if ((i >> ti) & 1)
          v[i][j] = 1;
  }
}

int main() {
  cin >> n >> dis1 >> dis2;
  calc(dis1), calc(dis2);
  for (int i = 0, cnt = 0, cur = n * n; i < n << 1; i++)
    for (int j = 0; j < n << 1; j++) {
      if (!v[i][j])
        printf("%d %d\n", i, j), cnt++;
      if (cnt == cur)
        return 0;
    }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int n, dis1, dis2, v[650][650];

void calc(int d) {
  int ti = 0;
  while (!(d & 3))
    d >>= 2, ti++;
  if ((d & 3) == 1) {
    for (int i = 0; i < n << 1; i++)
      for (int j = 0; j < n << 1; j++)
        if ((i >> ti) + (j >> ti) & 1)
          v[i][j] = 1;
  } else if ((d & 3) == 2) {
    for (int i = 0; i < n << 1; i++)
      for (int j = 0; j < n << 1; j++)
        if ((i >> ti) & 1)
          v[i][j] = 1;
  }
}

int main() {
  cin >> n >> dis1 >> dis2;
  calc(dis1), calc(dis2);
  for (int i = 0, cnt = 0, cur = n * n; i < n << 1; i++)
    for (int j = 0; j < n << 1; j++) {
      if (!v[i][j])
        printf("%d %d\n", i, j), cnt++;
      if (cnt == cur)
        return 0;
    }
  return 0;
}
Problem p03334 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int n, d1, d2, len, a[305][305];
void solve(int d) {
  len = 0;
  while (d % 4 == 0)
    len++, d /= 4;
  for (int i = 0; i < 2 * n; i++)
    for (int j = 0; j < 2 * n; j++) {
      if (d % 2 == 1)
        a[i][j] = (((i >> len) + (j >> len)) & 1) ? 1 : a[i][j];
      if (d % 4 == 2)
        a[i][j] = ((i >> len) & 1) ? 1 : a[i][j];
    }
}
int main() {
  scanf("%d%d%d", &n, &d1, &d2);
  solve(d1);
  solve(d2);
  int calc = 0;
  for (int i = 0; i < 2 * n; i++)
    for (int j = 0; j < 2 * n; j++) {
      if (a[i][j] == 0) {
        printf("%d %d\n", i, j);
        calc++;
        if (calc == n * n)
          return 0;
      }
    }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int n, d1, d2, len, a[605][605];
void solve(int d) {
  len = 0;
  while (d % 4 == 0)
    len++, d /= 4;
  for (int i = 0; i < 2 * n; i++)
    for (int j = 0; j < 2 * n; j++) {
      if (d % 2 == 1)
        a[i][j] = (((i >> len) + (j >> len)) & 1) ? 1 : a[i][j];
      if (d % 4 == 2)
        a[i][j] = ((i >> len) & 1) ? 1 : a[i][j];
    }
}
int main() {
  scanf("%d%d%d", &n, &d1, &d2);
  solve(d1);
  solve(d2);
  int calc = 0;
  for (int i = 0; i < 2 * n; i++)
    for (int j = 0; j < 2 * n; j++) {
      if (a[i][j] == 0) {
        printf("%d %d\n", i, j);
        calc++;
        if (calc == n * n)
          return 0;
      }
    }
  return 0;
}
Problem p03334 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

const int N = 303;

int n, col[N][N], cnt[3];
vector<pair<int, int>> diff;

void dfs(int x, int y, int c) {
  if (x >= 0 && x < 2 * n && y >= 0 && y < 2 * n && col[x][y] == 0) {
    col[x][y] = c;
    cnt[c]++;
    for (auto d : diff)
      dfs(x + d.first, y + d.second, 3 - c);
  }
}

int main() {
  cin >> n;

  int iter = 2;
  while (iter--) {
    // calcular arcos
    int d;
    cin >> d;
    diff.clear();
    for (int dx = 0; dx < 2 * n; dx++)
      for (int dy = 0; dy < 2 * n; dy++)
        if (dx * dx + dy * dy == d) {
          diff.emplace_back(dx, dy);
          diff.emplace_back(-dx, dy);
          diff.emplace_back(dx, -dy);
          diff.emplace_back(-dx, -dy);
        }

    // partir bipartito
    for (int i = 0; i < 2 * n; i++)
      for (int j = 0; j < 2 * n; j++)
        if (col[i][j] == 0)
          dfs(i, j, 1);

    // quedarse con particion mayor
    int best = (cnt[1] > cnt[2] ? 1 : 2);
    for (int i = 0; i < 2 * n; i++)
      for (int j = 0; j < 2 * n; j++)
        col[i][j] = (col[i][j] == best ? 0 : 3);
  }

  int need = n * n;
  for (int i = 0; i < 2 * n; i++)
    for (int j = 0; j < 2 * n; j++)
      if (col[i][j] == 0) {
        cout << i << ' ' << j << endl;
        if (--need == 0)
          return 0;
      }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

const int N = 610;

int n, col[N][N], cnt[3];
vector<pair<int, int>> diff;

void dfs(int x, int y, int c) {
  if (x >= 0 && x < 2 * n && y >= 0 && y < 2 * n && col[x][y] == 0) {
    col[x][y] = c;
    cnt[c]++;
    for (auto d : diff)
      dfs(x + d.first, y + d.second, 3 - c);
  }
}

int main() {
  cin >> n;

  int iter = 2;
  while (iter--) {
    // calcular arcos
    int d;
    cin >> d;
    diff.clear();
    for (int dx = 0; dx < 2 * n; dx++)
      for (int dy = 0; dy < 2 * n; dy++)
        if (dx * dx + dy * dy == d) {
          diff.emplace_back(dx, dy);
          diff.emplace_back(-dx, dy);
          diff.emplace_back(dx, -dy);
          diff.emplace_back(-dx, -dy);
        }

    // partir bipartito
    for (int i = 0; i < 2 * n; i++)
      for (int j = 0; j < 2 * n; j++)
        if (col[i][j] == 0)
          dfs(i, j, 1);

    // quedarse con particion mayor
    int best = (cnt[1] > cnt[2] ? 1 : 2);
    for (int i = 0; i < 2 * n; i++)
      for (int j = 0; j < 2 * n; j++)
        col[i][j] = (col[i][j] == best ? 0 : 3);
  }

  int need = n * n;
  for (int i = 0; i < 2 * n; i++)
    for (int j = 0; j < 2 * n; j++)
      if (col[i][j] == 0) {
        cout << i << ' ' << j << endl;
        if (--need == 0)
          return 0;
      }

  return 0;
}
Problem p03335 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <cstring>
#define M 4004
#define N 2002
int A[N], B[M], C[M], D[M], E[M], F[M], a[N], b[M], c[M], d[N], f[N], m, n, s,
    t;
inline void swap(int &u, int &v) { s = u, u = v, v = s; }
inline void add(int u, int v, int x, int y) {
  d[v] < d[u] ? swap(u, v), 0 : 0, C[++t] = u, D[t] = v, E[t] = x, F[t] = y,
                                   u != v ? B[t] = A[u], A[u] = t : 0;
}
void dfn(int u) {
  for (int i = a[u]; i; i = b[i])
    if (c[i] != f[u])
      f[c[i]] = u, dfn(c[i]);
  d[u] = ++t;
}
void dfs(int u) {
  for (int i = a[u]; i; i = b[i])
    if (c[i] != f[u])
      dfs(c[i]);
  for (; B[A[u]]; A[u] = B[B[A[u]]])
    add(D[A[u]], D[B[A[u]]], A[u], B[A[u]]);
  if (A[u])
    add(f[u], D[A[u]], A[u], 0);
}
int i, u, v;
int main() {
  for (scanf("%d%d", &n, &m), i = t = 1; i < n; i++)
    scanf("%d%d", &u, &v), b[++t] = a[u], c[a[u] = t] = v, b[++t] = a[v],
                           c[a[v] = t] = u;
  for (t = 0, dfn(1), i = 1, t = 0; i <= m; i++)
    scanf("%d%d", &u, &v), add(u, v, 0, 0);
  for (dfs(1), i = t; m < i; i--)
    D[E[i]] == D[i] ? swap(C[F[i]], D[F[i]]) : swap(C[E[i]], D[E[i]]);
  for (memset(b + 1, 0, n << 2), memset(c + 1, 0, n << 2), i = 1, s = 0; i <= m;
       i++)
    for (u = C[i], v = D[i]; u != v;)
      d[u] < d[v]                        ? s += !b[u], b[u] = 1,
                                u = f[u] : (s += !c[v], c[v] = 1, v = f[v]);
  for (printf("%d\n", s), i = 1; i <= m; i++)
    printf("%d %d\n", C[i], D[i]);
  return 0;
}

Fixed submission:
#include <cstdio>
#include <cstring>
#define M 4004
#define N 2002
int A[N], B[N * N], C[N * N], D[N * N], E[N * N], F[N * N], a[N], b[M], c[M],
    d[N], f[N], m, n, s, t;
inline void swap(int &u, int &v) { s = u, u = v, v = s; }
inline void add(int u, int v, int x, int y) {
  d[v] < d[u] ? swap(u, v), 0 : 0, C[++t] = u, D[t] = v, E[t] = x, F[t] = y,
                                   u != v ? B[t] = A[u], A[u] = t : 0;
}
void dfn(int u) {
  for (int i = a[u]; i; i = b[i])
    if (c[i] != f[u])
      f[c[i]] = u, dfn(c[i]);
  d[u] = ++t;
}
void dfs(int u) {
  for (int i = a[u]; i; i = b[i])
    if (c[i] != f[u])
      dfs(c[i]);
  for (; B[A[u]]; A[u] = B[B[A[u]]])
    add(D[A[u]], D[B[A[u]]], A[u], B[A[u]]);
  if (A[u])
    add(f[u], D[A[u]], A[u], 0);
}
int i, u, v;
int main() {
  for (scanf("%d%d", &n, &m), i = t = 1; i < n; i++)
    scanf("%d%d", &u, &v), b[++t] = a[u], c[a[u] = t] = v, b[++t] = a[v],
                           c[a[v] = t] = u;
  for (t = 0, dfn(1), i = 1, t = 0; i <= m; i++)
    scanf("%d%d", &u, &v), add(u, v, 0, 0);
  for (dfs(1), i = t; m < i; i--)
    D[E[i]] == D[i] ? swap(C[F[i]], D[F[i]]) : swap(C[E[i]], D[E[i]]);
  for (memset(b + 1, 0, n << 2), memset(c + 1, 0, n << 2), i = 1, s = 0; i <= m;
       i++)
    for (u = C[i], v = D[i]; u != v;)
      d[u] < d[v]                        ? s += !b[u], b[u] = 1,
                                u = f[u] : (s += !c[v], c[v] = 1, v = f[v]);
  for (printf("%d\n", s), i = 1; i <= m; i++)
    printf("%d %d\n", C[i], D[i]);
  return 0;
}
Problem p03337 (Python)

Buggy submission (status: Runtime Error):
def resolve():
    (
        a,
        b,
    ) = int(input())
    ans = max([a + b, a - b, a * b])
    print(ans)


if __name__ == "__main__":
    resolve()


Fixed submission:
def resolve():
    a, b = map(int, input().split())
    ans = max(a + b, a - b, a * b)
    print(ans)


if __name__ == "__main__":
    resolve()
Problem p03337 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>

int main(int argc, char *argv[]) {
  int A, B;
  scanf("%d", &A);
  scanf("%d", &B);
  int plus = A + B;
  int minus = A - B;
  int mult = A * B;

  int result = plus;
  if (minus > result)
    result = minus;
  if (mult > result)
    result = mult;

  return result;
}

Fixed submission:
#include <stdio.h>

int main(int argc, char *argv[]) {
  int A, B;
  scanf("%d", &A);
  scanf("%d", &B);
  int plus = A + B;
  int minus = A - B;
  int mult = A * B;

  int result = plus;
  if (minus > result)
    result = minus;
  if (mult > result)
    result = mult;

  printf("%d", result);
  return 0;
}
Problem p03337 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>

int main(void) {

  int A, B, max = 0;

  scanf("%d", A);
  scanf("%d", B);

  max = A + B;

  if ((A - B) > max)
    max = A - B;
  if ((A * B) > max)
    max = A * B;

  printf("%d", max);
  return 0;
}

Fixed submission:
#include <stdio.h>

int main(void) {

  int A, B, max = 0;

  scanf("%d", &A);
  scanf("%d", &B);

  max = A + B;

  if ((A - B) > max)
    max = A - B;
  if ((A * B) > max)
    max = A * B;

  printf("%d", max);
  return 0;
}
Problem p03337 (Python)

Buggy submission (status: Runtime Error):
A, B = map(int, input())

print(max([A + B, A - B, A * B]))


Fixed submission:
A, B = map(int, input().split())

print(max([A + B, A - B, A * B]))
Problem p03337 (Python)

Buggy submission (status: Runtime Error):
A, B = list(map(int, input().split()))
print(max(A + B, max(A - B.A * B)))


Fixed submission:
A, B = list(map(int, input().split()))
print(max(A + B, max(A - B, A * B)))