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

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

int he, le, a[501][501] = {0}, i, j, q[maxn], w[maxn], e[maxn], r[maxn],
            now = 0;

int main() {
  cin >> he >> le;
  for (i = 1; i <= he; i++) {
    for (j = 1; j <= le; j++) {
      cin >> a[i][j];
    }
  }
  for (i = 1; i <= he; i++) {
    for (j = 1; j <= le; j++) {
      if (a[i][j] % 2 == 0)
        continue;
      else if (a[i][j + 1] % 2 && j + 1 <= le) {
        a[i][j + 1] += 1;
        now++;
        q[now] = i;
        w[now] = j;
        e[now] = i;
        r[now] = j + 1;
      } else if (a[i + 1][j] % 2 && i + 1 <= he) {
        a[i + 1][j] += 1;
        now++;
        q[now] = i;
        w[now] = j;
        e[now] = i + 1;
        r[now] = j;
      } else if (j + 1 <= le) {
        a[i][j + 1] += 1;
        now++;
        q[now] = i;
        w[now] = j;
        e[now] = i;
        r[now] = j + 1;
      } else if (i + 1 <= he) {
        a[i + 1][j] += 1;
        now++;
        q[now] = i;
        w[now] = j;
        e[now] = i + 1;
        r[now] = j;
      }
    }
  }
  cout << now << endl;
  for (i = 1; i <= now; i++) {
    cout << q[i] << ' ' << w[i] << ' ' << e[i] << ' ' << r[i] << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300001;

int he, le, a[501][501] = {0}, i, j, q[maxn], w[maxn], e[maxn], r[maxn],
            now = 0;

int main() {
  cin >> he >> le;
  for (i = 1; i <= he; i++) {
    for (j = 1; j <= le; j++) {
      cin >> a[i][j];
    }
  }
  for (i = 1; i <= he; i++) {
    for (j = 1; j <= le; j++) {
      if (a[i][j] % 2 == 0)
        continue;
      else if (a[i][j + 1] % 2 && j + 1 <= le) {
        a[i][j + 1] += 1;
        now++;
        q[now] = i;
        w[now] = j;
        e[now] = i;
        r[now] = j + 1;
      } else if (a[i + 1][j] % 2 && i + 1 <= he) {
        a[i + 1][j] += 1;
        now++;
        q[now] = i;
        w[now] = j;
        e[now] = i + 1;
        r[now] = j;
      } else if (j + 1 <= le) {
        a[i][j + 1] += 1;
        now++;
        q[now] = i;
        w[now] = j;
        e[now] = i;
        r[now] = j + 1;
      } else if (i + 1 <= he) {
        a[i + 1][j] += 1;
        now++;
        q[now] = i;
        w[now] = j;
        e[now] = i + 1;
        r[now] = j;
      }
    }
  }
  cout << now << endl;
  for (i = 1; i <= now; i++) {
    cout << q[i] << ' ' << w[i] << ' ' << e[i] << ' ' << r[i] << endl;
  }
  return 0;
}
Problem p03263 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>
using namespace std;
int main(void) {
  int i, j, h, w, a[501][501], q[25000][2], p1, p2, p3, x, y, x1, y1;
  int n, xy[25000][4];
  scanf("%d %d", &h, &w);
  for (i = 1; i <= h; i++) {
    for (j = 1; j <= w; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  p1 = 0;
  for (i = 1; i <= h; i++) {
    if (i % 2 == 1) {
      for (j = 1; j <= w; j++) {
        q[p1][0] = i;
        q[p1][1] = j;
        p1++;
      }
    } else {
      for (j = w; j >= 1; j--) {
        q[p1][0] = i;
        q[p1][1] = j;
        p1++;
      }
    }
  }
  p2 = 0;
  for (i = 0; i < p1 - 1; i++) {
    y = q[i][0];
    x = q[i][1];
    y1 = q[i + 1][0];
    x1 = q[i + 1][1];
    if (a[y][x] % 2 == 1) {
      a[y][x]--;
      a[y1][x1]++;
      xy[p2][0] = y;
      xy[p2][1] = x;
      xy[p2][2] = y1;
      xy[p2][3] = x1;
      p2++;
    }
  }
  printf("%d\n", p2);
  for (i = 0; i < p2; i++) {
    printf("%d %d %d %d\n", xy[i][0], xy[i][1], xy[i][2], xy[i][3]);
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>
using namespace std;
int main(void) {
  int i, j, h, w, a[501][501], q[250000][2], p1, p2, p3, x, y, x1, y1;
  int n, xy[250000][4];
  scanf("%d %d", &h, &w);
  for (i = 1; i <= h; i++) {
    for (j = 1; j <= w; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  p1 = 0;
  for (i = 1; i <= h; i++) {
    if (i % 2 == 1) {
      for (j = 1; j <= w; j++) {
        q[p1][0] = i;
        q[p1][1] = j;
        p1++;
      }
    } else {
      for (j = w; j >= 1; j--) {
        q[p1][0] = i;
        q[p1][1] = j;
        p1++;
      }
    }
  }
  p2 = 0;
  for (i = 0; i < p1 - 1; i++) {
    y = q[i][0];
    x = q[i][1];
    y1 = q[i + 1][0];
    x1 = q[i + 1][1];
    if (a[y][x] % 2 == 1) {
      a[y][x]--;
      a[y1][x1]++;
      xy[p2][0] = y;
      xy[p2][1] = x;
      xy[p2][2] = y1;
      xy[p2][3] = x1;
      p2++;
    }
  }
  printf("%d\n", p2);
  for (i = 0; i < p2; i++) {
    printf("%d %d %d %d\n", xy[i][0], xy[i][1], xy[i][2], xy[i][3]);
  }
  return 0;
}
Problem p03263 (C++)

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

int main() {
  int h, w, a[50005], i, j, cnt = 0;
  bool odd = false, t = false;
  scanf("%d%d", &h, &w);
  for (i = 0; i < h; i++)
    for (j = 0; j < w; j++)
      scanf("%d", &a[i * w + (i % 2 ? j : w - 1 - j)]);
  for (i = 0; i < h * w; i++) {
    if (odd)
      cnt++;
    if (a[i] % 2)
      odd ^= true;
  }
  printf("%d\n", cnt);

  for (i = 0; i < h * w; i++) {
    if (t)
      printf("%d %d %d %d\n", (i - 1) / w + 1,
             ((i - 1) / w % 2 ? (i - 1) % w : w - 1 - (i - 1) % w) + 1,
             i / w + 1, (i / w % 2 ? i % w : w - 1 - i % w) + 1);
    if (a[i] % 2)
      t ^= true;
  }
}


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

int main() {
  int h, w, a[250005], i, j, cnt = 0;
  bool odd = false, t = false;
  scanf("%d%d", &h, &w);
  for (i = 0; i < h; i++)
    for (j = 0; j < w; j++)
      scanf("%d", &a[i * w + (i % 2 ? j : w - 1 - j)]);
  for (i = 0; i < h * w; i++) {
    if (odd)
      cnt++;
    if (a[i] % 2)
      odd ^= true;
  }
  printf("%d\n", cnt);

  for (i = 0; i < h * w; i++) {
    if (t)
      printf("%d %d %d %d\n", (i - 1) / w + 1,
             ((i - 1) / w % 2 ? (i - 1) % w : w - 1 - (i - 1) % w) + 1,
             i / w + 1, (i / w % 2 ? i % w : w - 1 - i % w) + 1);
    if (a[i] % 2)
      t ^= true;
  }
}
Problem p03263 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn = 510;
int n, m;
int a[maxn][maxn], b[maxn][5];

int main() {
  int ans = 0;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      scanf("%d", &a[i][j]);

  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m - 1; j++) {
      if (a[i][j] & 1) {
        b[ans][1] = i;
        b[ans][2] = j;
        b[ans][3] = i;
        b[ans][4] = j + 1;
        ans++;
        a[i][j + 1]++;
      }
    }

  for (int i = 1; i <= n - 1; i++) {
    if (a[i][m] & 1) {
      b[ans][1] = i;
      b[ans][2] = m;
      b[ans][3] = i + 1;
      b[ans][4] = m;
      ans++;
      a[i + 1][m]++;
    }
  }

  printf("%d\n", ans);
  for (int i = 0; i < ans; i++)
    printf("%d %d %d %d\n", b[i][1], b[i][2], b[i][3], b[i][4]);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn = 510;
int n, m;
int a[maxn][maxn], b[maxn * maxn][5];

int main() {
  int ans = 0;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      scanf("%d", &a[i][j]);

  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m - 1; j++) {
      if (a[i][j] & 1) {
        b[ans][1] = i;
        b[ans][2] = j;
        b[ans][3] = i;
        b[ans][4] = j + 1;
        ans++;
        a[i][j + 1]++;
      }
    }

  for (int i = 1; i <= n - 1; i++) {
    if (a[i][m] & 1) {
      b[ans][1] = i;
      b[ans][2] = m;
      b[ans][3] = i + 1;
      b[ans][4] = m;
      ans++;
      a[i + 1][m]++;
    }
  }

  printf("%d\n", ans);
  for (int i = 0; i < ans; i++)
    printf("%d %d %d %d\n", b[i][1], b[i][2], b[i][3], b[i][4]);
  return 0;
}
Problem p03263 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF = 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int, int> P;

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<int>> vec(H, vector<int>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> vec.at(i).at(j);
    }
  }
  vector<pair<P, P>> ret;
  for (int i = 0; i < H; i++) {
    if (i % 2 == 0) {
      for (int j = 0; j < W - 1; j++) {
        if (vec.at(i).at(j) % 2 == 1) {
          ret.push_back(make_pair(P(i, j), P(i, j + 1)));
          vec.at(i).at(j + 1)++;
        }
      }
      if (vec.at(i).at(W - 1) % 2 == 1 && i != H - 1) {
        ret.push_back(make_pair(P(i, W - 1), P(i + 1, W - 1)));
        vec.at(i + 1).at(W + 1)++;
      }
    } else {
      for (int j = W - 1; j >= 1; j--) {
        if (vec.at(i).at(j) % 2 == 1) {
          ret.push_back(make_pair(P(i, j), P(i, j - 1)));
          vec.at(i).at(j - 1)++;
        }
      }
      if (vec.at(i).at(0) % 2 == 1 && i != H - 1) {
        ret.push_back(make_pair(P(i, 0), P(i + 1, 0)));
        vec.at(i + 1).at(0)++;
      }
    }
  }
  cout << ret.size() << endl;
  for (int i = 0; i < ret.size(); i++) {
    cout << ret.at(i).first.first + 1 << " " << ret.at(i).first.second + 1
         << " " << ret.at(i).second.first + 1 << " "
         << ret.at(i).second.second + 1 << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF = 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int, int> P;

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<int>> vec(H, vector<int>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> vec.at(i).at(j);
    }
  }
  vector<pair<P, P>> ret;
  for (int i = 0; i < H; i++) {
    if (i % 2 == 0) {
      for (int j = 0; j < W - 1; j++) {
        if (vec.at(i).at(j) % 2 == 1) {
          ret.push_back(make_pair(P(i, j), P(i, j + 1)));
          vec.at(i).at(j + 1)++;
        }
      }
      if (vec.at(i).at(W - 1) % 2 == 1 && i != H - 1) {
        ret.push_back(make_pair(P(i, W - 1), P(i + 1, W - 1)));
        vec.at(i + 1).at(W - 1)++;
      }
    } else {
      for (int j = W - 1; j >= 1; j--) {
        if (vec.at(i).at(j) % 2 == 1) {
          ret.push_back(make_pair(P(i, j), P(i, j - 1)));
          vec.at(i).at(j - 1)++;
        }
      }
      if (vec.at(i).at(0) % 2 == 1 && i != H - 1) {
        ret.push_back(make_pair(P(i, 0), P(i + 1, 0)));
        vec.at(i + 1).at(0)++;
      }
    }
  }
  cout << ret.size() << endl;
  for (int i = 0; i < ret.size(); i++) {
    cout << ret.at(i).first.first + 1 << " " << ret.at(i).first.second + 1
         << " " << ret.at(i).second.first + 1 << " "
         << ret.at(i).second.second + 1 << endl;
  }
}
Problem p03263 (Python)

Buggy submission (status: Runtime Error):
import sys

sys.setrecursionlimit(10**6)
INF = float("inf")
MOD = 10**9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    H, W = map(int, input().split())
    A = []
    cnt = 0
    for _ in range(H):
        a = list(map(int, input().split()))
        cnt += sum(a)
        A.append(a)

    ans = []
    for h in range(H):
        if h % 2 == 0:
            for w in range(W):
                if h == H - 1 and w == W - 1:
                    continue
                if A[h][w] % 2 == 1:
                    if w == W:
                        A[h][w] -= 1
                        A[h + 1][w] += 1
                        ans.append((h, w, h + 1, w))
                    else:
                        A[h][w] -= 1
                        A[h][w + 1] += 1
                        ans.append((h, w, h, w + 1))
                else:
                    continue
        else:
            for w in range(W)[::-1]:
                if h == H - 1 and w == 0:
                    continue
                if A[h][w] % 2 == 1:
                    if w == 0:
                        A[h][w] -= 1
                        A[h + 1][w] += 1
                        ans.append((h, w, h + 1, w))
                    else:
                        A[h][w] -= 1
                        A[h][w - 1] += 1
                        ans.append((h, w, h, w - 1))
                else:
                    continue

    print(len(ans))
    for a, b, c, d in ans:
        print(a + 1, b + 1, c + 1, d + 1)


if __name__ == "__main__":
    main()


Fixed submission:
import sys

sys.setrecursionlimit(10**6)
INF = float("inf")
MOD = 10**9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    H, W = map(int, input().split())
    A = []
    cnt = 0
    for _ in range(H):
        a = list(map(int, input().split()))
        cnt += sum(a)
        A.append(a)

    ans = []
    for h in range(H):
        if h % 2 == 0:
            for w in range(W):
                if h == H - 1 and w == W - 1:
                    continue
                if A[h][w] % 2 == 1:
                    if w == W - 1:
                        A[h][w] -= 1
                        A[h + 1][w] += 1
                        ans.append((h, w, h + 1, w))
                    else:
                        A[h][w] -= 1
                        A[h][w + 1] += 1
                        ans.append((h, w, h, w + 1))
                else:
                    continue
        else:
            for w in range(W)[::-1]:
                if h == H - 1 and w == 0:
                    continue
                if A[h][w] % 2 == 1:
                    if w == 0:
                        A[h][w] -= 1
                        A[h + 1][w] += 1
                        ans.append((h, w, h + 1, w))
                    else:
                        A[h][w] -= 1
                        A[h][w - 1] += 1
                        ans.append((h, w, h, w - 1))
                else:
                    continue

    print(len(ans))
    for a, b, c, d in ans:
        print(a + 1, b + 1, c + 1, d + 1)


if __name__ == "__main__":
    main()
Problem p03263 (C++)

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define VI vector<int>
#define VVI vector<vector<int>>
#define MOD 1000000007

using ll = long long int;
using P = pair<int, int>;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

const ll INF = (ll)1e19;
// const int INF=(1<<30);
int cnt = 0;
VVI ans;

void f(VVI &a, int i, int j, int ni, int nj) {
  if (a[i][j] % 2 == 1) {
    a[i][j] -= 1;
    a[ni][nj] += 1;
    cnt++;
    VI tmp = {i, j, ni, nj};
    ans.emplace_back(tmp);
  }
}

int main() {
  int h, w;
  cin >> h >> w;

  VVI a(h, VI(w, 0));

  REP(i, h) REP(j, w) cin >> a[i][j];

  int i = 0;
  int j = 0;

  do {
    if (i % 2 == 0) {
      if (j == w - 1) {
        f(a, i, j, i + 1, j);
        i++;
      } else {
        f(a, i, j, i, j + 1);
        j++;
      }
    } else {
      if (j == 0) {
        f(a, i, j, i + 1, j);
        i++;
      } else {
        f(a, i, j, i, j - 1);
        j--;
      }
    }
  } while (!(i == h - 1 && (i % 2 == 0 && j == w - 1 || i % 2 == 1 && j == 0)));

  cout << cnt << endl;
  for (auto v : ans) {
    REP(i, 4) { cout << v[i] + 1 << (i == 3 ? "\n" : " "); }
  }
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define VI vector<int>
#define VVI vector<vector<int>>
#define MOD 1000000007

using ll = long long int;
using P = pair<int, int>;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

const ll INF = (ll)1e19;
// const int INF=(1<<30);
int cnt = 0;
VVI ans;

void f(VVI &a, int i, int j, int ni, int nj) {
  if (a[i][j] % 2 == 1) {
    a[i][j] -= 1;
    a[ni][nj] += 1;
    cnt++;
    VI tmp = {i, j, ni, nj};
    ans.emplace_back(tmp);
  }
}

int main() {
  int h, w;
  cin >> h >> w;

  if (h == 1 && w == 1) {
    cout << 0 << endl;
    return 0;
  }

  VVI a(h, VI(w, 0));

  REP(i, h) REP(j, w) cin >> a[i][j];

  int i = 0;
  int j = 0;

  do {
    if (i % 2 == 0) {
      if (j == w - 1) {
        f(a, i, j, i + 1, j);
        i++;
      } else {
        f(a, i, j, i, j + 1);
        j++;
      }
    } else {
      if (j == 0) {
        f(a, i, j, i + 1, j);
        i++;
      } else {
        f(a, i, j, i, j - 1);
        j--;
      }
    }
  } while (!(i == h - 1 && (i % 2 == 0 && j == w - 1 || i % 2 == 1 && j == 0)));

  cout << cnt << endl;
  for (auto v : ans) {
    REP(i, 4) { cout << v[i] + 1 << (i == 3 ? "\n" : " "); }
  }
}
Problem p03263 (C++)

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

#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;
using ll = long long;

int H, W;
bool used[500][500];
int coin[500][500];
int mov[250000][4];
int vecidx = 0;
pair<int, int> vec[4] = {make_pair(0, 1), make_pair(1, 0), make_pair(0, -1),
                         make_pair(-1, 0)};

void solve();

void init() { rep(i, 500) rep(j, 500) used[i][j] = true; }

bool direction(int x, int y) {
  int kari_x = x + vec[vecidx].first;
  int kari_y = y + vec[vecidx].second;
  return !(!used[kari_x][kari_y] && 0 <= kari_x && kari_x < H && 0 <= kari_y &&
           kari_y < W);
}

int main(void) {
  cin >> H >> W;
  init();
  rep(i, H) rep(j, W) used[i][j] = false;

  rep(i, H) rep(j, W) cin >> coin[i][j];
  int x = 0, y = 0;
  int cnt = 0;
  while (!used[x][y]) {
    used[x][y] = true;
    if (direction(x, y)) {
      if (vecidx == 3)
        vecidx = 0;
      else
        vecidx++;
    }
    if (direction(x, y))
      break;

    int next_x = x + vec[vecidx].first;
    int next_y = y + vec[vecidx].second;
    if (coin[x][y] % 2 == 1) {
      coin[x][y]--;
      coin[next_x][next_y]++;
      mov[cnt][0] = x + 1;
      mov[cnt][1] = y + 1;
      mov[cnt][2] = next_x + 1;
      mov[cnt][3] = next_y + 1;
      cnt++;
    }
    x = next_x;
    y = next_y;
  }
  cout << cnt << endl;
  rep(i, cnt) {
    rep(j, 4) {
      if (j == 3)
        cout << mov[i][j] << endl;
      else
        cout << mov[i][j] << " ";
    }
  }
  return 0;
}

void solve() {}

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

#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;
using ll = long long;

int H, W;
bool used[500][500];
int coin[500][500];
int mov[250000][4];
int vecidx = 0;
pair<int, int> vec[4] = {make_pair(0, 1), make_pair(1, 0), make_pair(0, -1),
                         make_pair(-1, 0)};

void solve();

void init() { rep(i, 500) rep(j, 500) used[i][j] = true; }

bool direction(int x, int y) {
  int kari_x = x + vec[vecidx].first;
  int kari_y = y + vec[vecidx].second;
  return !(0 <= kari_x && kari_x < H && 0 <= kari_y && kari_y < W &&
           !used[kari_x][kari_y]);
}

int main(void) {
  cin >> H >> W;
  init();
  rep(i, H) rep(j, W) used[i][j] = false;

  rep(i, H) rep(j, W) cin >> coin[i][j];
  int x = 0, y = 0;
  int cnt = 0;
  while (!used[x][y]) {
    used[x][y] = true;
    if (direction(x, y)) {
      if (vecidx == 3)
        vecidx = 0;
      else
        vecidx++;
    }
    if (direction(x, y))
      break;

    int next_x = x + vec[vecidx].first;
    int next_y = y + vec[vecidx].second;
    if (coin[x][y] % 2 == 1) {
      coin[x][y]--;
      coin[next_x][next_y]++;
      mov[cnt][0] = x + 1;
      mov[cnt][1] = y + 1;
      mov[cnt][2] = next_x + 1;
      mov[cnt][3] = next_y + 1;
      cnt++;
    }
    x = next_x;
    y = next_y;
  }
  cout << cnt << endl;
  rep(i, cnt) {
    rep(j, 4) {
      if (j == 3)
        cout << mov[i][j] << endl;
      else
        cout << mov[i][j] << " ";
    }
  }
  return 0;
}

void solve() {}
Problem p03263 (C++)

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

#define rep(n) for (int i = 0; i < n; i++)
#define repp(j, n) for (int j = 0; j < n; j++)
#define reppp(i, m, n) for (int i = m; i < n; i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;
const long double EPS = 10e-10;

int main() {
  std::ios::sync_with_stdio(0);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  int a[h][w];
  rep(h) repp(j, w) { cin >> a[i][j]; }

  int n = 0;
  int ans[500][4];
  rep(h) {
    repp(j, w) {
      if (i == h - 1 && j == w - 1)
        break;
      if (a[i][j] % 2 == 0)
        continue;
      a[i][j]--;
      ans[n][0] = i + 1;
      ans[n][1] = j + 1;
      if (j == w - 1) {
        a[i + 1][j]++;
        ans[n][2] = i + 2;
        ans[n][3] = j + 1;
      } else {
        a[i][j + 1]++;
        ans[n][2] = i + 1;
        ans[n][3] = j + 2;
      }
      n++;
    }
  }

  cout << n << endl;
  rep(n) {
    cout << ans[i][0] << " " << ans[i][1] << " " << ans[i][2] << " "
         << ans[i][3] << endl;
  }
  return 0;
}


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

#define rep(n) for (int i = 0; i < n; i++)
#define repp(j, n) for (int j = 0; j < n; j++)
#define reppp(i, m, n) for (int i = m; i < n; i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;
const long double EPS = 10e-10;

int main() {
  std::ios::sync_with_stdio(0);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  int a[h][w];
  rep(h) repp(j, w) { cin >> a[i][j]; }

  int n = 0;
  int ans[500 * 500 + 10][4];
  rep(h) {
    repp(j, w) {
      if (i == h - 1 && j == w - 1)
        break;
      if (a[i][j] % 2 == 0)
        continue;
      a[i][j]--;
      ans[n][0] = i + 1;
      ans[n][1] = j + 1;
      if (j == w - 1) {
        a[i + 1][j]++;
        ans[n][2] = i + 2;
        ans[n][3] = j + 1;
      } else {
        a[i][j + 1]++;
        ans[n][2] = i + 1;
        ans[n][3] = j + 2;
      }
      n++;
    }
  }

  cout << n << endl;
  rep(n) {
    cout << ans[i][0] << " " << ans[i][1] << " " << ans[i][2] << " "
         << ans[i][3] << endl;
  }
  return 0;
}
Problem p03263 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<int>> a(h + 1, vector<int>(w + 1, 0));
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> a[i][j];
    }
  }

  int count = 0;
  int y_prev[25000] = {}, x_prev[25000] = {}, y_next[25000] = {},
      x_next[25000] = {};
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j < w; j++) {
      if (a[i][j] % 2 == 1) {
        a[i][j]--;
        y_prev[count] = i;
        x_prev[count] = j;
        a[i][j + 1]++;
        y_next[count] = i;
        x_next[count] = j + 1;
        count++;
      }
    }

    if (a[i][w] % 2 == 1 && i < h) {
      a[i][w]--;
      y_prev[count] = i;
      x_prev[count] = w;
      a[i + 1][w]++;
      y_next[count] = i + 1;
      x_next[count] = w;
      count++;
    }
  }

  cout << count << endl;
  for (int i = 0; i < count; i++) {
    cout << y_prev[i] << " " << x_prev[i] << " " << y_next[i] << " "
         << x_next[i] << endl;
  }
}

Fixed submission:
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<int>> a(h + 1, vector<int>(w + 1, 0));
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> a[i][j];
    }
  }

  int count = 0;
  int y_prev[250000] = {}, x_prev[250000] = {}, y_next[250000] = {},
      x_next[250000] = {};
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j < w; j++) {
      if (a[i][j] % 2 == 1) {
        a[i][j]--;
        y_prev[count] = i;
        x_prev[count] = j;
        a[i][j + 1]++;
        y_next[count] = i;
        x_next[count] = j + 1;
        count++;
      }
    }

    if (a[i][w] % 2 == 1 && i < h) {
      a[i][w]--;
      y_prev[count] = i;
      x_prev[count] = w;
      a[i + 1][w]++;
      y_next[count] = i + 1;
      x_next[count] = w;
      count++;
    }
  }

  cout << count << endl;
  for (int i = 0; i < count; i++) {
    cout << y_prev[i] << " " << x_prev[i] << " " << y_next[i] << " "
         << x_next[i] << endl;
  }
}
Problem p03263 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define FOR(i, s, e) for (int i = (s); i < (e); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
using namespace std;
typedef long long LL;
typedef pair<int, int> P;

int a[510][510];
int step[30000][4];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int H, W;
  cin >> H >> W;

  REP(i, H) REP(j, W) cin >> a[i][j];
  int ans = 0;
  REP(i, H) REP(j, W - 1) {
    if (a[i][j] % 2) {
      step[ans][0] = i;
      step[ans][2] = i;
      step[ans][1] = j;
      step[ans][3] = j + 1;
      ++ans;
      a[i][j]--;
      a[i][j + 1]++;
    }
  }

  REP(i, H - 1) {
    int j = W - 1;
    if (a[i][j] % 2) {
      step[ans][0] = i;
      step[ans][2] = i + 1;
      step[ans][1] = j;
      step[ans][3] = j;
      ++ans;
      a[i][j]--;
      a[i + 1][j]++;
    }
  }

  cout << ans << endl;
  REP(i, ans) REP(j, 4) cout << step[i][j] + 1 << (j == 3 ? "\n" : " ");

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define FOR(i, s, e) for (int i = (s); i < (e); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
using namespace std;
typedef long long LL;
typedef pair<int, int> P;

int a[510][510];
int step[250000][4];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int H, W;
  cin >> H >> W;

  REP(i, H) REP(j, W) cin >> a[i][j];
  int ans = 0;
  REP(i, H) REP(j, W - 1) {
    if (a[i][j] % 2) {
      step[ans][0] = i;
      step[ans][2] = i;
      step[ans][1] = j;
      step[ans][3] = j + 1;
      ++ans;
      a[i][j]--;
      a[i][j + 1]++;
    }
  }

  REP(i, H - 1) {
    int j = W - 1;
    if (a[i][j] % 2) {
      step[ans][0] = i;
      step[ans][2] = i + 1;
      step[ans][1] = j;
      step[ans][3] = j;
      ++ans;
      a[i][j]--;
      a[i + 1][j]++;
    }
  }

  cout << ans << endl;
  REP(i, ans) REP(j, 4) cout << step[i][j] + 1 << (j == 3 ? "\n" : " ");

  return 0;
}
Problem p03263 (Python)

Buggy submission (status: Runtime Error):
def solve(string):
    ins = string.split("\n")
    h, w = map(int, ins[0].split(" "))
    cells = [list(map(lambda x: int(x) % 2 == 1, _i.split(" "))) for _i in ins[1:]]

    command = []
    for i in range(h):
        for j in range(w):
            if cells[i][j]:
                if j < w - 1:
                    cells[i][j + 1] ^= True
                    command.append("{} {} {} {}".format(i + 1, j + 1, i + 1, j + 2))
                elif i < h - 1:
                    cells[i + 1][j] ^= True
                    command.append("{} {} {} {}".format(i + 1, j + 1, i + 2, j + 1))
    command.insert(0, str(len(command)))
    return "\n".join(command)
    """
    ins = string.split("\n")
    h, w = map(int, ins[0].split(" "))
    a = [list(map(lambda x: int(x) % 2 == 1, _i.split(" "))) for _i in ins[1:]]
    move = []
    v_flag = False
    h_flag = False
    for i, _a in enumerate(a):
        for j, __a in enumerate(_a):
            curr = __a
            if h_flag:
                curr = not curr
                h_flag = False
            if j == w - 1 and v_flag:
                curr = not curr
                v_flag = False
            if not curr:
                continue
            if j < w - 1:
                h_flag = True
                move.append("{} {} {} {}".format(i + 1, j + 1, i + 1, j + 2))
            elif i < h - 1:
                v_flag = True
                move.append("{} {} {} {}".format(i + 1, j + 1, i + 2, j + 1))
    move.insert(0, str(len(move)))
    return "\n".join(move)
    """


if __name__ == "__main__":
    line = input()
    tmp = [line]
    for _ in range(int(line[0])):
        tmp.append(input())
    print(solve("\n".join(tmp)))


Fixed submission:
h, w = map(int, input().split(" "))
a = [list(map(lambda x: int(x) % 2 == 1, input().split(" "))) for _i in range(h)]
move = []
for i in range(h):
    for j in range(w):
        if not a[i][j]:
            continue
        if j < w - 1:
            a[i][j + 1] ^= True
            move.append("{} {} {} {}".format(i + 1, j + 1, i + 1, j + 2))
        elif i < h - 1:
            a[i + 1][j] ^= True
            move.append("{} {} {} {}".format(i + 1, j + 1, i + 2, j + 1))
move.insert(0, str(len(move)))
print("\n".join(move))
Problem p03263 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); (i)++)
#define rrep(i, s, e) for (int(i) = (s); (i) >= (e); (i)--)

int a[505][505];
vector<int> px;
vector<int> py;
vector<int> mx;
vector<int> my;

signed main() {
  int h, w;
  cin >> h >> w;

  if (h == 1 && w == 1) {
    cout << 0 << endl;
    return 0;
  }
  rep(i, 0, h - 1) rep(j, 0, w - 1) cin >> a[i][j];

  rep(i, 0, h - 1) rep(j, 0, w - 1) {
    if (i == h - 1 && j == w - 1)
      break;

    if (a[i][j] % 2) {
      px.push_back(i);
      py.push_back(j);

      if (j != w - 1) {
        mx.push_back(i);
        my.push_back(j + 1);
        a[i][j + 1]++;
      } else {
        mx.push_back(i + 1);
        my.push_back(j);
        a[i + 1][j]++;
      }
    }
  }
  if (mx.empty()) {
    cout << 0 << endl;
    return 9;
  }
  cout << mx.size() << endl;
  rep(i, 0, mx.size() - 1) cout << px[i] + 1 << " " << py[i] + 1 << " "
                                << mx[i] + 1 << " " << my[i] + 1 << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); (i)++)
#define rrep(i, s, e) for (int(i) = (s); (i) >= (e); (i)--)

int a[505][505];
vector<int> px;
vector<int> py;
vector<int> mx;
vector<int> my;

signed main() {
  int h, w;
  cin >> h >> w;

  if (h == 1 && w == 1) {
    cout << 0 << endl;
    return 0;
  }
  rep(i, 0, h - 1) rep(j, 0, w - 1) cin >> a[i][j];

  rep(i, 0, h - 1) rep(j, 0, w - 1) {
    if (i == h - 1 && j == w - 1)
      break;

    if (a[i][j] % 2) {
      px.push_back(i);
      py.push_back(j);

      if (j != w - 1) {
        mx.push_back(i);
        my.push_back(j + 1);
        a[i][j + 1]++;
      } else {
        mx.push_back(i + 1);
        my.push_back(j);
        a[i + 1][j]++;
      }
    }
  }
  if (mx.empty()) {
    cout << 0 << endl;
    return 0;
  }
  cout << mx.size() << endl;
  rep(i, 0, mx.size() - 1) cout << px[i] + 1 << " " << py[i] + 1 << " "
                                << mx[i] + 1 << " " << my[i] + 1 << endl;
}
Problem p03263 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
typedef long long ll;
#define rep(i, s, n) for (ll i = s; i < n; i++)
#define repe(i, s, n) for (ll i = s; i <= n; i++)
static const double PI = 3.1415926535897932384626433;
static const ll LL_MAX = (ll)1 << 62;
static const ll MOD = 1000000007;

ll y_1[100000];
ll x1[100000];
ll y2[100000];
ll x2[100000];
ll a[501][501] = {};

int main() {
  ll h, w;
  cin >> h >> w;
  repe(i, 1, h) repe(j, 1, w) cin >> a[i][j];

  ll cnt = 0;
  repe(i, 1, h) rep(j, 1, w) {
    if (a[i][j] & 1) {
      a[i][j]--;
      a[i][j + 1]++;
      y_1[cnt] = i;
      x1[cnt] = j;
      y2[cnt] = i;
      x2[cnt] = j + 1;
      cnt++;
    }
  }

  rep(i, 1, h) {
    if (a[i][w] & 1) {
      a[i][w]--;
      a[i + 1][w]++;

      y_1[cnt] = i;
      x1[cnt] = w;
      y2[cnt] = i + 1;
      x2[cnt] = w;
      cnt++;
    }
  }
  cout << cnt << endl;
  rep(i, 0, cnt) {
    cout << y_1[i] << " " << x1[i] << " " << y2[i] << " " << x2[i] << endl;
  }

  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
typedef long long ll;
#define rep(i, s, n) for (ll i = s; i < n; i++)
#define repe(i, s, n) for (ll i = s; i <= n; i++)
static const double PI = 3.1415926535897932384626433;
static const ll LL_MAX = (ll)1 << 62;
static const ll MOD = 1000000007;

ll y_1[300000];
ll x1[300000];
ll y2[300000];
ll x2[300000];
ll a[501][501] = {};

int main() {
  ll h, w;
  cin >> h >> w;
  repe(i, 1, h) repe(j, 1, w) cin >> a[i][j];

  ll cnt = 0;
  repe(i, 1, h) rep(j, 1, w) {
    if (a[i][j] & 1) {
      a[i][j]--;
      a[i][j + 1]++;
      y_1[cnt] = i;
      x1[cnt] = j;
      y2[cnt] = i;
      x2[cnt] = j + 1;
      cnt++;
    }
  }

  rep(i, 1, h) {
    if (a[i][w] & 1) {
      a[i][w]--;
      a[i + 1][w]++;

      y_1[cnt] = i;
      x1[cnt] = w;
      y2[cnt] = i + 1;
      x2[cnt] = w;
      cnt++;
    }
  }
  cout << cnt << endl;
  rep(i, 0, cnt) {
    cout << y_1[i] << " " << x1[i] << " " << y2[i] << " " << x2[i] << endl;
  }

  return 0;
}
Problem p03263 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int map[501][501];
int ans[501][4];

typedef pair<int, int> P;

int N, H, W;

vector<P> odd_point;

int main() {

  cin >> H >> W;

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> map[i][j];
    }
  }

  vector<P> route;
  for (int i = 0; i < H; i++) {

    if (i % 2 == 0)
      for (int j = 0; j < W; j++)
        route.push_back(make_pair(i, j));
    else
      for (int j = W - 1; j >= 0; j--)
        route.push_back(make_pair(i, j));
  }

  bool odd = false;
  int N = 0;
  for (int i = 0; i < route.size() - 1; i++) {
    if (odd == false) {
      if (map[route[i].first][route[i].second] % 2 == 1) {
        odd = true;
        ans[N][0] = route[i].first;
        ans[N][1] = route[i].second;
        ans[N][2] = route[i + 1].first;
        ans[N][3] = route[i + 1].second;
        N++;
      }
    } else {
      if (map[route[i].first][route[i].second] % 2 == 1) {
        odd = false;
        continue;
      }
      ans[N][0] = route[i].first;
      ans[N][1] = route[i].second;
      ans[N][2] = route[i + 1].first;
      ans[N][3] = route[i + 1].second;
      N++;
    }
  }
  cout << N << '\n';
  for (int i = 0; i < N; i++) {
    cout << ans[i][0] + 1 << ' ' << ans[i][1] + 1 << ' ' << ans[i][2] + 1 << ' '
         << ans[i][3] + 1 << '\n';
  }
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int map[501][501];
int ans[250001][4];

typedef pair<int, int> P;

int N, H, W;

vector<P> odd_point;

int main() {

  cin >> H >> W;

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> map[i][j];
    }
  }

  vector<P> route;
  for (int i = 0; i < H; i++) {

    if (i % 2 == 0)
      for (int j = 0; j < W; j++)
        route.push_back(make_pair(i, j));
    else
      for (int j = W - 1; j >= 0; j--)
        route.push_back(make_pair(i, j));
  }

  bool odd = false;
  int N = 0;
  for (int i = 0; i < route.size() - 1; i++) {
    if (odd == false) {
      if (map[route[i].first][route[i].second] % 2 == 1) {
        odd = true;
        ans[N][0] = route[i].first;
        ans[N][1] = route[i].second;
        ans[N][2] = route[i + 1].first;
        ans[N][3] = route[i + 1].second;
        N++;
      }
    } else {
      if (map[route[i].first][route[i].second] % 2 == 1) {
        odd = false;
        continue;
      }
      ans[N][0] = route[i].first;
      ans[N][1] = route[i].second;
      ans[N][2] = route[i + 1].first;
      ans[N][3] = route[i + 1].second;
      N++;
    }
  }
  cout << N << '\n';
  for (int i = 0; i < N; i++) {
    cout << ans[i][0] + 1 << ' ' << ans[i][1] + 1 << ' ' << ans[i][2] + 1 << ' '
         << ans[i][3] + 1 << '\n';
  }
}
Problem p03263 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>

using namespace std;
int AftermoveLogX[2600];
int AftermoveLogY[2600];
int BeforemoveLogX[2600];
int BeforemoveLogY[2600];
int main(void) {
  int h, w;
  int n = 0;
  cin >> h >> w;
  int a[h][w];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> a[i][j];
    }
  }
  int moveindex;
  moveindex = 0;
  for (int i = 0; i < h - 1; i++) {
    for (int j = 0; j < w; j++) {
      if (a[i][j] % 2 == 1) {
        a[i + 1][j] += 1;
        a[i][j]--;
        n++;
        BeforemoveLogX[moveindex] = j + 1;
        BeforemoveLogY[moveindex] = i + 1;
        AftermoveLogX[moveindex] = j + 1;
        AftermoveLogY[moveindex] = i + 2;
        moveindex++;
      }
    }
  }

  for (int i = 0; i < w - 1; i++) {
    if (a[h - 1][i] % 2 == 1) {
      a[h - 1][i + 1]++;
      a[h - 1][i]--;
      BeforemoveLogX[moveindex] = i + 1;
      BeforemoveLogY[moveindex] = h;
      AftermoveLogX[moveindex] = i + 2;
      AftermoveLogY[moveindex] = h;
      moveindex++;
      n++;
    }
  }
  cout << n << endl;

  for (int i = 0; i < moveindex; i++) {
    cout << BeforemoveLogY[i] << " " << BeforemoveLogX[i] << " ";
    cout << AftermoveLogY[i] << " " << AftermoveLogX[i] << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;
int AftermoveLogX[250000];
int AftermoveLogY[250000];
int BeforemoveLogX[250000];
int BeforemoveLogY[250000];
int main(void) {
  int h, w;
  int n = 0;
  cin >> h >> w;
  int a[h][w];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> a[i][j];
    }
  }
  int moveindex;
  moveindex = 0;
  for (int i = 0; i < h - 1; i++) {
    for (int j = 0; j < w; j++) {
      if (a[i][j] % 2 == 1) {
        a[i + 1][j] += 1;
        a[i][j]--;
        n++;
        BeforemoveLogX[moveindex] = j + 1;
        BeforemoveLogY[moveindex] = i + 1;
        AftermoveLogX[moveindex] = j + 1;
        AftermoveLogY[moveindex] = i + 2;
        moveindex++;
      }
    }
  }

  for (int i = 0; i < w - 1; i++) {
    if (a[h - 1][i] % 2 == 1) {
      a[h - 1][i + 1]++;
      a[h - 1][i]--;
      BeforemoveLogX[moveindex] = i + 1;
      BeforemoveLogY[moveindex] = h;
      AftermoveLogX[moveindex] = i + 2;
      AftermoveLogY[moveindex] = h;
      moveindex++;
      n++;
    }
  }
  cout << n << endl;

  for (int i = 0; i < moveindex; i++) {
    cout << BeforemoveLogY[i] << " " << BeforemoveLogX[i] << " ";
    cout << AftermoveLogY[i] << " " << AftermoveLogX[i] << endl;
  }
  return 0;
}
Problem p03263 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
static const int MAX = 500;
static const int MAX_ANS = 2500;
bool a[MAX][MAX];

bool change(bool t) { return t ? false : true; }
int main(void) {
  int h, w;
  cin >> h >> w;

  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      int f;
      cin >> f;
      if (f % 2)
        a[i][j] = true;
    }
  }

  int x_1[MAX_ANS], x_2[MAX_ANS], y_1[MAX_ANS], y_2[MAX_ANS];
  int n = 0;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j < w; j++) {
      if (a[i][j]) {
        x_1[n] = i;
        x_2[n] = i;
        y_1[n] = j;
        y_2[n] = j + 1;
        n++;
        a[i][j] = false;
        a[i][j + 1] = change(a[i][j + 1]);
      }
    }
  }
  for (int i = 0; i < h; i++) {
    if (a[i][w]) {
      x_1[n] = i;
      x_2[n] = i + 1;
      y_1[n] = w;
      y_2[n] = w;
      n++;
      a[i][w] = true;
      a[i + 1][w] = change(a[i + 1][w]);
    }
  }

  cout << n << endl;
  for (int i = 0; i < n; i++)
    cout << x_1[i] << " " << y_1[i] << " " << x_2[i] << " " << y_2[i] << endl;
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
static const int MAX = 500;
static const int MAX_ANS = 2e5 + 5;
bool a[MAX][MAX];

bool change(bool t) { return t ? false : true; }
int main(void) {
  int h, w;
  cin >> h >> w;

  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      int f;
      cin >> f;
      if (f % 2)
        a[i][j] = true;
    }
  }

  int x_1[MAX_ANS], x_2[MAX_ANS], y_1[MAX_ANS], y_2[MAX_ANS];
  int n = 0;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j < w; j++) {
      if (a[i][j]) {
        x_1[n] = i;
        x_2[n] = i;
        y_1[n] = j;
        y_2[n] = j + 1;
        n++;
        a[i][j] = false;
        a[i][j + 1] = change(a[i][j + 1]);
      }
    }
  }
  for (int i = 0; i < h; i++) {
    if (a[i][w]) {
      x_1[n] = i;
      x_2[n] = i + 1;
      y_1[n] = w;
      y_2[n] = w;
      n++;
      a[i][w] = true;
      a[i + 1][w] = change(a[i + 1][w]);
    }
  }

  cout << n << endl;
  for (int i = 0; i < n; i++)
    cout << x_1[i] << " " << y_1[i] << " " << x_2[i] << " " << y_2[i] << endl;
  return 0;
}
Problem p03263 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int INF = 1e9;

int grid[505][505];
int ans[25005][4];
int main() {
  int h, w;
  cin >> h >> w;
  rep(i, h) rep(j, w) cin >> grid[i][j];
  int cnt = 0;

  rep(i, h) rep(j, w) {
    if (j == w - 1 && grid[i][j] % 2 == 1) {
      if (i == h - 1)
        continue;
      ans[cnt][0] = i + 1;
      ans[cnt][1] = w;
      ans[cnt][2] = i + 2;
      ans[cnt][3] = w;
      grid[i + 1][w - 1]++;
      cnt++;
      continue;
    }
    if (grid[i][j] % 2 == 1) {
      ans[cnt][0] = i + 1;
      ans[cnt][1] = j + 1;
      ans[cnt][2] = i + 1;
      ans[cnt][3] = j + 2;
      grid[i][j + 1]++;
      cnt++;
    }
  }

  cout << cnt << endl;
  rep(i, cnt) {
    printf("%d %d %d %d\n", ans[i][0], ans[i][1], ans[i][2], ans[i][3]);
  }
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int INF = 1e9;

int grid[505][505];
int ans[250005][4];
int main() {
  int h, w;
  cin >> h >> w;
  rep(i, h) rep(j, w) cin >> grid[i][j];
  int cnt = 0;

  rep(i, h) rep(j, w) {
    if (j == w - 1 && grid[i][j] % 2 == 1) {
      if (i == h - 1)
        continue;
      ans[cnt][0] = i + 1;
      ans[cnt][1] = w;
      ans[cnt][2] = i + 2;
      ans[cnt][3] = w;
      grid[i + 1][w - 1]++;
      cnt++;
      continue;
    }
    if (grid[i][j] % 2 == 1) {
      ans[cnt][0] = i + 1;
      ans[cnt][1] = j + 1;
      ans[cnt][2] = i + 1;
      ans[cnt][3] = j + 2;
      grid[i][j + 1]++;
      cnt++;
    }
  }

  cout << cnt << endl;
  rep(i, cnt) {
    printf("%d %d %d %d\n", ans[i][0], ans[i][1], ans[i][2], ans[i][3]);
  }
}
Problem p03263 (C++)

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<int>> a(h, vector<int>(w));
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++)
      cin >> a[i][j];

  vector<int> x1, y1, x2, y2;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (a[i][j] % 2 == 1) {
        a[i][j]--;
        if (i == h - 1 and j == h - 1)
          continue;
        if (j < w - 1 or i == h - 1) {
          a[i][j + 1]++;
          x1.push_back(i + 1);
          y1.push_back(j + 1);
          x2.push_back(i + 1);
          y2.push_back(j + 2);
        } else {
          a[i + 1][j]++;
          x1.push_back(i + 1);
          y1.push_back(j + 1);
          x2.push_back(i + 2);
          y2.push_back(j + 1);
        }
      }
    }
  }

  cout << x1.size() << endl;
  for (int i = 0; i < x1.size(); i++)
    cout << x1[i] << ' ' << y1[i] << ' ' << x2[i] << ' ' << y2[i] << endl;

  return 0;
}


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

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<int>> a(h, vector<int>(w));
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++)
      cin >> a[i][j];

  vector<int> x1, y1, x2, y2;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (a[i][j] % 2 == 1) {
        a[i][j]--;
        if (i == h - 1 and j == w - 1)
          continue;
        if (j < w - 1 or i == h - 1) {
          a[i][j + 1]++;
          x1.push_back(i + 1);
          y1.push_back(j + 1);
          x2.push_back(i + 1);
          y2.push_back(j + 2);
        } else {
          a[i + 1][j]++;
          x1.push_back(i + 1);
          y1.push_back(j + 1);
          x2.push_back(i + 2);
          y2.push_back(j + 1);
        }
      }
    }
  }

  cout << x1.size() << endl;
  for (int i = 0; i < x1.size(); i++)
    cout << x1[i] << ' ' << y1[i] << ' ' << x2[i] << ' ' << y2[i] << endl;

  return 0;
}
Problem p03263 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#define MX 505

using namespace std;

int arr[MX][MX];
int opr[MX * 4][4], num;

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      scanf("%d", &arr[i][j]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j < m; j++)
      if (arr[i][j] & 1) {
        arr[i][j]--, arr[i][j + 1]++;
        num++;
        opr[num][0] = i;
        opr[num][1] = j;
        opr[num][2] = i;
        opr[num][3] = j + 1;
      }
  for (int i = 1; i < n; i++)
    if (arr[i][m] & 1) {
      arr[i][m]--, arr[i + 1][m]++;
      num++;
      opr[num][0] = i;
      opr[num][1] = m;
      opr[num][2] = i + 1;
      opr[num][3] = m;
    }
  printf("%d\n", num);
  for (int i = 1; i <= num; i++)
    printf("%d %d %d %d\n", opr[i][0], opr[i][1], opr[i][2], opr[i][3]);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#define MX 505

using namespace std;

int arr[MX][MX];
int opr[MX * MX][4], num;

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      scanf("%d", &arr[i][j]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j < m; j++)
      if (arr[i][j] & 1) {
        arr[i][j]--, arr[i][j + 1]++;
        num++;
        opr[num][0] = i;
        opr[num][1] = j;
        opr[num][2] = i;
        opr[num][3] = j + 1;
      }
  for (int i = 1; i < n; i++)
    if (arr[i][m] & 1) {
      arr[i][m]--, arr[i + 1][m]++;
      num++;
      opr[num][0] = i;
      opr[num][1] = m;
      opr[num][2] = i + 1;
      opr[num][3] = m;
    }
  printf("%d\n", num);
  for (int i = 1; i <= num; i++)
    printf("%d %d %d %d\n", opr[i][0], opr[i][1], opr[i][2], opr[i][3]);
  return 0;
}
Problem p03263 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int a[510][510];
struct move {
  int srx, sry, tx, ty;
} mv[2510];
int main() {
  // freopen("matrix.in","r",stdin);
  // freopen("matrix.out","w",stdout);
  int n, m, k = 0, i, j, count = 0;
  cin >> n >> m;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++)
      cin >> a[i][j];
  memset(mv, 0, sizeof(mv));
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m - 1; j++)
      if (a[i][j] % 2 == 1) {
        a[i][j]--;
        a[i][j + 1]++;
        k++;
        mv[k].srx = i;
        mv[k].sry = j;
        mv[k].tx = i;
        mv[k].ty = j + 1;
        count++;
      }
  for (i = 1; i <= n - 1; i++)
    if (a[i][m] % 2 == 1) {
      a[i][m]--;
      a[i + 1][m]++;
      k++;
      mv[k].srx = i, mv[k].sry = m, mv[k].tx = i + 1, mv[k].ty = m;
      count++;
    }
  cout << count << endl;
  for (i = 1; i <= k; i++)
    cout << mv[i].srx << " " << mv[i].sry << " " << mv[i].tx << " " << mv[i].ty
         << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int a[510][510];
struct move {
  int srx, sry, tx, ty;
} mv[250010];
int main() {
  // freopen("matrix.in","r",stdin);
  // freopen("matrix.out","w",stdout);
  int n, m, k = 0, i, j, count = 0;
  cin >> n >> m;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++)
      cin >> a[i][j];
  memset(mv, 0, sizeof(mv));
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m - 1; j++)
      if (a[i][j] % 2 == 1) {
        a[i][j]--;
        a[i][j + 1]++;
        k++;
        mv[k].srx = i;
        mv[k].sry = j;
        mv[k].tx = i;
        mv[k].ty = j + 1;
        count++;
      }
  for (i = 1; i <= n - 1; i++)
    if (a[i][m] % 2 == 1) {
      a[i][m]--;
      a[i + 1][m]++;
      k++;
      mv[k].srx = i, mv[k].sry = m, mv[k].tx = i + 1, mv[k].ty = m;
      count++;
    }
  cout << count << endl;
  for (i = 1; i <= k; i++)
    cout << mv[i].srx << " " << mv[i].sry << " " << mv[i].tx << " " << mv[i].ty
         << endl;
  return 0;
}