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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;

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<string> ans;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      stringstream ss;
      if (a[i][j] % 2 == 1) {
        if (j < w - 1) {
          a[i][j + 1]++;
          a[i][j]--;
          ss << i + 1 << " " << j + 1 << " " << i + 1 << " " << j + 2;
          ans.emplace_back(ss.str());
        } else if (i < h - 1) {
          a[i][j + 1]++;
          a[i][j]--;
          ss << i + 1 << " " << j + 1 << " " << i + 2 << " " << j + 1;
          ans.emplace_back(ss.str());
        }
      }
    }
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << endl;
  }
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;

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<string> ans;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      stringstream ss;
      if (a[i][j] % 2 == 1) {
        if (j < w - 1) {
          a[i][j + 1]++;
          a[i][j]--;
          ss << i + 1 << " " << j + 1 << " " << i + 1 << " " << j + 2;
          ans.emplace_back(ss.str());
        } else if (i < h - 1) {
          a[i + 1][j]++;
          a[i][j]--;
          ss << i + 1 << " " << j + 1 << " " << i + 2 << " " << j + 1;
          ans.emplace_back(ss.str());
        }
      }
    }
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << endl;
  }
}
Problem p03263 (Python)

Buggy submission (status: Runtime Error):
import sys


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


sys.setrecursionlimit(20000000)


def main():
    H, W = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(H)]
    answer = []
    for h in range(H):
        for w in range(W):
            if A[h][w] % 2 == 0:
                continue
            else:
                if h + 1 <= H - 1 and w + 1 <= W + 1:
                    if A[h + 1][w] % 2 == 1:
                        A[h + 1][w] += 1
                        answer.append([h + 1, w + 1, h + 2, w + 1])
                    else:
                        A[h][w + 1] += 1
                        answer.append([h + 1, w + 1, h + 1, w + 2])
                elif h + 1 <= H - 1:
                    A[h + 1][w] += 1
                    answer.append([h + 1, w + 1, h + 2, w + 1])
                elif w + 1 <= W - 1:
                    A[h][w + 1] += 1
                    answer.append([h + 1, w + 1, h + 1, w + 2])
                else:
                    continue
    N = len(answer)
    print(N)
    for i in range(N):
        print(*answer[i], sep=" ")


if __name__ == "__main__":
    main()


Fixed submission:
import sys


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


sys.setrecursionlimit(20000000)


def main():
    H, W = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(H)]
    answer = []
    for h in range(H):
        for w in range(W):
            if A[h][w] % 2 == 0:
                continue
            else:
                if h + 1 <= H - 1 and w + 1 <= W - 1:
                    if A[h + 1][w] % 2 == 1:
                        A[h + 1][w] += 1
                        answer.append([h + 1, w + 1, h + 2, w + 1])
                    else:
                        A[h][w + 1] += 1
                        answer.append([h + 1, w + 1, h + 1, w + 2])
                elif h + 1 <= H - 1:
                    A[h + 1][w] += 1
                    answer.append([h + 1, w + 1, h + 2, w + 1])
                elif w + 1 <= W - 1:
                    A[h][w + 1] += 1
                    answer.append([h + 1, w + 1, h + 1, w + 2])
                else:
                    continue
    N = len(answer)
    print(N)
    for i in range(N):
        print(*answer[i], sep=" ")


if __name__ == "__main__":
    main()
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 + 1, vector<int>(W + 1)), ans;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j < W; j++) {
      if (a[i][j] & 1) {
        ans.push_back({i, j, i, j + 1});
        a[i][j]--;
        a[i][j + 1]++;
      }
    }
  }
  for (int i = 1; i <= H; i++) {
    if (a[i][W] & 1) {
      ans.push_back({i, W, i + 1, W});
      a[i][W]--;
      a[i + 1][W]++;
    }
  }
  cout << ans.size() << endl;
  for (auto a : ans) {
    cout << a[0] << " " << a[1] << " " << a[2] << " " << a[3] << endl;
  }
}

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<int>> a(H + 1, vector<int>(W + 1)), ans;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j < W; j++) {
      if (a[i][j] & 1) {
        ans.push_back({i, j, i, j + 1});
        a[i][j]--;
        a[i][j + 1]++;
      }
    }
  }
  for (int i = 1; i < H; i++) {
    if (a[i][W] & 1) {
      ans.push_back({i, W, i + 1, W});
      a[i][W]--;
      a[i + 1][W]++;
    }
  }
  cout << ans.size() << endl;
  for (auto a : ans) {
    cout << a[0] << " " << a[1] << " " << a[2] << " " << a[3] << endl;
  }
}
Problem p03263 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int h, w, bor[510][510], cnt = 0, v[26000][4];
  cin >> h >> w;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++)
      cin >> bor[i][j];
  }
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (bor[i][j] % 2 == 1) {
        if (j != w) {
          cnt++;
          v[cnt][0] = i;
          v[cnt][1] = j;
          v[cnt][2] = i;
          v[cnt][3] = j + 1;
          // cout<<i<<' '<<j<<' '<<i<<' '<<j+1<<'\n';
          bor[i][j]--;
          bor[i][j + 1]++;
        } else if (i != h) {
          cnt++;
          v[cnt][0] = i;
          v[cnt][1] = j;
          v[cnt][2] = i + 1;
          v[cnt][3] = j;
          // cout<<i<<' '<<j<<' '<<i+1<<' '<<j<<'\n';
          bor[i][j]--;
          bor[i + 1][j]++;
        }
      }
    }
  }
  cout << cnt << '\n';
  for (int i = 1; i <= cnt; i++) {
    cout << v[i][0] << ' ' << v[i][1] << ' ' << v[i][2] << ' ' << v[i][3]
         << '\n';
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int h, w, bor[510][510], cnt = 0, v[260000][4];
  cin >> h >> w;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++)
      cin >> bor[i][j];
  }
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (bor[i][j] % 2 == 1) {
        if (j != w) {
          cnt++;
          v[cnt][0] = i;
          v[cnt][1] = j;
          v[cnt][2] = i;
          v[cnt][3] = j + 1;
          // cout<<i<<' '<<j<<' '<<i<<' '<<j+1<<'\n';
          bor[i][j]--;
          bor[i][j + 1]++;
        } else if (i != h) {
          cnt++;
          v[cnt][0] = i;
          v[cnt][1] = j;
          v[cnt][2] = i + 1;
          v[cnt][3] = j;
          // cout<<i<<' '<<j<<' '<<i+1<<' '<<j<<'\n';
          bor[i][j]--;
          bor[i + 1][j]++;
        }
      }
    }
  }
  cout << cnt << '\n';
  for (int i = 1; i <= cnt; i++) {
    cout << v[i][0] << ' ' << v[i][1] << ' ' << v[i][2] << ' ' << v[i][3]
         << '\n';
  }
  return 0;
}
Problem p03263 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;

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

  int count = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      a[i][j] %= 2;
      if (a[i][j] == 0)
        continue;
      if (i == h - 1 && j == w - 1)
        break;
      if (i == h - 1) {
        a[i][j + 1]++;
        count++;
      } else if (a[i][j + 1] % 2 == 0 || i == h - 1) {
        a[i + 1][j]++;
        count++;
      } else {
        a[i][j + 1]++;
        count++;
      }
    }
  }

  cout << count << endl;

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      b[i][j] %= 2;
      if (b[i][j] == 0)
        continue;
      if (i == h - 1 && j == w - 1)
        break;
      if (i == h - 1) {
        b[i][j + 1]++;
        count++;
        cout << i + 1 << " " << j + 1 << " " << i + 1 << " " << j + 2 << endl;
      } else if (b[i][j + 1] % 2 == 0 || i == h - 1) {
        b[i + 1][j]++;
        count++;
        cout << i + 1 << " " << j + 1 << " " << i + 2 << " " << j + 1 << endl;
      } else {
        b[i][j + 1]++;
        count++;
        cout << i + 1 << " " << j + 1 << " " << i + 1 << " " << j + 2 << endl;
      }
    }
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;

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

  int count = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      a[i][j] %= 2;
      if (a[i][j] == 0)
        continue;
      if (i == h - 1 && j == w - 1)
        break;
      if (i == h - 1) {
        a[i][j + 1]++;
        count++;
      } else if (a[i][j + 1] % 2 == 0 || i == h - 1) {
        a[i + 1][j]++;
        count++;
      } else {
        a[i][j + 1]++;
        count++;
      }
    }
  }

  cout << count << endl;

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      b[i][j] %= 2;
      if (b[i][j] == 0)
        continue;
      if (i == h - 1 && j == w - 1)
        break;
      if (i == h - 1) {
        b[i][j + 1]++;
        count++;
        cout << i + 1 << " " << j + 1 << " " << i + 1 << " " << j + 2 << endl;
      } else if (b[i][j + 1] % 2 == 0 || i == h - 1) {
        b[i + 1][j]++;
        count++;
        cout << i + 1 << " " << j + 1 << " " << i + 2 << " " << j + 1 << endl;
      } else {
        b[i][j + 1]++;
        count++;
        cout << i + 1 << " " << j + 1 << " " << i + 1 << " " << j + 2 << endl;
      }
    }
  }
}
Problem p03263 (C++)

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

using namespace std;

int main() {
  int a[505][505];
  int H, W;

  vector<string> ans;

  cin >> H >> W;

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> a[i][j];
    }
  }
  int x = 0, y = 0;
  int dx = 1;

  while (true) {
    int nx, ny;
    if (x + dx < 0 || W <= x + dx) {
      ny = y + 1;
      dx *= -1;
    } else {
      nx = x + dx;
      ny = y;
    }

    if (H <= ny) {
      break;
    }
    if (a[y][x] % 2 == 1) {
      a[y][x]--;
      a[ny][nx]++;
      ans.push_back(to_string(y + 1) + " " + to_string(x + 1) + " " +
                    to_string(ny + 1) + " " + to_string(nx + 1));
    }
    x = nx;
    y = ny;
  }

  cout << ans.size() << endl;

  for (auto i : ans) {
    cout << i << endl;
  }

  return 0;
}


Fixed submission:
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int a[505][505];
  int H, W;

  vector<string> ans;

  cin >> H >> W;

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> a[i][j];
    }
  }
  int x = 0, y = 0;
  int dx = 1;

  while (true) {
    int nx, ny;
    if (x + dx < 0 || W <= x + dx) {
      nx = x;
      ny = y + 1;
      dx *= -1;
    } else {
      nx = x + dx;
      ny = y;
    }

    if (H <= ny) {
      break;
    }
    if (a[y][x] % 2 == 1) {
      a[y][x]--;
      a[ny][nx]++;
      ans.push_back(to_string(y + 1) + " " + to_string(x + 1) + " " +
                    to_string(ny + 1) + " " + to_string(nx + 1));
    }
    x = nx;
    y = ny;
  }

  cout << ans.size() << endl;

  for (auto i : ans) {
    cout << i << endl;
  }

  return 0;
}
Problem p03263 (Python)

Buggy submission (status: Runtime Error):
from functools import partial
from itertools import islice


def take(n, iterable):
    return list(islice(iterable, n))


def chunked(iterable, n):
    return iter(partial(take, n, iter(iterable)), [])


def solve(s):
    h, w, *a = map(int, s.split())
    (*a,) = chunked(a, w)
    ans = []
    for i in range(h):
        for j in range(w - 1):
            if a[i][j] % 2 == 1:
                ans.append("{} {} {} {}".format(i + 1, j + 1, i + 1, j + 2))
                a[i][j + 1] += 1
    for i in range(h - 1):
        if a[i][w - 1] % 2 == 1:
            ans.append("{} {} {} {}".format(i + 1, w, i + 2, w))
            a[i + 1][w - 1] += 1
    ans += "{}\n".format(len(ans)) + ans
    return "\n".join(ans)


n, m = map(int, input().split())
print(solve("{} {}\n".format(n, m) + "\n".join([input() for _ in range(n)])))


Fixed submission:
from functools import partial
from itertools import islice


def take(n, iterable):
    return list(islice(iterable, n))


def chunked(iterable, n):
    return iter(partial(take, n, iter(iterable)), [])


def solve(s):
    h, w, *a = map(int, s.split())
    (*a,) = chunked(a, w)
    ans = []
    for i in range(h):
        for j in range(w - 1):
            if a[i][j] % 2 == 1:
                ans.append("{} {} {} {}".format(i + 1, j + 1, i + 1, j + 2))
                a[i][j + 1] += 1
    for i in range(h - 1):
        if a[i][w - 1] % 2 == 1:
            ans.append("{} {} {} {}".format(i + 1, w, i + 2, w))
            a[i + 1][w - 1] += 1
    return "{}\n".format(len(ans)) + "\n".join(ans)


n, m = map(int, input().split())
print(solve("{} {}\n".format(n, m) + "\n".join([input() for _ in range(n)])))
Problem p03263 (C++)

Buggy submission (status: Runtime Error):
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int A[510][510];
int B[25100][4];

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

  int x;
  rep(i, h) {
    rep(j, w) {
      cin >> x;
      A[i + 1][j + 1] = x % 2;
    }
  }

  int k = 0;
  bool b = false;
  int tmph, tmpw;
  for (int i = 1; i <= h; i++) {
    if (i % 2 == 1) {
      for (int j = 1; j <= w; j++) {
        if (b == false && A[i][j] % 2 == 1) {
          tmph = i, tmpw = j;
          b = true;
        } else if (b == true) {
          B[k][0] = tmph, B[k][1] = tmpw, B[k][2] = i, B[k][3] = j;
          k++;
          if (A[i][j] % 2 == 1)
            b = false;
          else
            tmph = i, tmpw = j;
        }
      }
    } else {
      for (int j = w; j >= 1; j--) {
        if (b == false && A[i][j] % 2 == 1) {
          tmph = i, tmpw = j;
          b = true;
        } else if (b == true) {
          B[k][0] = tmph, B[k][1] = tmpw, B[k][2] = i, B[k][3] = j;
          k++;
          if (A[i][j] % 2 == 1)
            b = false;
          else
            tmph = i, tmpw = j;
        }
      }
    }
  }

  cout << k << endl;
  rep(i, k) cout << B[i][0] << " " << B[i][1] << " " << B[i][2] << " "
                 << B[i][3] << endl;

  return 0;
}

Fixed submission:
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int A[510][510];
int B[251000][4];

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

  int x;
  rep(i, h) {
    rep(j, w) {
      cin >> x;
      A[i + 1][j + 1] = x % 2;
    }
  }

  int k = 0;
  bool b = false;
  int tmph, tmpw;
  for (int i = 1; i <= h; i++) {
    if (i % 2 == 1) {
      for (int j = 1; j <= w; j++) {
        if (b == false && A[i][j] % 2 == 1) {
          tmph = i, tmpw = j;
          b = true;
        } else if (b == true) {
          B[k][0] = tmph, B[k][1] = tmpw, B[k][2] = i, B[k][3] = j;
          k++;
          if (A[i][j] % 2 == 1)
            b = false;
          else
            tmph = i, tmpw = j;
        }
      }
    } else {
      for (int j = w; j >= 1; j--) {
        if (b == false && A[i][j] % 2 == 1) {
          tmph = i, tmpw = j;
          b = true;
        } else if (b == true) {
          B[k][0] = tmph, B[k][1] = tmpw, B[k][2] = i, B[k][3] = j;
          k++;
          if (A[i][j] % 2 == 1)
            b = false;
          else
            tmph = i, tmpw = j;
        }
      }
    }
  }

  cout << k << endl;
  rep(i, k) cout << B[i][0] << " " << B[i][1] << " " << B[i][2] << " "
                 << B[i][3] << endl;

  return 0;
}
Problem p03263 (C++)

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

int Matriz[505][505];
int Resultados[505][4];

int main() {
  int H, W;
  int aux;
  scanf("%d %d", &H, &W);
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      scanf("%d", &aux);
      Matriz[i][j] = aux;
    }
  }
  int contador = 0;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      aux = Matriz[i][j];
      if (aux % 2 == 1) {
        if (j < W - 1) {
          Matriz[i][j + 1]++;
          Resultados[contador][0] = i + 1;
          Resultados[contador][1] = j + 1;
          Resultados[contador][2] = i + 1;
          Resultados[contador][3] = j + 2;
          contador++;
        } else {
          if (i < H - 1) {
            Matriz[i + 1][j]++;
            Resultados[contador][0] = i + 1;
            Resultados[contador][1] = j + 1;
            Resultados[contador][2] = i + 2;
            Resultados[contador][3] = j + 1;
            contador++;
          }
        }
      }
    }
  }
  cout << contador << endl;
  for (int i = 0; i < contador; ++i) {
    cout << Resultados[i][0] << " " << Resultados[i][1] << " "
         << Resultados[i][2] << " " << Resultados[i][3] << endl;
  }
  return 0;
}

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

int Matriz[505][505];
int Resultados[250005][4];

int main() {
  int H, W;
  int aux;
  scanf("%d %d", &H, &W);
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      scanf("%d", &aux);
      Matriz[i][j] = aux;
    }
  }
  int contador = 0;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      aux = Matriz[i][j];
      if (aux % 2 == 1) {
        if (j < W - 1) {
          Matriz[i][j + 1]++;
          Resultados[contador][0] = i + 1;
          Resultados[contador][1] = j + 1;
          Resultados[contador][2] = i + 1;
          Resultados[contador][3] = j + 2;
          contador++;
        } else {
          if (i < H - 1) {
            Matriz[i + 1][j]++;
            Resultados[contador][0] = i + 1;
            Resultados[contador][1] = j + 1;
            Resultados[contador][2] = i + 2;
            Resultados[contador][3] = j + 1;
            contador++;
          }
        }
      }
    }
  }
  cout << contador << endl;
  for (int i = 0; i < contador; ++i) {
    cout << Resultados[i][0] << " " << Resultados[i][1] << " "
         << Resultados[i][2] << " " << Resultados[i][3] << endl;
  }
  return 0;
}
Problem p03263 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int MOD = 1e9 + 7;

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int H, W;
  cin >> H >> W;
  int A[H][W];
  rep(i, H) {
    rep(j, W) { cin >> A[i][j]; }
  }
  int ans = 0, M = 0;
  pair<int, int> P[100000];
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W - 1; j++) {
      if (A[i][j] % 2 == 1) {
        P[M].first = i + 1, P[M].second = j + 1;
        M++;
        P[M].first = i + 1, P[M].second = j + 2;
        M++;
        A[i][j + 1] += A[i][j];
        ans++;
      }
    }
  }
  for (int i = 0; i < H - 1; i++) {
    if (A[i][W - 1] % 2 == 1) {
      ans++;
      P[M].first = i + 1, P[M].second = W;
      M++;
      P[M].first = i + 2, P[M].second = W;
      M++;
      A[i + 1][W - 1] += A[i][W - 1];
    }
  }

  cout << ans << endl;
  for (int i = 0; i < ans; i++) {
    cout << P[i * 2].first << ' ' << P[i * 2].second << ' ';
    cout << P[i * 2 + 1].first << ' ' << P[i * 2 + 1].second << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int MOD = 1e9 + 7;

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int H, W;
  cin >> H >> W;
  int A[H][W];
  rep(i, H) {
    rep(j, W) { cin >> A[i][j]; }
  }
  int ans = 0, M = 0;
  pair<int, int> P[300000];
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W - 1; j++) {
      if (A[i][j] % 2 == 1) {
        P[M].first = i + 1, P[M].second = j + 1;
        M++;
        P[M].first = i + 1, P[M].second = j + 2;
        M++;
        A[i][j + 1] += A[i][j];
        ans++;
      }
    }
  }
  for (int i = 0; i < H - 1; i++) {
    if (A[i][W - 1] % 2 == 1) {
      ans++;
      P[M].first = i + 1, P[M].second = W;
      M++;
      P[M].first = i + 2, P[M].second = W;
      M++;
      A[i + 1][W - 1] += A[i][W - 1];
    }
  }

  cout << ans << endl;
  for (int i = 0; i < ans; i++) {
    cout << P[i * 2].first << ' ' << P[i * 2].second << ' ';
    cout << P[i * 2 + 1].first << ' ' << P[i * 2 + 1].second << endl;
  }
}
Problem p03263 (C++)

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define a first
#define b second
#define mp make_pair
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep1(i, n) for (ll i = 1; i <= n; i++)
ll H, W;
P change(ll x) {
  P p;
  if (((x + W - 1) / W) % 2 == 1)
    p = mp((x + W - 1) / W, x % (2 * W));
  else
    p = mp((x + W - 1) / W, 2 * W + 1 - x % (2 * W));
  return p;
}

int main() {
  cin >> H >> W;
  ll X[501][501];
  ll cX[501][501];
  rep1(i, H) rep1(j, W) {
    cin >> X[i][j];
    cX[i][j] = X[i][j];
  }

  ll cnt = 0;
  rep1(i, H * W - 1) {
    if (cX[change(i).a][change(i).b] % 2 == 1) {
      cX[change(i).a][change(i).b]--;
      cX[change(i + 1).a][change(i + 1).b]++;
      cnt++;
    }
  }
  cout << cnt << endl;
  rep1(i, H * W - 1) {
    if (X[change(i).a][change(i).b] % 2 == 1) {
      X[change(i).a][change(i).b]--;
      X[change(i + 1).a][change(i + 1).b]++;
      cout << change(i).a << " " << change(i).b << " " << change(i + 1).a << " "
           << change(i + 1).b << endl;
    }
  }
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define a first
#define b second
#define mp make_pair
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep1(i, n) for (ll i = 1; i <= n; i++)
ll H, W;
P change(ll x) {
  P p;
  if (((x + W - 1) / W) % 2 == 1)
    p = mp((x + W - 1) / W, x % (2 * W));
  else
    p = mp((x + W - 1) / W, (2 * W) - (x - 1) % (2 * W));
  return p;
}

int main() {
  cin >> H >> W;
  ll X[501][501];
  ll cX[501][501];
  rep1(i, H) rep1(j, W) {
    cin >> X[i][j];
    cX[i][j] = X[i][j];
  }

  ll cnt = 0;
  rep1(i, H * W - 1) {
    if (cX[change(i).a][change(i).b] % 2 == 1) {
      cX[change(i).a][change(i).b]--;
      cX[change(i + 1).a][change(i + 1).b]++;
      cnt++;
    }
  }
  cout << cnt << endl;
  rep1(i, H * W - 1) {
    if (X[change(i).a][change(i).b] % 2 == 1) {
      X[change(i).a][change(i).b]--;
      X[change(i + 1).a][change(i + 1).b]++;
      cout << change(i).a << " " << change(i).b << " " << change(i + 1).a << " "
           << change(i + 1).b << endl;
    }
  }
}
Problem p03263 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<int>> A(h, vector<int>(w));
  vector<tuple<int, int, int, int>> ans;
  rep(i, h) rep(j, w) cin >> A[i][j];
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w - 1; ++j) {
      if (A[i][j] % 2 == 1) {
        A[i][j]--;
        A[i][j + 1]++;
        ans.push_back(make_tuple(i, j, i, j + 1));
      }
    }
  }
  for (int i = 0; i < h; i++) {
    if (A[i][w - 1] % 2 == 1) {
      A[i][w - 1]--;
      A[i + 1][w - 1]++;
      ans.push_back(make_tuple(i, w - 1, i + 1, w - 1));
    }
  }
  cout << ans.size() << endl;
  for (auto elem : ans) {
    cout << get<0>(elem) + 1 << " " << get<1>(elem) + 1 << " "
         << get<2>(elem) + 1 << " " << get<3>(elem) + 1 << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<int>> A(h, vector<int>(w));
  vector<tuple<int, int, int, int>> ans;
  rep(i, h) rep(j, w) cin >> A[i][j];
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w - 1; ++j) {
      if (A[i][j] % 2 == 1) {
        A[i][j]--;
        A[i][j + 1]++;
        ans.push_back(make_tuple(i, j, i, j + 1));
      }
    }
  }
  for (int i = 0; i < h - 1; i++) {
    if (A[i][w - 1] % 2 == 1) {
      A[i][w - 1]--;
      A[i + 1][w - 1]++;
      ans.push_back(make_tuple(i, w - 1, i + 1, w - 1));
    }
  }
  cout << ans.size() << endl;
  for (auto elem : ans) {
    cout << get<0>(elem) + 1 << " " << get<1>(elem) + 1 << " "
         << get<2>(elem) + 1 << " " << get<3>(elem) + 1 << endl;
  }
}
Problem p03263 (C++)

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

int main() {
  int x1[maxn], x2[maxn];
  int y1[maxn], y2[maxn];
  int h, w, a[500][500], i, j, n = 0;
  scanf("%d%d", &h, &w);
  for (i = 1; i <= h; i++) {
    for (j = 1; j <= w; j++)
      scanf("%d", &a[i][j]);
  }
  for (i = 1; i <= h; i++) {
    for (j = 1; j < w; j++) {
      if (a[i][j] % 2 == 1) {
        y1[n] = i;
        y2[n] = i;
        x1[n] = j;
        x2[n] = j + 1;
        n++;
        a[i][j]--;
        a[i][j + 1]++;
      }
    }
  }
  for (i = 1; i < h; i++) {
    if (a[i][w] % 2 == 1) {
      y1[n] = i;
      y2[n] = i + 1;
      x1[n] = w;
      x2[n] = w;
      n++;
      a[i][w]--;
      a[i + 1][w]++;
    }
  }
  printf("%d\n", n);
  for (i = 0; i < n; i++)
    printf("%d %d %d %d\n", y1[i], x1[i], y2[i], x2[i]);
  return 0;
}


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

int main() {
  int x1[maxn], x2[maxn];
  int y1[maxn], y2[maxn];
  int h, w, a[550][550], i, j, n = 0;
  scanf("%d%d", &h, &w);
  for (i = 1; i <= h; i++) {
    for (j = 1; j <= w; j++)
      scanf("%d", &a[i][j]);
  }
  for (i = 1; i <= h; i++) {
    for (j = 1; j < w; j++) {
      if (a[i][j] % 2 == 1) {
        y1[n] = i;
        y2[n] = i;
        x1[n] = j;
        x2[n] = j + 1;
        n++;
        a[i][j]--;
        a[i][j + 1]++;
      }
    }
  }
  for (i = 1; i < h; i++) {
    if (a[i][w] % 2 == 1) {
      y1[n] = i;
      y2[n] = i + 1;
      x1[n] = w;
      x2[n] = w;
      n++;
      a[i][w]--;
      a[i + 1][w]++;
    }
  }
  printf("%d\n", n);
  for (i = 0; i < n; i++)
    printf("%d %d %d %d\n", y1[i], x1[i], y2[i], x2[i]);
  return 0;
}
Problem p03263 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define dum(x) cout << #x << '=' << x << endl
#define ll long long
using namespace std;

bool check(int x) {
  if (x % 2 == 0) {
    return true;
  } else {
    return false;
  }
}

int main() {
  int h, w;
  cin >> h >> w;
  int v[h][w];

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> v[i][j];
    }
  }

  int rescnt = 0;
  vector<pair<int, int>> vpin(25000);
  vector<pair<int, int>> vpout(25000);

  // 縦判定
  for (int i = 0; i < h - 1; ++i) {
    for (int j = 0; j < w; ++j) {
      if (check(v[i][j])) {
        continue;
      } else {
        vpin[rescnt] = make_pair(i + 1, j + 1);
        vpout[rescnt] = make_pair(i + 2, j + 1);
        rescnt++;
        v[i][j]--;
        v[i + 1][j]++;
      }
    }
  }

  // 横判定
  for (int j = 0; j < w - 1; ++j) {
    if (check(v[h - 1][j])) {
      continue;
    } else {
      vpin[rescnt] = make_pair(h, j + 1);
      vpout[rescnt] = make_pair(h, j + 2);
      rescnt++;
      v[h - 1][j]--;
      v[h - 1][j + 1]++;
    }
  }
  cout << rescnt << endl;
  for (int i = 0; i < rescnt; ++i) {
    cout << vpin[i].first << " " << vpin[i].second << " " << vpout[i].first
         << " " << vpout[i].second << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
#define dum(x) cout << #x << '=' << x << endl
#define ll long long
using namespace std;

bool check(int x) {
  if (x % 2 == 0) {
    return true;
  } else {
    return false;
  }
}

int main() {
  int h, w;
  cin >> h >> w;
  int v[h][w];

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> v[i][j];
    }
  }

  int rescnt = 0;
  vector<pair<int, int>> vpin(250000);
  vector<pair<int, int>> vpout(250000);

  // 縦判定
  for (int i = 0; i < h - 1; ++i) {
    for (int j = 0; j < w; ++j) {
      if (check(v[i][j])) {
        continue;
      } else {
        vpin[rescnt] = make_pair(i + 1, j + 1);
        vpout[rescnt] = make_pair(i + 2, j + 1);
        rescnt++;
        v[i][j]--;
        v[i + 1][j]++;
      }
    }
  }

  // 横判定
  for (int j = 0; j < w - 1; ++j) {
    if (check(v[h - 1][j])) {
      continue;
    } else {
      vpin[rescnt] = make_pair(h, j + 1);
      vpout[rescnt] = make_pair(h, j + 2);
      rescnt++;
      v[h - 1][j]--;
      v[h - 1][j + 1]++;
    }
  }
  cout << rescnt << endl;
  for (int i = 0; i < rescnt; ++i) {
    cout << vpin[i].first << " " << vpin[i].second << " " << vpout[i].first
         << " " << vpout[i].second << endl;
  }
}
Problem p03263 (C++)

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
int MOD = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int h, w;
  cin >> h >> w;
  int area[h][w];
  rep(i, h) {
    rep(j, w) { cin >> area[i][j]; }
  }

  vector<vi> result(2500, vector<int>(5, 0));

  int count = 0;

  rep(i, h) {
    rep(j, w) {
      if (area[i][j] % 2 == 1) {
        if (j != w - 1) {
          area[i][j]--;
          area[i][j + 1]++;
          result[count][0] = i;
          result[count][1] = j;
          result[count][2] = i;
          result[count][3] = j + 1;
          count++;
        } else if (i != h - 1) {
          area[i][j]--;
          area[i + 1][j]++;
          result[count][0] = i;
          result[count][1] = j;
          result[count][2] = i + 1;
          result[count][3] = j;
          count++;
        }
      }
    }
  }

  cout << count << endl;
  rep(i, count) {
    cout << result[i][0] + 1 << " " << result[i][1] + 1 << " "
         << result[i][2] + 1 << " " << result[i][3] + 1 << endl;
  }

  return 0;
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
int MOD = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int h, w;
  cin >> h >> w;
  int area[h][w];
  rep(i, h) {
    rep(j, w) { cin >> area[i][j]; }
  }

  vector<vi> result(250010, vector<int>(5, 0));

  int count = 0;

  rep(i, h) {
    rep(j, w) {
      if (area[i][j] % 2 == 1) {
        if (j != w - 1) {
          area[i][j]--;
          area[i][j + 1]++;
          result[count][0] = i;
          result[count][1] = j;
          result[count][2] = i;
          result[count][3] = j + 1;
          count++;
        } else if (i != h - 1) {
          area[i][j]--;
          area[i + 1][j]++;
          result[count][0] = i;
          result[count][1] = j;
          result[count][2] = i + 1;
          result[count][3] = j;
          count++;
        }
      }
    }
  }

  cout << count << endl;
  rep(i, count) {
    cout << result[i][0] + 1 << " " << result[i][1] + 1 << " "
         << result[i][2] + 1 << " " << result[i][3] + 1 << endl;
  }

  return 0;
}
Problem p03264 (C++)

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

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define D(x) cerr << __LINE__ << ": " << #x << " = " << (x) << '\n'
#define DD(x, y)                                                               \
  cerr << __LINE__ << ": " << #x << " = " << x << "   " << #y << " = " << y    \
       << '\n'
#define DDD(x, y, z)                                                           \
  cerr << __LINE__ << ": " << #x << " = " << x << "   " << #y << " = " << y    \
       << "   " << #z << " = " << z << '\n'
#define DBG cerr << __LINE__ << ": Hi" << '\n'
#define fresh                                                                  \
  {                                                                            \
    ios_base::sync_with_stdio(false);                                          \
    cin.tie(NULL);                                                             \
    cout.tie(NULL);                                                            \
  }
#define read freopen("in.txt", "rt", stdin)
#define write freopen("out.txt", "wt", stdout)
#define PI 3.1415926535897932384626433832795
#define mems(ds_name, val) memset(ds_name, val, sizeof(ds_name))

int main() {
  fresh;
  read;
  //	write;

  int t;
  cin >> t;
  int divs = t / 2;
  int mods = t % 2;
  if (!mods) {
    cout << divs * divs << endl;
  } else {
    cout << divs * (divs + 1) << endl;
  }
}


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

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define D(x) cerr << __LINE__ << ": " << #x << " = " << (x) << '\n'
#define DD(x, y)                                                               \
  cerr << __LINE__ << ": " << #x << " = " << x << "   " << #y << " = " << y    \
       << '\n'
#define DDD(x, y, z)                                                           \
  cerr << __LINE__ << ": " << #x << " = " << x << "   " << #y << " = " << y    \
       << "   " << #z << " = " << z << '\n'
#define DBG cerr << __LINE__ << ": Hi" << '\n'
#define fresh                                                                  \
  {                                                                            \
    ios_base::sync_with_stdio(false);                                          \
    cin.tie(NULL);                                                             \
    cout.tie(NULL);                                                            \
  }
#define read freopen("in.txt", "rt", stdin)
#define write freopen("out.txt", "wt", stdout)
#define PI 3.1415926535897932384626433832795
#define mems(ds_name, val) memset(ds_name, val, sizeof(ds_name))

int main() {
  fresh;
#ifndef ONLINE_JUDGE
//    read;
#endif
  //	write;

  int t;
  cin >> t;
  int divs = t / 2;
  int mods = t % 2;
  if (!mods) {
    cout << divs * divs << endl;
  } else {
    cout << divs * (divs + 1) << endl;
  }
}
Problem p03264 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
int main() {
  int k;
  scanf("%d", k);
  if (k % 2 == 0) {
    printf("%d", k / 2 * k / 2);
  }
  if (k % 2 == 1) {
    printf("%d", k / 2 * (k + 1) / 2);
  }
  return 0;
}


Fixed submission:
#include <stdio.h>
int main() {
  int k;
  scanf("%d", &k);
  if (k % 2 == 0) {
    printf("%d", k / 2 * k / 2);
  }
  if (k % 2 == 1) {
    printf("%d", k / 2 * (k + 1) / 2);
  }
  return 0;
}
Problem p03264 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

int main() {
  int k;
  cin >> k;

  int even = k / 2;
  int odd = k / 2 + k % 2;

  cout << even * odd << endl;
  while (1)
    ;
  return 0;
}

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

int main() {
  int k;
  cin >> k;

  int even = k / 2;
  int odd = k / 2 + k % 2;

  cout << even * odd << endl;
  return 0;
}
Problem p03264 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>

using namespace std;

int main() {
  int N;
  cin >> N;
  int count = 0;
  for (int i = 1; i <= N; i++) {
    for (int j = i; j <= N; i++) {
      if (i == j)
        continue;
      if (i % 2 == 0 && j % 2 == 1)
        count++;
      else if (j % 2 == 0 && i % 2 == 1)
        count++;
    }
  }
  cout << count;
}


Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int N;
  cin >> N;
  int count = 0;
  for (int i = 1; i <= N; i++) {
    for (int j = i; j <= N; j++) {
      if (i == j)
        continue;
      if (i % 2 == 0 && j % 2 == 1)
        count++;
      else if (j % 2 == 0 && i % 2 == 1)
        count++;
    }
  }
  cout << count;
}