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

#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

typedef complex<int> P;
bool G[5001][5001];
vector<P> v;

int solve() {
  int res = 0;
  for (int i = 0; i < v.size(); ++i) {
    for (int j = i + 1; j < v.size(); ++j) {
      P p1 = v[i];
      P p2 = v[j];
      P ve[2];
      ve[0] = ve[1] = p2 - p1;
      ve[0] = P(-ve[0].imag(), ve[0].real());
      ve[1] = -ve[0];
      for (int k = 0; k < 2; ++k) {
        P p1d = p1 + ve[k];
        P p2d = p2 + ve[k];
        if (p1d.real() < 0 || p1d.real() > 5000)
          continue;
        if (p1d.imag() < 0 || p1d.imag() > 5000)
          continue;
        if (p2d.real() < 0 || p2d.real() > 5000)
          continue;
        if (p2d.imag() < 0 || p2d.imag() > 5000)
          continue;
        if (G[p1d.imag()][p1d.real()] && G[p2d.imag()][p2d.real()]) {
          res = max(res,
                    ve[k].real() * ve[k].real() + ve[k].imag() * ve[k].imag());
          break;
        }
      }
    }
  }
  return res;
}

int main() {
  int n;
  while (cin >> n && n) {
    fill(G[0], G[5001], false);
    v.clear();
    for (int i = 0; i < n; ++i) {
      int x, y;
      cin >> x >> y;
      v.push_back(P(x, y));
      G[y][x] = true;
    }
    cout << solve() << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

typedef complex<int> P;
bool G[5001][5001];
vector<P> v;

int solve() {
  int res = 0;
  for (int i = 0; i < v.size(); ++i) {
    for (int j = i + 1; j < v.size(); ++j) {
      P p1 = v[i];
      P p2 = v[j];
      P ve[2];
      ve[0] = ve[1] = p2 - p1;
      ve[0] = P(-ve[0].imag(), ve[0].real());
      ve[1] = P(ve[0].imag(), -ve[0].real());
      for (int k = 0; k < 2; ++k) {
        P p1d = p1 + ve[k];
        P p2d = p2 + ve[k];
        if (p1d.real() < 0 || p1d.real() >= 5000)
          continue;
        if (p1d.imag() < 0 || p1d.imag() >= 5000)
          continue;
        if (p2d.real() < 0 || p2d.real() >= 5000)
          continue;
        if (p2d.imag() < 0 || p2d.imag() >= 5000)
          continue;
        if (G[p1d.imag()][p1d.real()] && G[p2d.imag()][p2d.real()]) {
          res = max(res,
                    ve[k].real() * ve[k].real() + ve[k].imag() * ve[k].imag());
          break;
        }
      }
    }
  }
  return res;
}

int main() {
  int n;
  while (cin >> n && n) {
    fill(G[0], G[5001], false);
    for (int i = 0; i < n; ++i) {
      int x, y;
      cin >> x >> y;
      v.push_back(P(x, y));
      G[y][x] = true;
    }
    cout << solve() << endl;
  }
  return 0;
}
Problem p00441 (C++) — buggy submission, verdict: Memory Limit Exceeded

#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <set>
#include <stdio.h>
#include <string.h>
#include <vector>

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

int n;
int ans = 0;
int pos[3333][2];
bool xy[5200][5200] = {};

int main() {

  for (;;) {
    scanf("%d", &n);
    if (!n)
      break;
    memset(xy, false, sizeof(xy));
    ans = 0;

    rep(i, n) {
      scanf("%d %d", &pos[i][0], &pos[i][1]);
      xy[pos[i][0]][pos[i][1]] = true;
    }

    for (int i = 0; i < n - 1; i++) {
      for (int j = i + 1; j < n; j++) {
        int vec[2] = {pos[i][0] - pos[j][0], pos[i][1] - pos[j][1]};
        if ((pos[i][0] + vec[1] >= 0 && pos[i][1] - vec[0] >= 0 &&
             pos[j][0] + vec[1] >= 0 && pos[j][1] - vec[0] >= 0 &&
             pos[i][0] + vec[1] < 5200 && pos[i][1] - vec[0] < 5200 &&
             pos[j][0] + vec[1] < 5200 && pos[j][1] - vec[0] < 5200 &&
             xy[pos[i][0] + vec[1]][pos[i][1] - vec[0]] &&
             xy[pos[j][0] + vec[1]][pos[j][1] - vec[0]]) ||
            (pos[i][0] - vec[1] >= 0 && pos[i][1] + vec[0] >= 0 &&
             pos[j][0] - vec[1] >= 0 && pos[j][1] + vec[0] >= 0 &&
             pos[i][0] - vec[1] < 5200 && pos[i][1] + vec[0] < 5200 &&
             pos[j][0] - vec[1] < 5200 && pos[j][1] + vec[0] < 5200 &&
             xy[pos[i][0] - vec[1]][pos[i][1] + vec[0]] &&
             xy[pos[j][0] - vec[1]][pos[j][1] + vec[0]]))
          ans = max(ans, vec[0] * vec[0] + vec[1] * vec[1]);
      }
    }

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

  return 0;
}

Error: MLE

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <set>
#include <stdio.h>
#include <string.h>
#include <vector>

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

int n;
int ans = 0;
int pos[3333][2];
bool xy[10003][10003] = {};

int main() {

  for (;;) {
    scanf("%d", &n);
    if (!n)
      break;
    memset(xy, false, sizeof(xy));
    ans = 0;

    rep(i, n) {
      scanf("%d %d", &pos[i][0], &pos[i][1]);
      xy[pos[i][0]][pos[i][1]] = true;
    }

    for (int i = 0; i < n - 1; i++) {
      for (int j = i + 1; j < n; j++) {
        int vec[2] = {pos[i][0] - pos[j][0], pos[i][1] - pos[j][1]};
        if ((pos[i][0] + vec[1] >= 0 && pos[i][1] - vec[0] >= 0 &&
             pos[j][0] + vec[1] >= 0 && pos[j][1] - vec[0] >= 0 &&
             xy[pos[i][0] + vec[1]][pos[i][1] - vec[0]] &&
             xy[pos[j][0] + vec[1]][pos[j][1] - vec[0]]) ||
            (pos[i][0] - vec[1] >= 0 && pos[i][1] + vec[0] >= 0 &&
             pos[j][0] - vec[1] >= 0 && pos[j][1] + vec[0] >= 0 &&
             xy[pos[i][0] - vec[1]][pos[i][1] + vec[0]] &&
             xy[pos[j][0] - vec[1]][pos[j][1] + vec[0]]))
          ans = max(ans, vec[0] * vec[0] + vec[1] * vec[1]);
      }
    }

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

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

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

typedef long long ll;
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define each(itr, c)                                                           \\
  for (__typeof(c.begin()) itr = c.begin(); itr != c.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

typedef pair<int, int> pi;

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

int main() {
  int n;
  while (cin >> n, n) {
    set<pi> p;

    vector<pi> v(n);
    rep(i, n) {
      scanf(" %d %d", &v[i].fi, &v[i].se);
      p.insert(v[i]);
    }

    sort(all(v));

    int ans = 0;

    // 2???????????¶
    rep(i, n) rep(j, i) {
      int dx = v[i].fi - v[j].fi;
      int dy = v[i].se - v[j].se;

      int p1x = v[j].fi - dy, p1y = v[j].se + dx;
      int p2x = v[i].fi - dy, p2y = v[i].se + dx;
      if (in(p1x, p1y) && in(p2x, p2y)) {
        if (p.find(pi(p1x, p1y)) != p.end() && p.find(pi(p2x, p2y)) != p.end())
          ans = max(ans, dx * dx + dy * dy);
      }

      int q1x = v[j].fi + dy, q1y = v[j].se - dx;
      int q2x = v[i].fi + dy, q2y = v[i].se - dx;
      if (in(q1x, q1y) && in(q2x, q2y)) {
        if (p.find(pi(q1x, q1y)) != p.end() && p.find(pi(q2x, q2y)) != p.end())
          ans = max(ans, dx * dx + dy * dy);
      }
    }

    cout << ans << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

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

typedef long long ll;
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define each(itr, c)                                                           \\
  for (__typeof(c.begin()) itr = c.begin(); itr != c.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

typedef pair<int, int> pi;

int p[5001][5001];

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

int main() {
  int n;
  while (cin >> n, n) {
    // initialize
    memset(p, 0, sizeof(p));

    vector<pi> v(n);
    rep(i, n) {
      scanf(" %d %d", &v[i].fi, &v[i].se);
      p[v[i].fi][v[i].se] = 1;
    }

    sort(all(v));

    int ans = 0;

    // 2???????????¶
    rep(i, n) rep(j, i) {
      int dx = v[i].fi - v[j].fi;
      int dy = v[i].se - v[j].se;

      int p1x = v[j].fi - dy, p1y = v[j].se + dx;
      int p2x = v[i].fi - dy, p2y = v[i].se + dx;
      if (in(p1x, p1y) && in(p2x, p2y)) {
        if (p[p1x][p1y] && p[p2x][p2y])
          ans = max(ans, dx * dx + dy * dy);
      }

      int q1x = v[j].fi + dy, q1y = v[j].se - dx;
      int q2x = v[i].fi + dy, q2y = v[i].se - dx;
      if (in(q1x, q1y) && in(q2x, q2y)) {
        if (p[q1x][q1y] && p[q2x][q2y])
          ans = max(ans, dx * dx + dy * dy);
      }
    }

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

#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rep3(i, s, n) for (int i = int(s); i < int(n); i++)
#define rev_rep(i, n) for (int i = int(n) - 1; i >= 0; i -= 1)

int N;
int x[3100];
int y[3100];
bool map[5100][5100];
int m(int x, int y) {
  if (x < 0 || y < 0 || x > 5000 || y > 5000)
    return false;
  return map[x][y];
}
int main() {
  while (cin >> N) {
    if (N == 0)
      break;
    rep(i, 5100) {
      rep(j, 5100) { map[i][j] = false; }
    }
    rep(i, N) {
      cin >> x[i] >> y[i];
      map[x[i]][y[i]] = true;
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
      for (int j = i + 1; j < N; j++) {
        int xd = x[j] - x[i];
        int yd = y[j] - y[i];
        int t = xd * xd + yd * yd;
        if ((m(x[i] + yd, y[i] - xd) && m(x[j] + yd, y[j] - xd)) ||
            (m(x[i] - yd, y[i] + xd) && m(x[j] - yd, y[j] + xd))) {
          ans = max(ans, t);
        }
      }
    }
    cout << ans << "\\n";
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rep3(i, s, n) for (int i = int(s); i < int(n); i++)
#define rev_rep(i, n) for (int i = int(n) - 1; i >= 0; i -= 1)

int N;
int x[3100];
int y[3100];
bool map[5100][5100];

int main() {
  while (cin >> N) {
    if (N == 0)
      break;
    rep(i, 5100) {
      rep(j, 5100) { map[i][j] = false; }
    }
    rep(i, N) {
      cin >> x[i] >> y[i];
      map[x[i]][y[i]] = true;
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
      for (int j = i + 1; j < N; j++) {
        int xd = x[j] - x[i];
        int yd = y[j] - y[i];
        int t = xd * xd + yd * yd;
        if ((map[x[i] + yd][y[i] - xd] && map[x[j] + yd][y[j] - xd]) ||
            (map[x[i] - yd][y[i] + xd] && map[x[j] - yd][y[j] + xd])) {
          ans = max(ans, t);
        }
      }
    }
    cout << ans << "\\n";
  }
  return 0;
}
Problem p00441 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <set>

using namespace std;

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

#define f first
#define s second
int main() {
  while (1) {
    int n;
    cin >> n;
    if (n == 0)
      break;
    pair<int, int> t[3333];

    rep(i, n) {
      int a, b;
      cin >> a >> b;
      t[i].f = a;
      t[i].s = b;
    }

    sort(t, t + n);

    int ans = 0;

    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        int dx = t[j].f - t[i].f;
        int dy = t[j].s - t[i].s;
        int flg = 1;
        int flg2 = 0;
        /*
        printf("%d %d\\n",i,j);
        printf("%d,%d %d,%d %d,%d\\n",t[i].f,t[i].s,t[j].f,t[j].s,dx,dy);*/
        if (binary_search(t, t + n, make_pair(t[j].f - dy, t[j].s + dx)) == 0) {
          flg = 0;
        }
        if (flg == 1 &&
            binary_search(t, t + n, make_pair(t[i].f - dy, t[i].s + dx)) == 0) {
          flg = 0;
        }
        /*
        if(binary_search(t,t+n,make_pair(t[j].f+dy,t[j].s-dx))==0){
                flg2=0;
        }
        if(flg2==1 && binary_search(t,t+n,make_pair(t[i].f+dy,t[i].s-dx))==0){
                flg2=0;
        }*/

        if (flg == 1 || flg2 == 1) {
          ans = max(ans, dx * dx + dy * dy);
        }
      }
    }
    printf("%d\\n", ans);
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <set>

using namespace std;

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

#define f first
#define s second
int main() {
  while (1) {
    int n;
    cin >> n;
    if (n == 0)
      break;
    pair<int, int> t[3333];

    rep(i, n) {
      int a, b;
      cin >> a >> b;
      t[i].f = a;
      t[i].s = b;
    }

    sort(t, t + n);

    int ans = 0;

    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        int dx = t[j].f - t[i].f;
        int dy = t[j].s - t[i].s;
        int flg = 1;
        int flg2 = 1;
        /*
        printf("%d %d\\n",i,j);
        printf("%d,%d %d,%d %d,%d\\n",t[i].f,t[i].s,t[j].f,t[j].s,dx,dy);*/
        if (binary_search(t, t + n, make_pair(t[j].f - dy, t[j].s + dx)) == 0) {
          flg = 0;
        }
        if (binary_search(t, t + n, make_pair(t[i].f - dy, t[i].s + dx)) == 0) {
          flg = 0;
        }

        if (binary_search(t, t + n, make_pair(t[j].f + dy, t[j].s - dx)) == 0) {
          flg2 = 0;
        }
        if (binary_search(t, t + n, make_pair(t[j].f + dy, t[j].s - dx)) == 0) {
          flg2 = 0;
        }

        if (flg == 1 || flg2 == 1) {
          ans = max(ans, dx * dx + dy * dy);
        }
      }
    }
    printf("%d\\n", ans);
  }
}
Problem p00441 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c)                                                              \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1 << 29;

typedef pair<int, int> pii;
#define F first
#define S second
int main() {
  int n;
  while (cin >> n, n) {
    set<pii> se;
    REP(i, n) {
      int x, y;
      cin >> x >> y;
      se.insert(pii(x, y));
    }
    int res = 0;
    FOR(it, se) {
      FOR(jt, se) {
        int vx = it->F - jt->F;
        int vy = it->S - jt->S;
        int s = vx * vx + vy * vy;
        if (s <= res)
          continue;
        if (se.count(pii(it->F - vy, it->S + vx)) &&
            se.count(pii(jt->F - vy, jt->S + vx)))
          res = s;
      }
    }
    cout << res << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c)                                                              \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1 << 29;

typedef pair<int, int> pii;
#define F first
#define S second
int main() {
  int n;
  while (cin >> n, n) {
    map<pii, bool> mp;
    vector<pii> v(n);
    REP(i, n) {
      int x, y;
      cin >> x >> y;
      v[i] = pii(x, y);
      mp[v[i]] = true;
    }
    int res = 0;
    REP(i, n) {
      for (int j = i + 1; j < n; ++j) {
        int vx = v[i].F - v[j].F;
        int vy = v[i].S - v[j].S;
        int s = vx * vx + vy * vy;
        if (s <= res)
          continue;
        if (mp[pii(v[i].F - vy, v[i].S + vx)] &&
            mp[pii(v[j].F - vy, v[j].S + vx)]) {
          res = max(res, s);
        }
      }
    }
    cout << res << endl;
  }
}
Problem p00441 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>

struct loc {
  int x, y;
};

bool map[5001][5001];
loc pillar[3000];

bool ju(int a) {
  if (0 <= a && a <= 5000)
    return true;
  else
    return false;
}

int main() {
  while (true) {
    int n;
    std::cin >> n;
    if (!n)
      break;
    loc max = {0, 0};
    memset(map, false, sizeof map);
    for (int i = 0; i < n; i++) {
      std::cin >> pillar[i].x >> pillar[i].y;
      map[pillar[i].x][pillar[i].y] = true;
    }

    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        loc vec = {pillar[i].x - pillar[j].x, pillar[i].y - pillar[j].y};

        loc p1 = {pillar[i].x - vec.y, pillar[i].y + vec.x};
        loc p2 = {pillar[j].x - vec.y, pillar[j].y + vec.x};
        loc p3 = {pillar[i].x + vec.y, pillar[i].y - vec.x};
        loc p4 = {pillar[j].x + vec.y, pillar[j].y - vec.x};

        if (ju(p1.x) && ju(p1.y) && ju(p2.x) && ju(p2.y) && map[p1.x][p1.y] &&
            map[p2.x][p2.y]) {
          if (max.x * max.x + max.y * max.y < vec.x * vec.x + vec.y * vec.y) {
            max = {vec.x, vec.y};
          }

        } else if (ju(p3.x) && ju(p3.y) && ju(p4.x) && ju(p4.y) &&
                   map[p3.x][p3.y] && map[p4.x][p4.y]) {
          if (max.x * max.x + max.y * max.y < vec.x * vec.x + vec.y * vec.y) {
            max = {vec.x, vec.y};
          }
        }
      }
    }
    std::cout << (max.x + max.y) * (max.x + max.y) - 2 * max.x * max.y
              << std::endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cstring>
#include <iostream>

struct loc {
  int x, y;
};

bool map[5001][5001];
loc pillar[1000];

int main() {
  while (true) {
    int n;
    std::cin >> n;
    if (!n)
      break;
    loc max = {0, 0};
    memset(map, false, sizeof map);
    for (int i = 0; i < n; i++) {
      std::cin >> pillar[i].x >> pillar[i].y;
      map[pillar[i].x][pillar[i].y] = true;
    }

    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        loc vec = {pillar[i].x - pillar[j].x, pillar[i].y - pillar[j].y};

        loc p1 = {pillar[i].x - vec.y, pillar[i].y + vec.x};
        loc p2 = {pillar[j].x - vec.y, pillar[j].y + vec.x};
        loc p3 = {pillar[i].x + vec.y, pillar[i].y - vec.x};
        loc p4 = {pillar[j].x + vec.y, pillar[j].y - vec.x};

        if (p1.x >= 0 && p1.y >= 0 && p2.x >= 0 && p2.y >= 0 &&
            map[p1.x][p1.y] && map[p2.x][p2.y]) {
          if (max.x * max.x + max.y * max.y < vec.x * vec.x + vec.y * vec.y) {
            max = {vec.x, vec.y};
          }

        } else if (p3.x >= 0 && p3.y >= 0 && p4.x >= 0 && p4.y >= 0 &&
                   map[p3.x][p3.y] && map[p4.x][p4.y]) {
          if (max.x * max.x + max.y * max.y < vec.x * vec.x + vec.y * vec.y) {
            max = {vec.x, vec.y};
          }
        }
      }
    }
    std::cout << (max.x + max.y) * (max.x + max.y) - 2 * max.x * max.y
              << std::endl;
  }
  return 0;
}
Problem p00441 (C++) — buggy submission, verdict: Runtime Error

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

bool p[5000 + 1][5000 + 1];
int x[3000], y[3000];

int main() {
  int n;
  while (~scanf("%d", &n)) {
    if (n == 0)
      break;

    memset(p, false, sizeof(p));
    for (int i = 0; i < n; ++i) {
      scanf("%d %d", &x[i], &y[i]);
      p[y[i]][x[i]] = true;
    }

    int ans = 0;
    for (int i = 0; i < n; ++i) {
      for (int j = i + 1; j < n; ++j) {
        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 (x1 < 0 || 5000 < x1 || y1 < 0 || 5000 < y1 || x2 < 0 || 5000 < x2 ||
            y2 < 0 || 5000 < y2)
          continue;

        if (p[y1][x1] && p[y2][x2])
          ans = std::max(ans, dx * dx + dy * dy);
      }
    }

    printf("%d\\n", ans);
  }
  return 0;
}

Error: 0

Fixed submission:

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

bool p[5000 + 1][5000 + 1];
int x[3000], y[3000];

int main() {
  int n;
  while (~scanf("%d", &n)) {
    if (n == 0)
      break;

    memset(p, false, sizeof(p));
    for (int i = 0; i < n; ++i) {
      scanf("%d %d", &x[i], &y[i]);
      p[y[i]][x[i]] = true;
    }

    int ans = 0;
    for (int i = 0; i < n; ++i) {
      for (int j = i + 1; j < n; ++j) {
        int dx = abs(x[i] - x[j]);
        int dy = abs(y[i] - y[j]);

        int x1 = x[i] + dy, y1 = y[i] + dx;
        int x2 = x[j] + dy, y2 = y[j] + dy;

        if (p[y1][x1] && p[y2][x2])
          ans = std::max(ans, dx * dx + dy * dy);
      }
    }

    printf("%d\\n", ans);
  }
  return 0;
}
Problem p00441 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define PB push_back
typedef pair<int, int> pii;
static const int INF = 1LL << 61;

inline bool isRange(pii &p1) {
  return 0 <= p1.first && p1.first <= 5000 && 0 <= p1.second &&
         p1.second <= 5000;
}

inline double dis(pii &p1, pii &p2) {
  double a = abs(p1.first - p2.first), b = abs(p1.second - p2.second);
  return sqrt(a * a + b * b);
}

bool exist[5005][5005] = {false};

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

  int n;

  while (cin >> n, n) {
    pii ps[3005];
    fill(exist[0], exist[5005], false);
    for (int i = 0; i < n; ++i) {
      int x, y;
      cin >> x >> y;
      ps[i] = pii(x, y);
      exist[x][y] = true;
    }
    sort(ps, ps + n);

    int res = 0;
    for (int i = 0; i < n; ++i) {
      for (int j = i + 1; j < n; ++j) {
        if (i == j)
          continue;
        for (int k = -1; k < 2; k += 2) {
          int dx = k * abs(ps[i].second - ps[j].second),
              dy = k * abs(ps[i].first - ps[j].first);
          pii temp[2] = {pii(ps[i].first + dx, ps[i].second + dy),
                         pii(ps[j].first + dx, ps[j].second + dy)};

          if (!isRange(temp[0]) || !isRange(temp[1]) ||
              !exist[temp[0].first][temp[0].second] ||
              !exist[temp[1].first][temp[1].second])
            continue;

          double seg = dis(ps[i], ps[j]);
          res = max(res, (long long)(seg * seg + 0.00000001));
        }
      }
    }

    cout << res << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define PB push_back
typedef pair<int, int> pii;
static const int INF = 1LL << 61;

inline bool isRange(pii &p1) { return 0 <= p1.first && p1.second <= 5000; }

inline double dis(pii &p1, pii &p2) {
  double a = abs(p1.first - p2.first), b = abs(p1.second - p2.second);
  return sqrt(a * a + b * b);
}

bool exist[5005][5005] = {false};

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

  int n;

  while (cin >> n, n) {
    pii ps[3005];
    fill(exist[0], exist[5005], false);
    for (int i = 0; i < n; ++i) {
      int x, y;
      cin >> x >> y;
      ps[i] = pii(x, y);
      exist[x][y] = true;
    }
    sort(ps, ps + n);

    int res = 0;
    for (int i = 0; i < n; ++i) {
      for (int j = i + 1; j < n; ++j) {
        if (i == j)
          continue;
        for (int k = -1; k < 2; k += 2) {
          int dx = k * abs(ps[i].second - ps[j].second),
              dy = k * abs(ps[i].first - ps[j].first);
          pii temp[2] = {pii(ps[i].first + dx, ps[i].second + dy),
                         pii(ps[j].first + dx, ps[j].second + dy)};

          if (!isRange(temp[0]) || !isRange(temp[1]) ||
              !exist[temp[0].first][temp[0].second] ||
              !exist[temp[1].first][temp[1].second])
            continue;

          double seg = dis(ps[i], ps[j]);
          res = max(res, (long long)(seg * seg + 0.00000001));
        }
      }
    }

    cout << res << endl;
  }

  return 0;
}