alexjercan/bugnet huggingface dataset:
Problem p00441 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define int long long // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rrep2(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(a) (a).begin(), (a).end()

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
typedef vector<vector<int>> Graph;
const int inf = 1e9;
const int mod = 1e9 + 7;

const int MAX = 5001;
bool exist[MAX][MAX];

inline bool inside(int x, int y) {
  return 0 <= x && x < MAX && 0 <= y && y < MAX;
}

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

  int n;
  while (cin >> n, n) {
    rep(i, 5001) rep(j, 5001) exist[i][j] = false;

    V x(n), y(n);
    rep(i, n) {
      cin >> x[i] >> y[i];
      exist[x[i]][y[i]] = true;
    }

    int ans = 0;
    rep(i, n) {
      rep2(j, i + 1, n) {
        int dx = x[j] - x[i];
        int dy = y[j] - y[i];
        int x1 = x[i] + dy, y1 = y[i] - dx;
        int x2 = x[j] + dy, y2 = y[j] - dx;
        if (!inside(x1, y1) || !inside(x2, y2))
          continue;
        if (exist[x[i] + dy][y[i] - dx] && exist[x[j] + dy][y[j] - dx]) {
          ans = max(ans, dx * dx + dy * dy);
        }
      }
    }

    cout << ans << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rrep2(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(a) (a).begin(), (a).end()

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
typedef vector<vector<int>> Graph;
const int inf = 1e9;
const int mod = 1e9 + 7;

bool exist[5001][5001];

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

  int n;
  while (cin >> n, n) {
    rep(i, 5001) rep(j, 5001) exist[i][j] = false;

    V x(n), y(n);
    rep(i, n) {
      cin >> x[i] >> y[i];
      exist[x[i]][y[i]] = true;
    }

    int ans = 0;
    rep(i, n) {
      rep2(j, i + 1, n) {
        int dx = x[j] - x[i];
        int dy = y[j] - y[i];
        if (exist[x[i] + dy][y[i] - dx] && exist[x[j] + dy][y[j] - dx]) {
          ans = max(ans, dx * dx + dy * dy);
        }
      }
    }

    cout << ans << endl;
  }
}
Problem p00441 (C++) — buggy submission, verdict: Memory Limit Exceeded

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory.h>
#include <memory>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, m, n) for (int i = m; i < n; i++)
using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<double, double> Pd;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 29;
const double EPS = 1E-10;

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

map<P, bool> mp;
P pos[5000];

int main() {
  int n;
  while (cin >> n && n) {
    int res = 0;
    mp.clear();
    rep(i, n) {
      cin >> pos[i].first >> pos[i].second;
      mp[pos[i]] = true;
    }
    rep(i, n) rep(j, n) {
      if (i == j)
        continue;
      int dx = pos[i].first - pos[j].first;
      int dy = pos[i].second - pos[j].second;

      int x2 = pos[j].first + dy;
      int y2 = pos[j].second - dx;
      int x3 = x2 + dx;
      int y3 = y2 + dy;

      if (mp.find(P(x2, y2)) != mp.end() && mp.find(P(x3, y3)) != mp.end()) {
        res = max(res, dx * dx + dy * dy);
      }
    }
    cout << res << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory.h>
#include <memory>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, m, n) for (int i = m; i < n; i++)
using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<double, double> Pd;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 29;
const double EPS = 1E-10;

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

map<P, bool> mp;
P pos[5000];

int main() {
  int n;
  while (cin >> n && n) {
    int res = 0;
    mp.clear();
    rep(i, n) {
      cin >> pos[i].first >> pos[i].second;
      mp[pos[i]] = true;
    }
    rep(i, n) rep(j, n) {
      if (i == j)
        continue;
      int dx = pos[i].first - pos[j].first;
      int dy = pos[i].second - pos[j].second;

      int x2 = pos[j].first + dy;
      int y2 = pos[j].second - dx;
      int x3 = x2 + dx;
      int y3 = y2 + dy;

      if (mp[P(x2, y2)] && mp[P(x3, y3)]) {
        res = max(res, dx * dx + dy * dy);
      }
    }
    cout << res << endl;
  }
  return 0;
}
Problem p00441 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
#include <string.h>
bool p[5001][5001];
bool check(int x, int y) {
  if (x >= 0 && y >= 0 && x <= 5000 && y <= 5000 && p[x][y])
    return true;
  else
    return false;
}
int main() {
  while (1) {
    int n, x[3000], y[3000];
    long long max = 0;
    scanf("%d", &n);
    if (n == 0)
      return 0;
    memset(p, false, sizeof(p));
    for (int i = 0; i < n; i++) {
      scanf("%d %d", x + i, y + i);
      p[x[i]][y[i]] = true;
    }
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        int x1 = x[i];
        int x2 = x[j];
        int y1 = y[i];
        int y2 = y[j];
        int dx = x2 - x1;
        int dy = y2 - y1;
        if (max < dx * dx + dy * dy &&
            ((check(x1 + dy, y1 - dx) && check(x2 + dy, y2 - dx)) ||
             (check(x1 - dy, y1 - dx) && check(x2 - dy, y2 - dx))))
          max = dx * dx + dy * dy;
      }
    }
    printf("%lld\\n", max);
  }
}

Error: 0

Fixed submission:

#include <stdio.h>
#define max(a, b) ((a) > (b) ? (a) : (b))
bool p[5001][5001];
int n, x[3000], y[3000], i, j, s = 0;
int main() {
  while (1) {
    scanf("%d", &n);
    if (n == 0) {
      return 0;
    }
    for (i = 0; i < n; i++) {
      for (j = 0; j < n; j++) {
        p[i][j] = false;
      }
    }
    for (i = 0; i < n; i++) {
      scanf("%d%d", &x[i], &y[i]);
      p[x[i]][y[i]] = true;
    }
    for (i = 0; i < n; i++) {
      for (j = i + 1; j < n; j++) {
        if (x[i] + y[i] - y[j] >= 0 && y[i] + x[j] - x[i] >= 0 &&
            x[j] + y[i] - y[j] >= 0 && y[j] + x[j] - x[i] >= 0 &&
            p[x[i] + y[i] - y[j]][y[i] + x[j] - x[i]] &&
            p[x[j] + y[i] - y[j]][y[j] + x[j] - x[i]]) {
          s = max(s, (x[i] - x[j]) * (x[i] - x[j]) +
                         (y[i] - y[j]) * (y[i] - y[j]));
        }
      }
    }
    printf("%d\\n", s);
  }
  return 0;
}
Problem p00441 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define INF (2 << 28)
#define fr first
#define sc second
using namespace std;

typedef long long ll;
typedef pair<int, int> iP;

bool p[5001][5001];

int main() {

  int n;
  while (cin >> n, n) {
    memset(p, false, sizeof(p));
    vector<iP> pos(n);
    for (int i = 0; i < n; i++) {
      cin >> pos[i].fr >> pos[i].sc;
      p[pos[i].fr][pos[i].sc] = true;
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (i == j)
          continue;
        int dx = pos[i].fr - pos[j].fr, dy = pos[i].sc - pos[j].sc;
        if (0 < pos[i].fr - dy && pos[i].fr - dy < 5001 && 0 < pos[j].fr - dy &&
            pos[j].fr - dy < 5001 && 0 < pos[i].sc + dx &&
            pos[i].sc + dx < 5001 && 0 < pos[j].sc + dx &&
            pos[j].sc + dx < 5001) {
          if (p[pos[i].fr - dy][pos[i].sc + dx] &&
              p[pos[j].fr - dy][pos[j].sc + dx])
            ans = max(dx * dx + dy * dy, ans);
        }
      }
    }
    cout << ans << endl;
  }
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define INF (2 << 28)
#define fr first
#define sc second
using namespace std;

typedef long long ll;
typedef pair<int, int> iP;

bool p[11][3001][3001];

int main() {

  int n;
  while (cin >> n, n) {
    memset(p, false, sizeof(p));
    vector<iP> pos(n);
    for (int i = 0; i < n; i++) {
      cin >> pos[i].fr >> pos[i].sc;
      p[5][pos[i].fr][pos[i].sc] = true;
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (i == j)
          continue;
        int dx = pos[i].fr - pos[j].fr, dy = pos[i].sc - pos[j].sc;
        if (p[5][pos[i].fr - dy][pos[i].sc + dx] &&
            p[5][pos[j].fr - dy][pos[j].sc + dx])
          ans = max(dx * dx + dy * dy, ans);
      }
    }

    cout << ans << endl;
  }
}
Problem p00441 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define INF 100000000
typedef long long int lli;
typedef pair<int, int> P;

int x[3001];
int y[3001];
bool g[5001][5001];

int main() {
  int n, ans;
  while (cin >> n && n) {
    ans = 0;
    for (int i = 0; i < 5001; ++i) {
      for (int j = 0; j < 5001; ++j) {
        g[i][j] = false;
      }
    }
    for (int i = 0; i < n; ++i) {
      cin >> x[i];
      cin >> y[i];
      g[x[i]][y[i]] = true;
    }
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        int dy = y[j] - y[i];
        int dx = x[j] - x[i];
        if (x[j] >= x[i] && y[j] >= y[i] && 0 <= x[i] - dy &&
            x[i] - dy <= 5000 && 0 <= y[i] + dx && y[i] + dx <= 5000 &&
            0 <= x[j] - dy && x[j] - dy <= 5000 && 0 <= y[j] + dx &&
            y[j] + dx <= 5000) {
          if (g[x[i] - dy][y[i] + dx] && g[x[j] - dy][y[j] + dx]) {
            ans = max(ans, dx * dx + dy * dy);
          }
        }
      }
    }
    cout << ans << "\\n";
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define INF 100000000
typedef long long int lli;
typedef pair<int, int> P;

int x[3000];
int y[3000];
bool g[5001][5001];

int main() {
  int n, ans = 0;
  while (cin >> n && n) {
    for (int i = 0; i < 5001; ++i) {
      for (int j = 0; j < 5001; ++j) {
        g[i][j] = false;
      }
    }
    for (int i = 0; i < n; ++i) {
      cin >> x[i];
      cin >> y[i];
      g[x[i]][y[i]] = true;
    }
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        if (x[j] > x[i] && y[j] > y[i] && x[i] - (y[j] - y[i]) <= 5000 &&
            y[i] + (x[j] - x[i]) <= 5000 && x[j] - (y[j] - y[i]) <= 5000 &&
            y[j] + (x[j] - x[i]) <= 5000) {
          if (g[x[i] - (y[j] - y[i])][y[i] + (x[j] - x[i])] &&
              g[x[j] - (y[j] - y[i])][y[j] + (x[j] - x[i])]) {
            ans = max(ans, (x[j] - x[i]) * (x[j] - x[i]) +
                               (y[j] - y[i]) * (y[j] - y[i]));
          }
        }
      }
    }
    cout << ans << "\\n";
  }
  return 0;
}
Problem p00441 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
bool a[5001][5001];
int main() {
  int i, j;
  int v, w, x[3000], y[3000], n;
  int mx;
  while (cin >> n && n) {
    memset(a, 0, sizeof(a));
    for (i = 0; i < n; i++) {
      cin >> x[i] >> y[i];
      a[x[i]][y[i]] = 1;
    }
    mx = 0;
    for (i = 0; i < n - 1; i++) {
      for (j = i + 1; j < n; j++) {
        v = x[i] - x[j];
        w = y[i] - y[j];
        if ((x[i] - w >= 0 && y[i] + v >= 0 && x[j] - w >= 0 && y[j] + v >= 0 &&
             x[i] - w <= 5000 && y[i] + v <= 5000 && x[j] - w <= 5000 &&
             y[j] + v <= 5000 && a[x[i] - w][y[i] + v] &&
             a[x[j] - w][y[j] + v]) ||
            (x[i] + w >= 0 && y[i] - v >= 0 && x[j] + w >= 0 && y[j] - v >= 0 &&
             x[i] + w <= 5000 && y[i] - v <= 5000 && x[j] + w <= 5000 &&
             y[j] - v <= 5000 && a[x[i] + w][y[i] - v] &&
             a[x[j] + w][y[j] - v]))
          if (mx < v * v + w * w)
            mx = v * v + w * w;
      }
    }
    cout << mx << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int i, j;
  int v, w, x[3000], y[3000], n;
  int mx;
  bool a[5001][5001];
  while (cin >> n && n) {
    memset(a, 0, sizeof(a));
    for (i = 0; i < n; i++) {
      cin >> x[i] >> y[i];
      a[x[i]][y[i]] = 1;
    }
    mx = 0;
    for (i = 0; i < n - 1; i++) {
      for (j = i + 1; j < n; j++) {
        v = x[i] - x[j];
        w = y[i] - y[j];
        if ((x[i] - w >= 0 && y[i] + v >= 0 && x[j] - w >= 0 && y[j] + v >= 0 &&
             x[i] - w <= 5000 && y[i] + v <= 5000 && x[j] - w <= 5000 &&
             y[j] + v <= 5000 && a[x[i] - w][y[i] + v] &&
             a[x[j] - w][y[j] + v]) ||
            (x[i] + w >= 0 && y[i] - v >= 0 && x[j] + w >= 0 && y[j] - v >= 0 &&
             x[i] + w <= 5000 && y[i] - v <= 5000 && x[j] + w <= 5000 &&
             y[j] - v <= 5000 && a[x[i] + w][y[i] - v] &&
             a[x[j] + w][y[j] - v]))
          if (mx < v * v + w * w)
            mx = v * v + w * w;
      }
    }
    cout << mx << endl;
  }
  return 0;
}
Problem p00441 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <iostream>
#define REP(i, a, n) for (int i = a; i < n; i++)
using namespace std;

int n;
int x[3000], y[3000];
bool mp[5001][5001];
int m, dx, dy, s;

int exists(int x, int y) {
  return 0 <= x && x <= 5000 && 0 <= y && y <= 5000 && mp[x][y] == 1;
}

int main(void) {
  while (cin >> n, n != 0) {
    REP(i, 0, 5001) {
      REP(j, 0, 5001) { mp[i][j] = 0; }
    }
    REP(i, 0, n) {
      cin >> x[i] >> y[i];
      mp[x[i]][y[i]] = 1;
    }

    m = 0;
    REP(i, 0, n) {
      REP(j, i + 1, n) {
        dx = x[i] - x[j];
        dy = y[i] - y[j];

        if (exists(x[i] + dy, y[i] - dx) && exists(x[j] + dy, y[j] - dx)) {
          s = dx * dx + dy * dy;
          if (m < s)
            m = s;
        }
        if (exists(x[i] - dy, y[i] + dx) && exists(x[j] - dy, y[j] + dx)) {
          s = dx * dx + dy * dy;
          if (m < s)
            m = s;
        }
      }
    }

    cout << m << endl;
  }

  return 0;
}

Error: MLE

Fixed submission:

#include <iostream>
#define REP(i, a, n) for (int i = a; i < n; i++)
using namespace std;

int n;
int x[3000], y[3000];
int mp[5001][5001];
int m, dx, dy, s;

int exists(int x, int y) {
  return 0 <= x && x <= 5000 && 0 <= y && y <= 5000 && mp[x][y] == 1;
}

int main(void) {
  while (cin >> n, n != 0) {
    REP(i, 0, 5001) {
      REP(j, 0, 5001) { mp[i][j] = 0; }
    }
    REP(i, 0, n) {
      cin >> x[i] >> y[i];
      mp[x[i]][y[i]] = 1;
    }

    m = 0;
    REP(i, 0, n) {
      REP(j, i + 1, n) {
        dx = x[i] - x[j];
        dy = y[i] - y[j];

        if (exists(x[i] + dy, y[i] - dx) && exists(x[j] + dy, y[j] - dx)) {
          s = dx * dx + dy * dy;
          if (m < s)
            m = s;
        }
        if (exists(x[i] - dy, y[i] + dx) && exists(x[j] - dy, y[j] + dx)) {
          s = dx * dx + dy * dy;
          if (m < s)
            m = s;
        }
      }
    }

    cout << m << endl;
  }

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

// AOJ 0518: The Oldest Site
#include <algorithm>
#include <iostream>
using namespace std;
int n, a[3001][2], x, y, ans = 0;
bool pillar[5001][5001];
int main() {
  while (cin >> n) {
    if (n == 0)
      return 0;
    ans = 0;
    for (int i = 0; i < 5001; i++) {
      for (int j = 0; j < 5001; j++) {
        pillar[i][j] = 0;
      }
    }
    for (int i = 0; i < n; i++) {
      cin >> a[i][0] >> a[i][1];
      pillar[a[i][0]][a[i][1]] = 1;
    }
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        x = a[i][0] - a[j][0];
        y = a[i][1] - a[j][1];
        if (a[i][1] >= x && a[j][1] >= x && a[i][0] + y > 0 &&
            a[j][0] + y > 0 && a[i][1] - x < 5001 && a[j][1] - x < 5001 &&
            a[i][0] + y < 5001 && a[j][0] + y < 5001) {
          if (pillar[a[i][0] + y][a[i][1] - x] == 1 &&
              pillar[a[j][0] + y][a[j][1] - x] == 1) {
            ans = max(ans, (x + y) * (x + y) - (x * y * 2));
          }
        }
        if (a[i][0] >= y && a[j][0] >= y && a[i][1] + x > 0 &&
            a[j][1] + x > 0 && a[i][0] - y < 5001 && a[j][0] - y < 5001 &&
            a[i][1] + x < 5001 && a[j][1] + x < 5001) {
          if (pillar[a[i][0] - y][a[i][1] + x] == 1 &&
              pillar[a[j][0] - y][a[j][1] + x] == 1) {
            ans = max(ans, (x + y) * (x + y) - (x * y * 2));
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int n, a[3001][2], b[3000], x, y, ans = 0;
bool pillar[5001][5001];
int main() {
  while (cin >> n) {
    ans = 0;
    for (int i = 0; i < 5001; i++) {
      for (int j = 0; j < 5001; j++) {
        pillar[i][j] = 0;
      }
    }
    for (int i = 0; i < n; i++) {
      cin >> a[i][0] >> a[i][1];
      pillar[a[i][0]][a[i][1]] = 1;
    }
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        x = a[i][0] - a[j][0];
        y = a[i][1] - a[j][1];
        if (a[i][1] >= x && a[j][1] >= x && a[i][0] + y > 0 &&
            a[j][0] + y > 0) {
          if (pillar[a[i][0] + y][a[i][1] - x] == 1 &&
              pillar[a[j][0] + y][a[j][1] - x] == 1) {
            ans = max(ans, (x + y) * (x + y) - (x * y * 2));
          }
        }
        if (a[i][0] >= y && a[j][0] >= y && a[i][1] + x > 0 &&
            a[j][1] + x > 0) {
          if (pillar[a[i][0] - y][a[i][1] + x] == 1 &&
              pillar[a[j][0] - y][a[j][1] + x] == 1) {
            ans = max(ans, (x + y) * (x + y) - (x * y * 2));
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00441 (C++) — buggy submission, verdict: Runtime Error

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

struct P {
  int x, y;
};
bool e[5001][5001];

bool exist(int x, int y) {
  if (x < 0 || 5000 < x || y < 0 || 5000 < y)
    return false;
  return e[x][y];
}
int main() {
  int n;
  P pole[3000];
  while (cin >> n, n) {
    int ans = 0;
    memset(e, false, sizeof(e));
    for (int i = 0; i < n; i++) {
      int x, y;
      cin >> x >> y;
      pole[i].x = x;
      pole[i].y = y;
      e[x][y] = true;
    }
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        int dx, dy;
        dx = pole[i].x - pole[j].x;
        dy = pole[i].y - pole[j].y;
        if (exist(pole[i].x + dy, pole[i].y - dx) &&
                exist(pole[j].x + dy, pole[j].y - dx) ||
            exist(pole[i].x - dy, pole[i].y + dx) &&
                exist(pole[j].x - dy, pole[j].y + dx)) {
          ans = max(ans, dx * dx + dy * dy);
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

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

struct P {
  int x, y;
};
bool e[5000][5000];

bool exist(int x, int y) {
  if (x < 0 || 5000 <= x || y < 0 || 5000 <= y)
    return false;
  return e[x][y];
}
int main() {
  int n;
  P pole[3000];
  while (cin >> n, n) {
    int ans = 0;
    memset(pole, false, sizeof(pole));
    for (int i = 0; i < n; i++) {
      int x, y;
      cin >> x >> y;
      pole[i].x = x - 1;
      pole[i].y = y - 1;
      e[x - 1][y - 1] = true;
    }
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        int dx, dy;
        dx = pole[i].x - pole[j].x;
        dy = pole[i].y - pole[j].y;
        if (exist(pole[i].x + dy, pole[i].y - dx) &&
                exist(pole[j].x + dy, pole[j].y - dx) ||
            exist(pole[i].x - dy, pole[i].y + dx) &&
                exist(pole[j].x - dy, pole[j].y + dx)) {
          ans = max(ans, dx * dx + dy * dy);
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00441 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

bool a[5002][5002];

bool f(int x, int y) {
  if (x < 0 || x >= 5002 || y < 0 || y >= 5002)
    return false;
  return a[x][y];
}

int main() {
  while (1) {
    for (int i = 0; i < 5002; i++)
      for (int j = 0; j < 5002; j++)
        a[i][j] = false;
    int n, x[5002], y[5002];
    scanf("%d", &n);
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      scanf("%d%d", &x[i], &y[i]);
      a[x[i]][y[i]] = true;
    }

    int ret = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        int sx = y[i] - y[j], sy = x[j] - x[i];
        if (f(x[i] + sx, y[i] + sy) && f(x[j] + sx, y[j] + sy))
          ret = max(ret, sx * sx + sy * sy);
        else if (f(x[i] - sx, y[i] - sy) && f(x[j] - sx, y[j] - sy))
          ret = max(ret, sx * sx + sy * sy);
      }
    }

    printf("%d\\n", ret);
  }
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

bool a[3002][3002];

bool f(int x, int y) {
  if (x < 0 || x >= 3002 || y < 0 || y >= 3002)
    return false;
  return a[x][y];
}

int main() {
  while (1) {
    for (int i = 0; i < 3002; i++)
      for (int j = 0; j < 3002; j++)
        a[i][j] = false;
    int n, x[3002], y[3002];
    scanf("%d", &n);
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      scanf("%d%d", &x[i], &y[i]);
      a[x[i]][y[i]] = true;
    }

    int ret = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        int sx = y[i] - y[j], sy = x[j] - x[i];
        if (f(x[i] + sx, y[i] + sy) && f(x[j] + sx, y[j] + sy))
          ret = max(ret, sx * sx + sy * sy);
        else if (f(x[i] - sx, y[i] - sy) && f(x[j] - sx, y[j] - sy))
          ret = max(ret, sx * sx + sy * sy);
      }
    }

    printf("%d\\n", ret);
  }
}