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

#include <cstdio>
#include <cstring>

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

using namespace std;

int n, nh;
char tr[10000][11];
int hit[10000], blow[10000];

char ans[11];
int gen(int i, char *s, bool *used) {
  rep(j, nh) {
    int h = hit[j], b = blow[j];
    rep(k, i) rep(l, n) if (s[k] == tr[j][l]) {
      if (k == l)
        h--;
      else
        b--;
    }
    if (h < 0 || b < 0 || h + b > n - i)
      return 0;
  }

  if (i == n) {
    strcpy(ans, s);
    return 1;
  }

  int res = 0;
  for (int c = '0'; c <= '9'; c++)
    if (!used[c]) {
      used[c] = true;
      s[i] = c;
      res += gen(i + 1, s, used);
      used[c] = false;
      if (res >= 2)
        return res;
    }
  return res;
}

int main() {
  for (; scanf("%d%d", &n, &nh), n;) {
    rep(i, nh) scanf("%s%d%d", tr[i], hit + i, blow + i);

    char s[11] = {};
    bool used[128] = {};
    printf("%s\\n", gen(0, s, used) == 1 ? ans : "NO");
  }

  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>

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

using namespace std;

bool isvalid(int n, const char *s, const char *tr, int hit, int blow) {
  rep(i, n) rep(j, n) if (s[i] == tr[j]) {
    if (i == j)
      hit--;
    else
      blow--;
  }
  return hit == 0 && blow == 0;
}

int m, idx[3628800];
char s[3628800][11];
void gen(int i, int n, char *tmp, bool *used) {
  if (i == n) {
    strcpy(s[m], tmp);
    idx[m] = m++;
    return;
  }

  for (int c = '0'; c <= '9'; c++)
    if (!used[c]) {
      used[c] = true;
      tmp[i] = c;
      gen(i + 1, n, tmp, used);
      used[c] = false;
    }
}

int main() {
  for (int n, nh; scanf("%d%d", &n, &nh), n;) {
    m = 0;
    char tmp[11] = "";
    bool used[128] = {};
    gen(0, n, tmp, used);

    // printf("m=%d\\n",m);
    // rep(i,10) puts(s[i]);
    while (nh--) {
      char tr[11];
      int hit, blow;
      scanf("%s%d%d", tr, &hit, &blow);

      rep(i, m) if (!isvalid(n, s[idx[i]], tr, hit, blow)) {
        swap(idx[i], idx[m - 1]);
        i--;
        m--;
      }
    }

    printf("%s\\n", m == 1 ? s[idx[0]] : "NO");
  }

  return 0;
}
Problem p00703 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstring>
#include <iostream>
#include <vector>
using namespace std;

int n, m;
int h[100], b[100];
bool bad[10][10];
vector<int> t[100], val, ans;

bool check(bool *used) {
  for (int i = 0; i < m; i++) {
    int hit = 0, blow = 0;
    for (int j = 0; j < n; j++) {
      if (val[j] == t[i][j]) {
        hit++;
      } else if (used[t[i][j]]) {
        blow++;
      }
    }
    if (hit != h[i] || blow != b[i])
      return false;
  }
  return true;
}

bool solve(int idx, bool *used) {
  if (idx == n) {
    if (!check(used))
      return true;
    if (!ans.empty())
      return false;
    ans = val;
    return true;
  }

  for (int i = 0; i < 10; i++) {
    if (used[i] || bad[idx][i])
      continue;
    used[i] = true;
    val[idx] = i;
    if (!solve(idx + 1, used))
      return false;
    used[i] = false;
  }

  return true;
}

int main(void) {
  while (cin >> n >> m, n || m) {
    memset(bad, 0, sizeof(bad));
    for (int i = 0; i < m; i++) {
      string s;
      cin >> s >> h[i] >> b[i];
      t[i].clear();
      for (int j = 0; j < n; j++) {
        t[i].push_back(s[j] - '0');
        if (h[i] == 0)
          bad[j][t[i][j]] = true;
      }
    }

    bool used[10];
    memset(used, 0, sizeof(used));
    ans.clear();
    val = vector<int>(n);
    bool flg = solve(0, used);

    if (flg && !ans.empty()) {
      for (int i = 0; i < n; i++)
        cout << ans[i];
      cout << endl;
    } else {
      cout << "NO\\n";
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cstring>
#include <iostream>
#include <vector>
using namespace std;

int n, m;
int h[100], b[100];
vector<int> t[100], val, ans;

bool check(bool *used) {
  for (int i = 0; i < m; i++) {
    int hit = 0, blow = 0;
    for (int j = 0; j < n; j++) {
      if (val[j] == t[i][j]) {
        hit++;
      } else if (used[t[i][j]]) {
        blow++;
      }
    }
    if (hit != h[i] || blow != b[i])
      return false;
  }
  return true;
}

bool solve(int idx, bool *used) {
  if (idx == n) {
    if (!check(used))
      return true;
    if (!ans.empty())
      return false;
    ans = val;
    return true;
  }

  for (int i = 0; i < 10; i++) {
    if (used[i])
      continue;
    used[i] = true;
    val[idx] = i;
    if (!solve(idx + 1, used))
      return false;
    used[i] = false;
  }

  return true;
}

int main(void) {
  while (cin >> n >> m, n || m) {
    for (int i = 0; i < m; i++) {
      string s;
      cin >> s >> h[i] >> b[i];
      t[i].clear();
      for (int j = 0; j < n; j++) {
        t[i].push_back(s[j] - '0');
      }
    }

    bool used[10];
    memset(used, 0, sizeof(used));
    ans.clear();
    val = vector<int>(n);
    bool flg = solve(0, used);

    if (flg && !ans.empty()) {
      for (int i = 0; i < n; i++)
        cout << ans[i];
      cout << endl;
    } else {
      cout << "NO\\n";
    }
  }

  return 0;
}
Problem p00706 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

#define int long long

int H, W, S, T;
bool fld[100][100];

int Count(int x, int y) {
  int res = 0;
  for (int i = y; i < y + T; i++) {
    for (int j = x; j < x + S; j++) {
      res += fld[i][j];
    }
  }
  return res;
}

signed main() {
  int N;
  while (cin >> N, N) {
    fill_n((bool *)fld, 100 * 100, false);
    cin >> W >> H;
    for (int i = 0; i < N; i++) {
      int X, Y;
      cin >> X >> Y;
      X--;
      Y--;
      fld[Y][X] = true;
    }
    cin >> S >> T;

    int ma = 0;
    for (int i = 0; i <= H - T; i++) {
      for (int j = 0; j <= W - S; j++) {
        ma = max(ma, Count(j, i));
      }
    }
    printf("%lld\\n", ma);
  }
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define int long long

int H, W, S, T;
bool fld[100][100];

int Count(int x, int y) {
  int res = 0;
  for (int i = y; i < y + T; i++) {
    for (int j = x; j < x + S; j++) {
      res += fld[i][j];
    }
  }
  return res;
}

signed main() {
  int N;
  while (cin >> N, N) {
    fill_n((bool *)fld, 100 * 1000, false);
    cin >> W >> H;
    for (int i = 0; i < N; i++) {
      int X, Y;
      cin >> X >> Y;
      X--;
      Y--;
      fld[Y][X] = true;
    }
    cin >> S >> T;

    int ma = 0;
    for (int i = 0; i <= H - T; i++) {
      for (int j = 0; j <= W - S; j++) {
        ma = max(ma, Count(j, i));
      }
    }
    printf("%lld\\n", ma);
  }
}
Problem p00706 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define abs(a) max((a), -(a))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repe(i, n) rep(i, (n) + 1)
#define per(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define pere(i, n) rep(i, (n) + 1)
#define all(x) (x).begin(), (x).end()
#define SP << " " <<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main() {
  while (1) {
    int n, w, h;
    cin >> n >> w >> h;
    if (n == 0)
      return 0;
    vector<vector<int>> ruiseki(h + 1, vector<int>(w + 1, 0));
    int x, y;
    for (int i = 0; i < n; i++) {
      cin >> x >> y;
      ruiseki[y][x]++;
    }
    for (int i = 1; i <= h; i++) {
      for (int j = 1; j <= w; j++) {
        ruiseki[i][j] +=
            +ruiseki[i - 1][j] + ruiseki[i][j - 1] - ruiseki[i - 1][j - 1];
      }
    }
    int s, t;
    cin >> t >> s;
    int ans = 0;
    for (int i = s; i <= h; i++) {
      for (int j = t; j <= w; j++) {
        ans = max(ans, ruiseki[i][j] - ruiseki[i - s][j] - ruiseki[i][j - t] +
                           ruiseki[i - s][j - t]);
      }
    }
    cout << ans << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

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

#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define abs(a) max((a), -(a))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repe(i, n) rep(i, (n) + 1)
#define per(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define pere(i, n) rep(i, (n) + 1)
#define all(x) (x).begin(), (x).end()
#define SP << " " <<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main() {
  while (1) {
    int n, w, h;
    cin >> n >> w >> h;
    vector<vector<int>> ruiseki(h + 1, vector<int>(w + 1, 0));
    int x, y;
    for (int i = 0; i < n; i++) {
      cin >> x >> y;
      ruiseki[y][x]++;
    }
    for (int i = 1; i <= h; i++) {
      for (int j = 1; j <= w; j++) {
        ruiseki[i][j] +=
            +ruiseki[i - 1][j] + ruiseki[i][j - 1] - ruiseki[i - 1][j - 1];
      }
    }
    int s, t;
    cin >> t >> s;
    int ans = 0;
    for (int i = s; i <= h; i++) {
      for (int j = t; j <= w; j++) {
        ans = max(ans, ruiseki[i][j] - ruiseki[i - s][j] - ruiseki[i][j - t] +
                           ruiseki[i - s][j - t]);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00706 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = a; i < b; ++i)
int main() {
  int n;
  while (cin >> n, n) {
    int w, h;
    cin >> w >> h;
    vector<vector<int>> c(h, vector<int>(w, 0));
    FOR(i, 0, n) {
      int x, y;
      cin >> x >> y;
      c[--y][--x] = 1;
    }
    int s, t;
    cin >> s >> t;
    int ans = 0;
    FOR(i, 0, h - t + 1) FOR(j, 0, w - s + 1) {
      int a = 0;
      FOR(k, i, i + t) FOR(l, j, j + s) a += c[k][l];
      ans = max(ans, a);
    }
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = a; i < b; ++i)
int main() {
  int n;
  while (cin >> n, n) {
    int w, h;
    cin >> w >> h;
    vector<vector<int>> c(n, vector<int>(n, 0));
    FOR(i, 0, n) {
      int x, y;
      cin >> x >> y;
      c[--y][--x] = 1;
    }
    int s, t;
    cin >> s >> t;
    int ans = 0;
    FOR(i, 0, h - t + 1) FOR(j, 0, w - s + 1) {
      int a = 0;
      FOR(k, i, i + t) FOR(l, j, j + s) { a += c[k][l]; }
      ans = max(ans, a);
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00706 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  while (true) {
    int N;
    cin >> N;
    if (N == 0)
      break;
    int W, H;
    cin >> W >> H;
    int F[W][H];
    memset(F, 0, sizeof(F));
    for (int i = 0; i < N; ++i) {
      int x, y;
      cin >> x >> y;
      x--, y--;
      F[x][y] = 1;
    }
    int S, T;
    cin >> S >> T;
    int G[W + 1][H + 1];
    memset(G, 0, sizeof(G));
    for (int y = 1; y <= H; ++y) {
      for (int x = 1; x <= W; ++x) {
        G[x][y] = G[x - 1][y] + G[x][y - 1] - G[x - 1][y - 1] + F[x - 1][y - 1];
        // cerr << "G(" << y << "," << x << ") = " << G[x][y] << endl;
      }
    }
    int ans = 0;
    for (int y = T; y <= H; ++y) {
      for (int x = S; x <= W; ++x) {
        ans = max(ans, G[x][y] - G[x - S][y] - G[x][y - T] + G[x - S][y - T]);
      }
    }
    cout << ans << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  while (true) {
    int N;
    cin >> N;
    if (N == 0)
      break;
    int W, H;
    cin >> W >> H;
    int F[W][H];
    memset(F, 0, sizeof(F));
    for (int i = 0; i < N; ++i) {
      int x, y;
      cin >> x >> y;
      F[x][y] = 1;
    }
    int S, T;
    cin >> S >> T;
    int G[W + 1][H + 1];
    memset(G, 0, sizeof(G));
    for (int y = 1; y <= H; ++y) {
      for (int x = 1; x <= W; ++x) {
        G[x][y] = G[x - 1][y] + G[x][y - 1] - G[x - 1][y - 1] + F[x - 1][y - 1];
      }
    }
    int ans = 0;
    for (int y = T; y <= H; ++y) {
      for (int x = S; x <= W; ++x) {
        ans = max(ans, G[x][y] - G[x - S][y] - G[x][y - T] + G[x - S][y - T]);
      }
    }
    cout << ans << endl;
  }
}
Problem p00706 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
using namespace std;
int main() {
  int n, h, w, x[1000], y[1000], s, t;
  while (true) {
    cin >> n;
    if (n == 0)
      break;
    cin >> w >> h;
    for (int i = 0; i < n; i++)
      cin >> x[i] >> y[i];
    cin >> s >> t;
    int best = 0;
    for (int i = 0; i <= h - t; i++) {
      for (int j = 0; j <= w - s; j++) {
        int count = 0;
        for (int k = 0; k < n; k++) {
          if (j + 1 <= x[k] && j + s >= x[k] && i + 1 <= y[k] && i + t >= y[k])
            count++;
        }
        if (count > best)
          best = count;
      }
    }
    cout << best << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main() {
  int n, w, h, s, t;
  while (true) {
    cin >> n;
    if (n == 0)
      break;
    cin >> w >> h;
    int x[100], y[100];
    for (int i = 0; i < n; i++)
      cin >> x[i] >> y[i];
    cin >> s >> t;
    int best = 0;
    for (int i = 1; i <= h - t + 1; i++) {
      for (int j = 1; j <= w - s + 1; j++) {
        int count = 0;
        for (int k = 0; k < n; k++) {
          if (i <= y[k] && i + t > y[k] && j <= x[k] && j + s > x[k])
            count++;
        }
        if (count > best)
          best = count;
      }
    }
    cout << best << endl;
  }
  return 0;
}
Problem p00706 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

int main(int argc, char const *argv[]) {
  while (true) {
    int N;
    std::cin >> N;
    if (N == 0)
      break;
    int W, H;
    std::cin >> W >> H;
    std::vector<std::vector<char>> field(H, std::vector<char>(W, 0));
    for (int i = 0; i < N; ++i) {
      int x, y;
      std::cin >> x >> y;
      field[y - 1][x - 1] = 1;
    }
    int S, T;
    std::cin >> S >> T;

    int max_trees = 0;
    for (int y = 0; y <= H - T; ++y) {
      for (int x = 0; x <= W - S; ++x) {
        int cnt = 0;
        for (int h = 0; h < T; ++h)
          for (int w = 0; w < S; ++w)
            if (field[y + h][x + w])
              ++cnt;
        if (cnt > max_trees)
          max_trees = cnt;
      }
    }
    std::cout << max_trees << std::endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
#include <vector>

int main(int argc, char const *argv[]) {
  while (true) {
    int N;
    std::cin >> N;
    if (N == 0)
      break;
    int W, H;
    std::cin >> W >> H;
    std::vector<std::vector<char>> field(W, std::vector<char>(H, 0));
    for (int i = 0; i < N; ++i) {
      int x, y;
      std::cin >> x >> y;
      field[y - 1][x - 1] = 1;
    }
    int S, T;
    std::cin >> S >> T;
    int max_trees = 0;
    for (int i = 0; i < H; ++i) {
      for (int j = 0; j < W; ++j) {
        int cnt = 0;
        for (int k = 0; k < T; ++k)
          for (int l = 0; l < S; ++l)
            if (field[i + k][j + l])
              ++cnt;
        if (cnt > max_trees)
          max_trees = cnt;
      }
    }
    std::cout << max_trees << std::endl;
  }
  return 0;
}
Problem p00706 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cctype>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, a, b) for (int i = (a); i < b; i++)
#define INF 1000000000
using namespace std;
bool debug = false;

int main() {
  int n;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    int w, h;
    cin >> w >> h;
    int d[101][101];
    for (int i = 0; i < 101; i++)
      for (int j = 0; j < 101; j++)
        d[i][j] = 0;

    for (int i = 0; i < n; i++) {
      int x, y;
      cin >> x >> y;
      d[y][x] = 1;
    }

    if (debug) {
      for (int i = 0; i <= h; i++) {
        for (int j = 0; j <= w; j++) {
          cout << d[i][j] << " ";
        }
        cout << endl;
      }
    }

    int maxi = 0;
    int s, t;
    cin >> s >> t;
    for (int i = 0; i <= h - t + 1; i++) {
      for (int j = 0; j <= w - s + 1; j++) {
        int cnt = 0;
        for (int k = 0; k < t; k++) {
          for (int l = 0; l < s; l++) {
            if (d[k + i][l + j] == 1)
              cnt++;
          }
        }
        maxi = max(maxi, cnt);
      }
    }
    cout << maxi << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, a, b) for (int i = (a); i < b; i++)
#define INF 1000000000
using namespace std;
bool debug = false;

int main() {
  int n;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    int w, h;
    cin >> w >> h;
    int d[w][h];
    for (int i = 0; i < h; i++)
      for (int j = 0; j < w; j++)
        d[i][j] = 0;

    for (int i = 0; i < n; i++) {
      int x, y;
      cin >> x >> y;
      d[y][x] = 1;
    }
    int maxi = 0;
    int s, t;
    cin >> s >> t;
    for (int i = 0; i < w - s; i++) {
      for (int j = 0; j < h - t; j++) {
        int cnt = 0;
        for (int k = 0; k < t; k++) {
          for (int l = 0; l < s; l++) {
            if (d[k + j][l + i] == 1)
              cnt++;
          }
        }
        maxi = max(maxi, cnt);
      }
    }
    cout << maxi << endl;
  }
  return 0;
}
Problem p00706 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define rep(i, a) for (int i = 0; i < a; i++)
using namespace std;

int main(void) {
  int n;
  int w, h, s, t;
  while (cin >> n, n) {
    cin >> w >> h;
    vector<vector<int>> m(h, vector<int>(w));
    // cout<<w<<' '<<h<<endl;
    rep(i, n) {
      int a, b;
      cin >> a >> b;
      --a, --b;
      m[b][a]++;
    }
    cin >> t >> s;
    /*
    cout<<w<<' '<<h<<endl;
    cout<<s<<' '<<t<<endl;
    cout<<h-s+1<<' '<<w-t+1<<endl;//*/
    // rep(i,h){rep(j,w)cout<<m[i][j];cout<<endl;}
    int ret = -1;
    rep(i, h - s + 1) {
      rep(j, w - t + 1) {
        int c = 0;
        //				cout<<i<<' '<<j<<endl;
        rep(k, s) rep(l, t) if (m[i + k][j + l]) c++;
        ret = max(c, ret);
      }
    }
    cout << ret << endl;
  }
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define rep(i, a) for (int i = 0; i < a; i++)
using namespace std;

int main(void) {
  int n;
  int w, h, s, t;
  while (cin >> n, n) {
    cin >> w >> h;
    vector<vector<int>> m(h, vector<int>(w));
    rep(i, n) {
      int a, b;
      cin >> a >> b;
      --a, --b;
      m[b][a]++;
    }
    cin >> s >> t;
    // rep(i,h){rep(j,w)cout<<m[i][j];cout<<endl;}
    int ret = -1;
    rep(i, h - s + 1) {
      rep(j, w - t + 1) {
        int c = 0;
        rep(k, s) rep(l, t) if (m[i + l][j + k]) c++;
        ret = max(c, ret);
      }
    }
    cout << ret << endl;
  }
}
Problem p00706 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) range(i, 0, b)
#define vi vector<int>
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a), end()
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int tree[505][2];

int countTrees(int w, int h, int s, int t, int n) {
  int trees = 0, count;
  range(i, 1, h - t + 2) {
    range(j, 1, w - s + 2) {
      count = 0;
      rep(k, n) {
        if (j <= tree[k][0] && j + s - 1 >= tree[k][0] && i <= tree[k][1] &&
            i + t - 1 >= tree[k][1]) {
          count++;
        }
      }
      trees = max(trees, count);
    }
  }
  return trees;
}

int solve(int w, int h, int s, int t, int n) {
  return max(countTrees(w, h, s, t, n), countTrees(h, w, s, t, n));
}

int main() {
  int n;
  while (cin >> n, n) {
    rep(i, 505) rep(j, 2) tree[i][j] = 0;
    int w, h, s, t;
    cin >> w >> h;
    rep(i, n) { cin >> tree[i][0] >> tree[i][1]; }
    cin >> s >> t;
    cout << solve(w, h, s, t, n) << endl;
  }
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) range(i, 0, b)
#define vi vector<int>
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a), end()
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int tree[105][2];

int countTrees(int w, int h, int s, int t, int n) {
  int trees = 0, count;
  rep(i, h - t + 1) {
    rep(j, w - s + 1) {
      count = 0;
      rep(k, n) {
        if (j <= tree[k][0] && j + s - 1 >= tree[k][0] && i <= tree[k][1] &&
            i + t - 1 >= tree[k][1]) {
          count++;
        }
      }
      trees = max(trees, count);
    }
  }
  return trees;
}

int solve(int w, int h, int s, int t, int n) {
  return max(countTrees(w, h, s, t, n), countTrees(h, w, s, t, n));
}

int main() {
  int n;
  while (cin >> n, n) {
    rep(i, 105) rep(j, 2) tree[i][j] = 0;
    int w, h, s, t;
    cin >> w >> h;
    rep(i, n) { cin >> tree[i][0] >> tree[i][1]; }
    cin >> s >> t;
    cout << solve(w, h, s, t, n) << endl;
  }
}
Problem p00706 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i, n) for (i = 0; i < n; i++)
#define loop(i, a, n) for (i = a; i < n; i++)
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)

typedef vector<int> vi;
typedef pair<int, int> pii;

int main(void) {
  int i, j;
  int n;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    int h, w;
    cin >> w >> h;
    vector<vi> v(w, vi(h, 0));
    rep(i, n) {
      int x, y;
      cin >> x >> y;
      v[x - 1][y - 1]++;
    }
    int s, t, k, l;
    cin >> s >> t;
    int ans = 0;
    rep(i, w - s + 1) rep(j, h - t + 1) {
      int tmp = 0;
      rep(k, s) rep(l, t) if (v[i + k][j + l]) tmp++;
      ans = max(ans, tmp);
    }
    cout << ans << endl;
  }
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i, n) for (i = 0; i < n; i++)
#define loop(i, a, n) for (i = a; i < n; i++)
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)

typedef vector<int> vi;
typedef pair<int, int> pii;

int main(void) {
  int i, j;
  int n;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    int h, w;
    cin >> h >> w;
    vector<vi> v(h, vi(w, 0));
    rep(i, n) {
      int x, y;
      cin >> x >> y;
      v[y - 1][x - 1]++;
    }
    int s, t, k, l;
    cin >> s >> t;
    int ans = 0;
    rep(i, h - t) rep(j, w - s) {
      int tmp = 0;
      rep(k, t) rep(l, s) if (v[i + k][j + l]) tmp++;
      ans = max(ans, tmp);
    }
    cout << ans << endl;
  }
}