alexjercan/bugnet huggingface dataset:
Problem p01104 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using Int = int64_t;
const Int inf = 1LL << 53;

int main() {
  for (;;) {
    Int n, m;
    std::cin >> n >> m;
    if (n == 0 && m == 0) {
      break;
    }
    auto xss = std::vector<std::string>(n);
    for (Int i = 0; i < n; ++i) {
      std::string ss;
      std::cin >> ss;
      xss[i] = ss;
    }
    if (n <= 20) {
      Int res = 0;
      for (Int i = 0; i < (1 << n); ++i) {
        std::string ss(m, '0');
        Int num = 0;
        for (Int k = 0; k < n; ++k) {
          if ((i & (1 << k)) != 0) {
            num += 1;
            for (Int j = 0; j < m; ++j) {
              ss[j] = ss[j] == xss[k][j] ? '0' : '1';
            }
          }
        }
        bool valid = true;
        for (Int j = 0; j < m; ++j) {
          if (ss[j] != '0') {
            valid = false;
          }
        }
        if (valid) {
          res = std::max(res, num);
        }
      }
      std::cout << res << std::endl;
    } else {
      auto ys = std::vector<Int>(n);
      for (Int i = 0; i < n; ++i) {
        Int t = 0;
        for (Int k = 0; k < m; ++k) {
          if (xss[i][k] == '1') {
            t |= 1 << k;
          }
        }
        ys[i] = t;
      }
      std::vector<Int> dp(1 << m, -inf);
      std::vector<Int> dp2(1 << m, -inf);
      dp[0] = 0;
      for (Int i = 0; i < n; ++i) {
        for (Int k = 0; k < 1 << m; ++k) {
          dp2[k] = std::max(dp[k], dp[k ^ ys[i]] + 1);
        }
        std::swap(dp, dp2);
      }
      std::cout << dp[0] << std::endl;
    }
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using Int = int64_t;
const Int inf = 1LL << 53;

int main() {
  for (;;) {
    Int n, m;
    std::cin >> n >> m;
    if (n == 0 && m == 0) {
      break;
    }
    auto xss = std::vector<std::string>(n);
    for (Int i = 0; i < n; ++i) {
      std::string ss;
      std::cin >> ss;
      xss[i] = ss;
    }
    if (n <= 23) {
      Int res = 0;
      for (Int i = 0; i < (1 << n); ++i) {
        std::string ss(m, '0');
        Int num = 0;
        for (Int k = 0; k < n; ++k) {
          if ((i & (1 << k)) != 0) {
            num += 1;
            for (Int j = 0; j < m; ++j) {
              ss[j] = ss[j] == xss[k][j] ? '0' : '1';
            }
          }
        }
        bool valid = true;
        for (Int j = 0; j < m; ++j) {
          if (ss[j] != '0') {
            valid = false;
          }
        }
        if (valid) {
          res = std::max(res, num);
        }
      }
      std::cout << res << std::endl;
    } else {
      auto ys = std::vector<Int>(n);
      for (Int i = 0; i < n; ++i) {
        Int t = 0;
        for (Int k = 0; k < m; ++k) {
          if (xss[i][k] == '1') {
            t |= 1 << k;
          }
        }
        ys[i] = t;
      }
      std::vector<Int> dp(1 << m, -inf);
      std::vector<Int> dp2(1 << m, -inf);
      dp[0] = 0;
      for (Int i = 0; i < n; ++i) {
        for (Int k = 0; k < 1 << m; ++k) {
          dp2[k] = std::max(dp[k], dp[k ^ ys[i]] + 1);
        }
        std::swap(dp, dp2);
      }
      std::cout << dp[0] << std::endl;
    }
  }
}
Problem p01104 (C++) — buggy submission, verdict: Time Limit Exceeded

#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 pb emplace_back
typedef long long ll;
typedef pair<int, int> pint;

int dp[2][1 << 21];
int bit[501], bit2[25][501], cnt[501];
int main() {
  int n, m;
  string s;
  while (cin >> n >> m, n) {
    if (m <= 20) {
      memset(bit, 0, sizeof(bit));
      rep(i, n) {
        cin >> s;
        rep(j, m) if (s[j] == '1') bit[i] |= 1 << j;
      }
      memset(dp, -1, sizeof(dp));
      dp[0][0] = 0;
      rep(i, n) {
        rep(j, 1 << m) dp[1][j] = dp[0][j];
        rep(j, 1 << m) if (dp[0][j] != -1) {
          dp[1][j ^ bit[i]] = max(dp[1][j ^ bit[i]], dp[0][j] + 1);
        }
        swap(dp[0], dp[1]);
      }
      cout << dp[0][0] << endl;
    } else {
      memset(bit2, 0, sizeof(bit2));
      rep(i, n) {
        cin >> s;
        rep(j, m) if (s[j] == '1') bit2[i][j] = 1;
      }
      int mx = 0;
      rep(i, 1 << n) {
        int c = __builtin_popcount(i);
        if (mx >= c)
          continue;
        memset(cnt, 0, sizeof(cnt));
        rep(j, n) if ((i >> j) & 1) rep(k, m) cnt[k] ^= bit2[j][k];
        int sum = 0;
        rep(j, m) sum += cnt[j];
        if (sum == 0)
          mx = max(mx, c);
      }
      cout << mx << endl;
    }
  }
  return 0;
}


Error: TLE

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 pb emplace_back
typedef long long ll;
typedef pair<int, int> pint;

int dp[2][1 << 22];
int bit[501], bit2[25][501], cnt[501];
int main() {
  int n, m;
  string s;
  while (cin >> n >> m, n) {
    if (m <= 21) {
      memset(bit, 0, sizeof(bit));
      rep(i, n) {
        cin >> s;
        rep(j, m) if (s[j] == '1') bit[i] |= 1 << j;
      }
      memset(dp, -1, sizeof(dp));
      dp[0][0] = 0;
      rep(i, n) {
        rep(j, 1 << m) dp[1][j] = dp[0][j];
        rep(j, 1 << m) if (dp[0][j] != -1) {
          dp[1][j ^ bit[i]] = max(dp[1][j ^ bit[i]], dp[0][j] + 1);
        }
        swap(dp[0], dp[1]);
      }
      cout << dp[0][0] << endl;
    } else {
      memset(bit2, 0, sizeof(bit2));
      rep(i, n) {
        cin >> s;
        rep(j, m) if (s[j] == '1') bit2[i][j] = 1;
      }
      int mx = 0;
      for (int i = (1 << n) - 1; i >= 0; --i) {
        int c = __builtin_popcount(i);
        if (mx >= c)
          continue;
        memset(cnt, 0, sizeof(cnt));
        rep(j, n) if ((i >> j) & 1) rep(k, m) cnt[k] ^= bit2[j][k];
        int sum = 0;
        rep(j, m) sum += cnt[j];
        if (sum == 0)
          mx = max(mx, c);
      }
      cout << mx << endl;
    }
  }
  return 0;
}
Problem p01109 (C++) — buggy submission, verdict: Runtime Error

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

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

  while (true) {
    int n, ans = 0, mean = 0;
    cin >> n;
    if (n == 0) {
      break;
    }
    int a[n];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      mean += a[i];
    }
    mean /= n;
    for (int i = 0; i < n; i++) {
      if (a[i] <= mean) {
        ans++;
      }
    }
    cout << ans << endl;
  }
}


Error: TLE

Fixed submission:

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, a[n], ans, mean;

  while (true) {
    ans = 0;
    mean = 0;
    cin >> n;
    if (n == 0) {
      break;
    }
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      mean += a[i];
    }
    mean /= n;
    for (int i = 0; i < n; i++) {
      if (a[i] <= mean) {
        ans++;
      }
    }
    cout << ans << endl;
  }
}
Problem p01109 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;

#define maxn 10010
int n, sum, eve, cnt;
int num[maxn];

int main() {
  while (cin >> n && n) {
    sum = 0;
    eve = 0;
    cnt = 0;
    for (int i = 0; i < n; i++) {
      cin >> num[i];
      sum += num[i];
    }
    eve = sum / n;
    for (int i = 0; i < n; i++) {
      if (num[i] <= eve)
        cnt++;
    }
    cout << cnt << '\\n';
  }
  getchar();
  getchar();
  return 0;
}


Error: 0

Fixed submission:

// #include<bits/stdc++.h>
#include <iostream>
#include <stdio.h>
#define pi 3.141592653897932384626
#define abs(x) ((x) > 0 ? (x) : (-(x)))
#define eps (double)(0.0000001)
#define fs first
#define se second
// freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
using namespace std;
long a[1000];
int main() {
  long n;
  cin >> n;
  while (n) {
    long s = 0, x = 0;
    for (long i = 0; i < n; ++i) {
      scanf("%ld", &a[i]);
      s += a[i];
    }
    s /= n;
    for (long i = 0; i < n; ++i) {
      if (a[i] <= s)
        ++x;
    }
    cout << x << endl;
    cin >> n;
  }
  return 0;
}
Problem p01110 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>
#define ll long long
#define N 100000

using namespace std;

int g[600][600], dx, dy;

int main(void) {
#ifdef _DEBUG
  freopen("1.in", "r", stdin);
#else
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#endif
  int n, m, t, p;
  while (cin >> n >> m >> t >> p, n) {
    dx = dy = 0;
    memset(g, 0, sizeof(g));
    for (int i = 0; i != n; ++i)
      for (int j = 0; j != m; ++j)
        g[i][j] = 1;
    while (t--) {
      int d, c;
      cin >> d >> c;
      if (d == 1) {
        for (int i = 0; i != c; ++i)
          for (int j = 0; j != m - dy; ++j)
            g[dx + c + i][dy + j] += g[dx + c - i - 1][dy + j];
        dx += c;
        if (n < dx + 2 * c)
          n = dx + 2 * c;
      } else if (d == 2) {
        for (int j = 0; j != c; ++j)
          for (int i = 0; i != n - dx; ++i)
            g[dx + i][dy + c + j] += g[dx + i][dy + c - j - 1];
        dy += c;
        if (m < dy + 2 * c)
          m = dy + 2 * c;
      }
    }
    while (p--) {
      int x, y;
      cin >> x >> y;
      cout << g[dx + x][dy + y] << endl;
    }
  }
  return 0;
}


Error: 0

Fixed submission:

#include <cstring>
#include <iostream>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#define ll long long
#define N 100000

using namespace std;

int g[64][64], dx, dy;

int main(void) {
#ifdef _DEBUG
  freopen("1.in", "r", stdin);
#else
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#endif
  int n, m, t, p;
  while (cin >> n >> m >> t >> p, n) {
    dx = dy = 0;
    memset(g, 0, sizeof(g));
    for (int i = 0; i != n; ++i)
      for (int j = 0; j != m; ++j)
        g[i][j] = 1;
    while (t--) {
      int d, c;
      cin >> d >> c;
      if (d == 1) {
        for (int i = 0; i != c; ++i)
          for (int j = 0; j != m - dy; ++j)
            g[dx + c + i][dy + j] += g[dx + c - i - 1][dy + j];
        dx += c;
        if (n < dx + 2 * c)
          n = dx + 2 * c;
      } else if (d == 2) {
        for (int j = 0; j != c; ++j)
          for (int i = 0; i != n - dx; ++i)
            g[dx + i][dy + c + j] += g[dx + i][dy + c - j - 1];
        dy += c;
        if (m < dy + 2 * c)
          m = dy + 2 * c;
      }
    }
    while (p--) {
      int x, y;
      cin >> x >> y;
      cout << g[dx + x][dy + y] << endl;
    }
  }
  return 0;
}
Problem p01110 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, m, t, p;
  while (cin >> n >> m >> t >> p, n) {
    vector<pair<int, int>> d(t), x(p);
    for (auto &e : d)
      cin >> e.first >> e.second;
    for (auto &e : x)
      cin >> e.first >> e.second;

    vector<vector<int>> a((t + 1) * m, vector<int>((t + 1) * n));
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < n; j++) {
        a[i][j] = 1;
      }
    }
    int x0 = 0, y0 = 0;
    for (auto e : d) {
      if (e.first == 1) {
        x0 += e.second;
        for (int i = 0; a[y0 + i][x0]; i++) {
          for (int j = 0;
               x0 - j - 1 >= 0 && (a[y0 + i][x0 + j] || a[y0 + i][x0 - j - 1]);
               j++) {
            a[y0 + i][x0 + j] += a[y0 + i][x0 - j - 1];
            a[y0 + i][x0 - j - 1] = 0;
          }
        }
      } else {
        y0 += e.second;
        for (int j = 0; a[y0][x0 + j]; j++) {
          for (int i = 0;
               y0 - i - 1 >= 0 && (a[y0 + i][x0 + j] || a[y0 - i - 1][x0 + j]);
               i++) {
            a[y0 + i][x0 + j] += a[y0 - i - 1][x0 + j];
            a[y0 - i - 1][x0 + j] = 0;
          }
        }
      }
    }

    for (auto e : x) {
      cout << a[y0 + e.second][x0 + e.first] << endl;
    }
  }
}


Error: 0

Fixed submission:

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

int main() {
  int n, m, t, p;
  while (cin >> n >> m >> t >> p, n) {
    vector<pair<int, int>> d(t), x(p);
    for (auto &e : d)
      cin >> e.first >> e.second;
    for (auto &e : x)
      cin >> e.first >> e.second;

    vector<vector<int>> a(2 * m, vector<int>(2 * n));
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < n; j++) {
        a[i][j] = 1;
      }
    }
    int x0 = 0, y0 = 0;
    for (auto e : d) {
      if (e.first == 1) {
        x0 += e.second;
        for (int i = 0; a[y0 + i][x0]; i++) {
          for (int j = 0;
               x0 - j - 1 >= 0 && (a[y0 + i][x0 + j] || a[y0 + i][x0 - j - 1]);
               j++) {
            a[y0 + i][x0 + j] += a[y0 + i][x0 - j - 1];
            a[y0 + i][x0 - j - 1] = 0;
          }
        }
      } else {
        y0 += e.second;
        for (int j = 0; a[y0][x0 + j]; j++) {
          for (int i = 0;
               y0 - i - 1 >= 0 && (a[y0 + i][x0 + j] || a[y0 - i - 1][x0 + j]);
               i++) {
            a[y0 + i][x0 + j] += a[y0 - i - 1][x0 + j];
            a[y0 - i - 1][x0 + j] = 0;
          }
        }
      }
    }

    for (auto e : x) {
      cout << a[y0 + e.second][x0 + e.first] << endl;
    }
  }
}
Problem p01110 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define LL long long

using namespace std;

int a[1005][1005];

int main() {
  int n, m, t, p;
  while (scanf("%d%d%d%d", &m, &n, &t, &p)) {
    if (n == 0 && m == 0 && t == 0 && p == 0)
      break;
    int ox = 0, oy = 0;
    memset(a, 0, sizeof(a));
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++)
        a[i][j] = 1;

    for (int i = 0; i < t; i++) {
      int d, c;
      scanf("%d%d", &d, &c);
      if (d == 2) {
        for (int j = c + ox; j < c + ox + c; j++)
          for (int k = oy; k < oy + m; k++)
            if (2 * (c + ox) - j - 1 >= 0)
              a[j][k] += a[2 * (c + ox) - j - 1][k];
        ox += c;
        n = max(n - c, c);
      }

      if (d == 1) {
        for (int j = ox; j < ox + n; j++)
          for (int k = c + oy; k < c + oy + c; k++)
            if (2 * (c + oy) - k - 1 >= 0)
              a[j][k] += a[j][2 * (c + oy) - k - 1];

        oy += c;
        m = max(m - c, c);
      }
    }
    for (int i = 0; i < p; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      printf("%d\\n", a[y + ox][x + oy]);
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int M, N, T, P, d, c;
int a[65][65];
int vis[65][65];
int cnt;
void rev() {
  int t = N & 1;
  t ^= 1;

  for (int i = 0; i < N / 2; ++i)
    for (int j = 0; j < M; ++j)
      swap(a[i][j], a[N / 2 - i + N / 2 - t][j]);
}

int main() {
  while (1) {
    scanf("%d%d%d%d", &M, &N, &T, &P);

    for (int i = 0; i < N; ++i)
      for (int j = 0; j < M; ++j) {
        a[i][j] = 1;
        vis[i][j] = 1;
      }

    for (int i = 1; i <= T; ++i) {
      ++cnt;
      scanf("%d%d", &d, &c);

      if (d == 1) {
        for (int j = 0; j < c; ++j) {
          for (int k = 0; k < N; ++k) {
            if (vis[k][c - j + c - 1] == cnt)
              a[k][c - j + c - 1] += a[k][j];
            else {
              a[k][c - j + c - 1] = a[k][j];
              vis[k][c - j + c - 1] = cnt;
            }
          }
        }
        if (M - c > c)
          M = M - c;
        else
          M = c;
        for (int j = 0; j < N; ++j) {
          for (int k = 0; k < M; ++k) {
            a[j][k] = a[j][k + c];
            vis[j][k] = cnt + 1;
          }
        }
      } else {
        for (int j = 0; j < c; ++j) {
          for (int k = 0; k < M; ++k) {
            if (vis[c - j + c - 1][k] == cnt)
              a[c - j + c - 1][k] += a[j][k];
            else {
              a[c - j + c - 1][k] = a[j][k];
              vis[c - j + c - 1][k] = cnt;
            }
          }
        }
        if (c > N - c)
          N = c;
        else
          N -= c;
        for (int j = 0; j < N; ++j)
          for (int k = 0; k < M; ++k) {
            a[j][k] = a[j + c][k];
            vis[j][k] = cnt + 1;
          }
        // rev();
      }
    }

    int ans = 0, x, y;
    for (int i = 1; i <= P; ++i) {
      scanf("%d%d", &x, &y);
      printf("%d\\n", a[y][x]);
    }
  }
}
/*
10 8 3 2
2 2
1 3
1 1
0 1
*/
Problem p01110 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int AX = 1e3 + 66;
int vis[AX][AX];
int res[AX][AX];
int main() {
  int n, m, t, p;
  while (scanf("%d%d%d%d", &n, &m, &t, &p) && n && m && t && p) {
    memset(vis, 0, sizeof(vis));
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < n; j++) {
        vis[i][j] = 1;
      }
    }
    int left = 0;
    int down = 0;
    int x, y;
    int op;
    for (int i = 0; i < t; i++) {
      // cout << "?? : " << vis[3][4] << endl;
      scanf("%d%d", &op, &x);
      if (op == 2) {
        down += x;
        int s = 0;
        m = max(m, down + x);
        for (int k = down; k < down + x; k++) {
          s++;
          for (int j = left; j < n; j++) {
            vis[k][j] += vis[down - s][j];
          }
        }
      } else {
        left += x;
        int s = 0;
        n = max(n, left + x);
        for (int j = left; j < left + x; j++) {
          s++;
          for (int k = down; k < m; k++) {
            vis[k][j] += vis[k][left - s];
          }
        }
      }
    }

    for (int i = 0; i < p; i++) {
      scanf("%d%d", &x, &y);

      printf("%d\\n", vis[y + down][x + left]);
    }
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int AX = 300;
int vis[AX][AX];
int res[AX][AX];
int main() {
  int n, m, t, p;
  while (scanf("%d%d%d%d", &n, &m, &t, &p) && n && m && t && p) {
    for (int i = 0; i < AX; i++) {
      for (int j = 0; j < AX; j++) {
        vis[i][j] = 0;
      }
    }
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < n; j++) {
        vis[i][j] = 1;
      }
    }
    int left = 0;
    int down = 0;
    int x, y;
    int op;
    for (int i = 0; i < t; i++) {
      // cout << "?? : " << vis[3][4] << endl;
      scanf("%d%d", &op, &x);
      if (op == 2) {
        down += x;
        int s = 0;
        m = max(m, down + x);
        for (int k = down; k < down + x; k++) {
          s++;
          for (int j = left; j < n; j++) {
            vis[k][j] += vis[down - s][j];
          }
        }
      } else {
        left += x;
        int s = 0;
        n = max(n, left + x);
        for (int j = left; j < left + x; j++) {
          s++;
          for (int k = down; k < m; k++) {
            vis[k][j] += vis[k][left - s];
          }
        }
      }
    }

    for (int i = 0; i < p; i++) {
      scanf("%d%d", &x, &y);

      printf("%d\\n", vis[y + down][x + left]);
    }
  }
  return 0;
}
Problem p01110 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

using namespace std;

int main() {
  while (true) {
    int n, m, t, p;
    cin >> n >> m >> t >> p;
    if (n == 0)
      break;

    vector<vector<int>> card(500, vector<int>(500, 0));
    for (int x = 0; x < n; ++x) {
      for (int y = 0; y < m; ++y) {
        card[x][y] = 1;
      }
    }

    int l = 0, u = 0;
    for (int q = 0; q < t; ++q) {
      int d, c;
      cin >> d >> c;

      if (d == 1) {
        for (int x = 0; x < c; ++x) {
          for (int y = 0; y < m; ++y) {
            card[l + c * 2 - x - 1][u + y] += card[l + x][u + y];
            card[l + x][u + y] = 0;
          }
        }
        l += c;
        n = max(c, n - c);
      } else {
        for (int x = 0; x < n; ++x) {
          for (int y = 0; y < c; ++y) {
            card[l + x][u + c * 2 - 1 - y] += card[l + x][u + y];
            card[l + x][u + y] = 0;
          }
        }
        u += c;
        m = max(c, m - c);
      }
    }

    for (int q = 0; q < p; ++q) {
      int x, y;
      cin >> x >> y;
      cout << card[l + x][u + y] << endl;
    }
  }
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int main() {
  while (true) {
    int n, m, t, p;
    cin >> n >> m >> t >> p;
    if (n == 0)
      break;

    vector<vector<int>> card(300, vector<int>(300, 0));
    for (int x = 0; x < n; ++x) {
      for (int y = 0; y < m; ++y) {
        card[x][y] = 1;
      }
    }

    int l = 0, u = 0;
    for (int q = 0; q < t; ++q) {
      int d, c;
      cin >> d >> c;

      if (d == 1) {
        for (int x = 0; x < c; ++x) {
          for (int y = 0; y < m; ++y) {
            card[l + c * 2 - x - 1][u + y] += card[l + x][u + y];
            card[l + x][u + y] = 0;
          }
        }
        l += c;
        n = max(c, n - c);
      } else {
        for (int x = 0; x < n; ++x) {
          for (int y = 0; y < c; ++y) {
            card[l + x][u + c * 2 - 1 - y] += card[l + x][u + y];
            card[l + x][u + y] = 0;
          }
        }
        u += c;
        m = max(c, m - c);
      }
    }

    for (int q = 0; q < p; ++q) {
      int x, y;
      cin >> x >> y;
      cout << card[l + x][u + y] << endl;
    }
  }
  return 0;
}
Problem p01110 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int n, m, t, p;
  while (true) {
    cin >> n >> m >> t >> p;
    int hnum = 0, wnum = 0;
    long long int origami[500][500];
    for (int i = 0; i < 500; i++) {
      for (int j = 0; j < 500; j++) {
        origami[i][j] = 0;
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        origami[i][j] = 1;
      }
    }
    if (n == 0)
      break;
    for (int i = 0; i < t; i++) {
      int d, c;
      cin >> d >> c;
      if (d == 1) {
        for (int j = wnum + c; j < wnum + c * 2; j++) {
          for (int k = 0; k < m * 2; k++) {
            origami[j][k] += origami[c + wnum - (j - wnum - c) - 1][k];
          }
        }
        wnum += c;
      } else {
        for (int j = 0; j < n * 2; j++) {
          for (int k = hnum + c; k < hnum + c * 2; k++) {
            origami[j][k] += origami[j][c + hnum - (k - hnum - c) - 1];
          }
        }
        hnum += c;
      }
      /*
      for(int j=0;j<m;j++){
          for(int k =0;k<n+1;k++){
              cerr<<origami[k][j];
          }
          cerr<<endl;
      }*/
    }
    for (int i = 0; i < p; i++) {
      int x, y;
      cin >> x >> y;
      cout << origami[x + wnum][y + hnum] << endl;
    }
  }
  return 0;
}


Error: WA

Fixed submission:

#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int main() {
  while (true) {
    int n, m, t, p;
    cin >> n >> m >> t >> p;
    if (n == 0)
      break;
    vector<int> d(t);
    vector<int> c(t);
    vector<vector<int>> origami(n * 3, vector<int>(m * 3, 1));
    int xpos = 0;
    int ypos = 0;
    for (int i = 0; i < t; i++) {
      cin >> d[i] >> c[i];
      if (d[i] == 1) {
        for (int k = c[i] + xpos; k < c[i] * 2 + xpos; k++) {
          for (int j = ypos; j < m; j++) {
            origami[k][j] += origami[k - (c[i])][j];
          }
        }
        xpos += c[i];
      } else {
        for (int k = xpos; k < n; k++) {
          for (int j = c[i] + ypos; j < c[i] * 2 + ypos; j++) {
            origami[k][j] += origami[k][j - c[i]];
          }
        }
        ypos += c[i];
      }
    }
    vector<int> x(p);
    vector<int> y(p);
    int ans = 0;
    for (int i = 0; i < p; i++) {
      cin >> x[i] >> y[i];
      cout << origami[x[i] + xpos][y[i] + ypos] << endl;
    }
  }

  return 0;
}