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

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

typedef pair<int, int> P;

typedef struct {
  int x, y;
} Point;

int dist(P a) { return a.first * a.first + a.second * a.second; }

int main() {
  int n;

  while (cin >> n, n) {
    Point a;
    vector<P> v;

    for (int i = 0; i < n; i++) {
      cin >> a.x >> a.y;
      v.push_back(P(a.x, a.y));
    }

    sort(v.begin(), v.end());

    int ans = 0;

    for (int i = 0; i < n - 1; i++) {
      for (int j = i + 1; j < n; j++) {
        P b, c, d;

        b.first = v[i].first - v[j].first;
        b.second = v[i].second - v[j].second;

        c.first = v[i].first - b.second;
        c.second = v[i].second + b.first;
        d.first = v[j].first - b.second;
        d.second = v[j].second + b.first;

        if (binary_search(v.begin(), v.end(), c) &&
            binary_search(v.begin(), v.end(), d)) {
          ans = max(ans, dist(b));
        }
      }
    }
    cout << ans << endl;
  }

  return 0;
}

Error: MLE

Fixed submission:

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

typedef pair<int, int> Q;
typedef pair<double, Q> P;

#define EPS (1e-10)
#define equal(a, b) (fabs((a) - (b)) < EPS)

class Point {
public:
  double x, y;

  Point(double x = 0, double y = 0) : x(x), y(y) {}

  Point operator+(Point p) { return Point(x + p.x, y + p.y); }
  Point operator-(Point p) { return Point(x - p.x, y - p.y); }
  Point operator*(double a) { return Point(a * x, a * y); }

  double abs() { return sqrt(norm()); }
  double norm() { return x * x + y * y; }

  bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; }

  bool operator==(const Point &p) const {
    return equal(x, p.x) && equal(y, p.y);
  }
};

double dist(Point a, Point b) {
  return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}

int main() {
  int n;

  while (cin >> n, n) {
    Point a[n];
    vector<P> v;

    for (int i = 0; i < n; i++) {
      cin >> a[i].x >> a[i].y;
    }

    for (int i = 0; i < n - 1; i++) {
      for (int j = i + 1; j < n; j++) {
        v.push_back(P(dist(a[i], a[j]), Q(i, j)));
      }
    }

    sort(v.begin(), v.end());

    map<int, int> mp;
    int ans = 0;
    for (int i = 0; i < n - 1; i++) {
      for (int j = i + 1; j < n; j++) {
        double len = dist(a[i], a[j]);

        int left = 0;
        int right = v.size() - 1;

        while (right - left > 1) {
          int mid = (left + right) / 2;

          if (v[mid].first == len) {
            if (v[mid].second.first == i && v[mid].second.second == j) {
              break;
            } else {
              mp[len * len]++;
              break;
            }
          } else if (v[mid].first > len) {
            right = mid;
          } else
            left = mid;
        }
      }
    }
    for (map<int, int>::iterator it = mp.begin(); it != mp.end(); it++) {
      if (it->second >= 4) {
        int size = it->first;
        ans = max(ans, size);
      }
    }

    cout << ans << endl;
  }

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

#include <algorithm>
#include <iostream>
using namespace std;
bool p[5001][5001];
int x[3000], y[3000], n, maxn;
int main() {
  while (true) {
    cin >> n;
    maxn = 0;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> x[i] >> y[i];
      p[x[i]][y[i]] = true;
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (i == j)
          continue;
        int X1 = x[j] - x[i], Y1 = y[j] - y[i];
        int X2 = -Y1, Y2 = X1;
        int X3 = X1 - Y1, Y3 = X1 + Y1;
        int X4 = X2 + x[i], Y4 = Y2 + y[i];
        int X5 = X3 + x[i], Y5 = Y3 + y[i];
        if (X4 < 0 || X4 > 5000 || Y4 < 0 || Y4 > 5000 || X5 < 0 || X5 > 5000 ||
            Y5 < 0 || Y5 > 5000)
          continue;
        if (p[X4][Y4] == true && p[X5][Y5] == true) {
          maxn = max(maxn, X1 * X1 + Y1 * Y1);
        }
      }
    }
    cout << maxn << endl;
    for (int i = 0; i < n; i++) {
      p[x[i]][y[i]] = true;
    }
  }
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
bool p[5001][5001];
int x[3000], y[3000], n, maxn;
int main() {
  while (true) {
    cin >> n;
    maxn = 0;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> x[i] >> y[i];
      p[x[i]][y[i]] = true;
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (i == j)
          continue;
        int X1 = x[j] - x[i], Y1 = y[j] - y[i];
        int X2 = -Y1, Y2 = X1;
        int X3 = X1 - Y1, Y3 = X1 + Y1;
        if (p[X2 + x[i]][Y2 + y[i]] == true &&
            p[X3 + x[i]][Y3 + y[i]] == true) {
          maxn = max(maxn, X1 * X1 + Y1 * Y1);
        }
      }
    }
    cout << maxn << endl;
    for (int i = 0; i < n; i++) {
      p[x[i]][y[i]] = true;
    }
  }
  return 0;
}
Problem p00441 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int n;
int x[5000], y[5000], maxn;
bool p[7000][7000];
int Ax, Ay, Bx, By, Cx, Cy, Dx, Dy;

int main() {
  while (true) {
    memset(p, false, sizeof(p));
    cin >> n;
    maxn = 0;
    if (n == 0) {
      break;
    }
    for (int i = 0; i < n; i++) {
      cin >> 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++) {
        Ax = x[i];
        Bx = x[j];
        Ay = y[i];
        By = y[j];
        Cx = Ax - (By - Ay);
        Cy = Ay + (Bx - Ax);
        Dx = Bx - (By - Ay);
        Dy = By + (Bx - Ax);
        if (Cx >= 0 && Cy >= 0 && Dx >= 0 && Dy >= 0 && Cx <= 5000 &&
            Cy <= 5000 && Dx <= 5000 && Dy <= 5000) {
          if (p[Cx][Cy] == true && p[Dx][Dy] == true) {
            maxn = max(maxn, (Ax - Bx) * (Ax - Bx) + (Ay - By) * (Ay - By));
          }
        }
      }
    }
    cout << maxn << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int n;
int x[100], y[100], A, B, C, D, maxn;

int main() {
  while (true) {
    maxn = 0;
    cin >> n;
    if (n == 0) {
      break;
    }
    for (int i = 0; i < n; i++) {
      cin >> x[i] >> y[i];
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        for (int k = 0; k < n; k++) {
          for (int l = 0; l < n; l++) {
            if (i != j && j != k && k != l && l != i && i != k && j != l) {
              A = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);
              B = (x[i] - x[l]) * (x[i] - x[l]) + (y[i] - y[l]) * (y[i] - y[l]);
              C = (x[k] - x[j]) * (x[k] - x[j]) + (y[k] - y[j]) * (y[k] - y[j]);
              D = (x[k] - x[l]) * (x[k] - x[l]) + (y[k] - y[l]) * (y[k] - y[l]);
              if (A == B && B == C && C == D && D == A) {
                maxn = max(maxn, A);
              }
            }
          }
        }
      }
    }
    cout << maxn << endl;
  }
  return 0;
}
Problem p00441 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>
#pragma warning(disable : 4996)
using namespace std;
int n, x[3009], y[3009];
bool ok[5009][5009];
int main() {
  while (scanf("%d", &n), n) {
    for (int i = 0; i < n; i++) {
      scanf("%d%d", &x[i], &y[i]);
      ok[x[i]][y[i]] = true;
    }
    int ret = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        int va = x[j] - x[i], vb = y[j] - y[i];
        int ex = x[i] + vb, ey = y[i] - va;
        int fx = x[j] + vb, fy = y[j] - va;
        if (0 <= ex && ex <= 5000 && 0 <= ey && ey <= 5000 && 0 <= fx &&
            fx <= 5000 && 0 <= fy && fy <= 5000 && ok[ex][ey] && ok[fx][fy]) {
          ret = max(ret, va * va + vb * vb);
        }
      }
    }
    printf("%d\\n", ret);
    for (int i = 0; i < n; i++)
      ok[x[i]][y[i]] = false;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
#pragma warning(disable : 4996)
using namespace std;
int n, x[3009], y[3009];
bool ok[5009][5009];
int main() {
  while (scanf("%d", &n), n) {
    for (int i = 0; i < n; i++) {
      scanf("%d%d", &x[i], &y[i]);
      ok[x[i]][y[i]] = true;
    }
    int ret = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        int va = x[j] - x[i], vb = y[j] - y[i];
        int ex = x[i] + vb, ey = y[i] - va;
        int fx = x[j] + vb, fy = y[j] - va;
        if (0 <= ex && ex <= 5000 && 0 <= fy && fy <= 5000 && ok[ex][ey] &&
            ok[fx][fy]) {
          ret = max(ret, va * va + vb * vb);
        }
      }
    }
    printf("%d\\n", ret);
    for (int i = 0; i < n; i++)
      ok[x[i]][y[i]] = false;
  }
  return 0;
}
Problem p00441 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
#include <map>
#include <set>

using namespace std;

typedef pair<int, int> P;
typedef set<P> S;
typedef S::iterator I;

int main() {
  int n;
  P p;
  while (true) {
    S points;
    int max_square = 0;
    cin >> n;
    if (n == 0) {
      return 0;
    }
    for (int i = 0; i < n; ++i) {
      cin >> p.first >> p.second;
      points.insert(p);
    }
    for (I i1 = points.begin(); i1 != points.end(); ++i1) {
      for (I i2 = points.begin(); i2 != points.end(); ++i2) {
        P dp1(i2->first - i1->first, i2->second - i1->second);
        P dp2(i1->first - i2->first, i1->second - i2->second);
        P p3(-dp1.second + i1->first, dp1.first + i1->second);
        P p4(dp2.second + i2->first, -dp2.first + i2->second);
        int square = dp1.first * dp1.first + dp1.second * dp1.second;
        if (square < max_square) {
          continue;
        }
        if (points.find(p3) != points.end() &&
            points.find(p4) != points.end()) {
          max_square = square;
        }
      }
    }
    cout << max_square << endl;
  }
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
#include <map>
#include <set>

using namespace std;

typedef pair<int, int> P;
typedef set<P> S;
typedef S::iterator I;

int main() {
  int n;
  int max_square = 0;
  P p;
  S points;
  while (true) {
    cin >> n;
    if (n == 0) {
      return 0;
    }
    for (int i = 0; i < n; ++i) {
      cin >> p.first >> p.second;
      points.insert(p);
    }
    for (I i1 = points.begin(); i1 != points.end(); ++i1) {
      for (I i2 = points.begin(); i2 != points.end(); ++i2) {
        P dp1(i2->first - i1->first, i2->second - i1->second);
        P dp2(i1->first - i2->first, i1->second - i2->second);
        P p3(-dp1.second + i1->first, dp1.first + i1->second);
        P p4(dp2.second + i2->first, -dp2.first + i2->second);
        if (points.find(p3) != points.end() &&
            points.find(p4) != points.end()) {
          max_square =
              max(max_square, dp1.first * dp1.first + dp1.second * dp1.second);
        }
      }
    }
    cout << max_square << endl;
  }
}
Problem p00441 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
typedef pair<int, int> P;
P p[3000];
int n;
int ans;
int main() {
  while (cin >> n && n) {
    ans = 0;
    for (int i = 0; i < n; i++)
      scanf("%d %d", &p[i].first, &p[i].second);
    sort(p, p + n);
    for (int i = 0; i + 1 < n; i++) {
      for (int j = i + 1; j < n; j++) {
        P a = p[i], b = p[j], c, d;
        c.first = a.first + a.second - b.second;
        c.second = a.second + b.first - a.first;
        d.first = b.first + a.second - b.second;
        d.second = b.second + b.first - a.first;
        if (binary_search(p, p + n, c) == false)
          continue;
        if (binary_search(p, p + n, d) == false)
          continue;
        int d1 = (a.first - b.first);
        int d2 = (a.second - b.second);
        int d3 = d1 * d1 + d2 * d2;
        ans = max(ans, d3);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <iostream>
#include <map>
using namespace std;
typedef pair<int, int> P;
map<P, bool> t;
P p[3000];
int n;
int ans;
int main() {
  while (cin >> n && n) {
    t.clear();
    ans = 0;
    for (int i = 0; i < n; i++) {
      cin >> p[i].first >> p[i].second;
      t[p[i]] = true;
    }
    for (int i = 0; i + 1 < n; i++) {
      for (int j = i + 1; j < n; j++) {
        P a = p[i], b = p[j], c, d;
        c.first = a.first + a.second - b.second;
        c.second = a.second + b.first - a.first;
        d.first = b.first + a.second - b.second;
        d.second = b.second + b.first - a.first;
        if (!t[c] || !t[d])
          continue;
        int d1 = (a.first - b.first);
        int d2 = (a.second - b.second);
        int d3 = d1 * d1 + d2 * d2;
        ans = max(ans, d3);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00441 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>
using namespace std;
bool p[5001][5001];
int main() {
  int n, a;
  while (cin >> n, n) {
    int x[3000] = {0};
    int y[3000] = {0};
    memset(p, 0, sizeof(p));
    for (int i = 0; i < n; ++i) {
      cin >> x[i] >> y[i];
      p[y[i]][x[i]] = true;
    }
    a = 0;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        int dx = x[i] - x[j], dy = y[i] - y[j];
        if (y[i] - dx >= 0 && y[i] - dx <= 5000 && x[i] + dy >= 0 &&
            x[i] + dy <= 5000 && y[j] - dx >= 0 && y[j] - dx <= 5000 &&
            x[j] + dy >= 0 && x[j] + dy <= 500 && p[y[i] - dx][x[i] + dy] &&
            p[y[j] - dx][x[j] + dy])
          a = max(a, dx * dx + dy * dy);
        else if (y[i] + dx >= 0 && y[i] + dx <= 5000 && x[i] - dy >= 0 &&
                 x[i] - dy <= 5000 && y[j] + dx >= 0 && y[j] + dx <= 5000 &&
                 x[j] - dy >= 0 && x[j] - dy <= 5000 &&
                 p[y[i] + dx][x[i] - dy] && p[y[j] + dx][x[j] - dy])
          a = max(a, dx * dx + dy * dy);
      }
    }
    cout << a << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cstring>
#include <iostream>
using namespace std;
bool p[5001][5001];
int main() {
  int n, a;
  while (cin >> n, n) {
    int x[3000] = {0};
    int y[3000] = {0};
    memset(p, 0, sizeof(p));
    for (int i = 0; i < n; ++i) {
      cin >> x[i] >> y[i];
      p[y[i]][x[i]] = true;
    }
    a = 0;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        int dx = x[i] - x[j], dy = y[i] - y[j];
        if (y[i] - dx >= 0 && y[i] - dx <= 5000 && x[i] + dy >= 0 &&
            x[i] + dy <= 5000 && p[y[i] - dx][x[i] + dy] &&
            p[y[j] - dx][x[j] + dy])
          a = max(a, dx * dx + dy * dy);
        else if (y[i] + dx >= 0 && y[i] + dx <= 5000 && x[i] - dy >= 0 &&
                 x[i] - dy <= 5000 && p[y[i] + dx][x[i] - dy] &&
                 p[y[j] + dx][x[j] - dy])
          a = max(a, dx * dx + dy * dy);
      }
    }
    cout << a << endl;
  }
  return 0;
}
Problem p00441 (C++) — buggy submission, verdict: Runtime Error

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

struct coordinates {
  int x, y;
};

bool stage[5001][5001] = {};

int latte(coordinates a_c, coordinates b_c) {
  coordinates diff, np, a = a_c, b = b_c;
  int situ, s;
  bool flag = true;
  np = b;
  diff.x = b.x - a.x;
  diff.y = b.y - a.y;
  s = (diff.x * diff.x + diff.y * diff.y) + 0.1;
  // printf("1:%d,%d 2:%d,%d ",a.x,a.y,b.x,b.y);
  for (int i = 3; i <= 4; i++, situ++) {
    swap(diff.x, diff.y);
    diff.y *= -1;
    b.x += diff.x;
    b.y += diff.y;
    // printf("%d:%d,%d ",i,b.x,b.y);
    if (b.x < 0 || 5000 < b.x || b.y < 0 || 5000 < b.y || !stage[b.x][b.y]) {
      flag = false;
      break;
    }
  } // puts("");
  if (flag) {
    // printf("%d,%d %d,%d\\n",diff.x,diff.y,a.x,a.y);
    return s;
  }
  return 0;
}

int main() {
  int N;
  while (cin >> N, N) {
    for (int i = 0; i <= 5000; i++)
      for (int j = 0; j <= 5000; j++)
        stage[i][j] = false;

    int ans = 0;
    coordinates pole[3001];
    for (int i = 0; i < N; i++) {
      cin >> pole[i].x >> pole[i].y;
      stage[pole[i].x][pole[i].y] = true;
    }
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        if (i != j) {
          ans = max(ans, latte(pole[i], pole[j]));
        }
      }
    }
    printf("%d\\n", ans);
  }
  return 0;
}

Error: -11

Fixed submission:

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

struct coordinates {
  int x, y;
};
bool stage[5001][5001];

int latte(coordinates a_c, coordinates b_c) {
  coordinates diff, np, a = a_c, b = b_c;
  int situ, s;
  bool flag = true;
  np = b;
  diff.x = b.x - a.x;
  diff.y = b.y - a.y;
  s = (diff.x * diff.x + diff.y * diff.y) + 0.1;
  // printf("1:%d,%d 2:%d,%d ",a.x,a.y,b.x,b.y);
  for (int i = 3; i <= 4; i++, situ++) {
    swap(diff.x, diff.y);
    diff.y *= -1;
    b.x += diff.x;
    b.y += diff.y;
    // printf("%d:%d,%d ",i,b.x,b.y);
    if (!stage[b.x][b.y]) {
      flag = false;
      break;
    }
  } // puts("");
  if (flag) {
    // printf("%d,%d %d,%d\\n",diff.x,diff.y,a.x,a.y);
    return s;
  }
  return 0;
}

int main() {
  int N, ans = 0;
  coordinates pole[3000];
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> pole[i].x >> pole[i].y;
    stage[pole[i].x][pole[i].y] = true;
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (i != j) {
        ans = max(ans, latte(pole[i], pole[j]));
      }
    }
  }
  printf("%d\\n", ans);
  return 0;
}
Problem p00441 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define f first
#define s second
#define rep(i, x) for (int i = 0; i < x; i++)
P za[3005];
int main() {
  srand((unsigned int)time(NULL));
  while (1) {
    int n;
    scanf("%d", &n);
    if (!n)
      return 0;
    static bool in[5005][5005] = {};
    for (int i = 1; i <= n; i++) {
      scanf("%d %d", &za[i].f, &za[i].s);
      in[za[i].f][za[i].s] = true;
    }
    int ret = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = i + 1; j <= n; j++) {
        int xa = za[i].f;
        int xb = za[j].f;
        int ya = za[i].s;
        int yb = za[j].s;
        if (xa + xb - yb + ya < 0 || ya + yb + xb - xa < 0 ||
            xa + xb + yb - ya < 0 || ya + yb - xb + xa < 0)
          continue;
        if (xa + xb - yb + ya > 10000 || ya + yb + xb - xa > 10000 ||
            xa + xb + yb - ya > 10000 || ya + yb - xb + xa > 10000)
          continue;
        if (in[(xa + xb - yb + ya) / 2][(ya + yb + xb - xa) / 2] &&
            in[(xa + xb + yb - ya) / 2][(ya + yb - xb + xa) / 2])
          ret = max(ret, (xa - xb) * (xa - xb) + (ya - yb) * (ya - yb));
      }
    }
    printf("%d\\n", ret / 2);
  }
}

Error: -11

Fixed submission:

#include <cstdio>
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int main() {
  int n, x[3000], y[3000];
  bool f[5001][5001] = {false};
  while (true) {
    int ans = 0;
    cin >> n;
    if (n == 0)
      return 0;
    for (int i = 0; i < n; i++) {
      cin >> x[i] >> y[i];
      f[x[i]][y[i]] = true;
    }
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        int a, b, c, d;
        a = x[j] + y[i] - y[j];
        b = y[j] + x[j] - x[i];
        c = x[i] + y[i] - y[j];
        d = y[i] + x[j] - x[i];
        bool f1 = false, f2 = false;
        if (a >= 0 && a <= 5000 && b >= 0 && b <= 5000 && f[a][b])
          f1 = true;
        if (c >= 0 && c <= 5000 && d >= 0 && d <= 5000 && f[c][d])
          f2 = true;
        if (f1 && f2)
          ans = max(ans, (a - c) * (a - c) + (b - d) * (b - d));
      }
    }
    cout << ans << "\\n";
  }
}
Problem p00441 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define FOR(i, n) for (int i = 0; i < (int)(n); i++)
#define FORR(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define ZERO(a) memset(a, 0, sizeof(a))
#define len(a) sizeof(a)
#define ll long long
#define pii pair<int, int>
#define INF 1 << 29
#define MAX 3333
using namespace std;

int x[MAX], y[MAX];

void solve() {
  int n;
  for (;;) {
    cin >> n;
    if (!n)
      break;
    FOR(i, n) cin >> x[i] >> y[i];
    set<pii> st;
    FOR(i, n) st.insert(mp(x[i], y[i]));
    int ma = 0;
    FOR(i, n) {
      FORR(j, i + 1, n) {
        pii v(x[j] - x[i], y[j] - y[i]), p(x[i] + v.second, y[i] - v.first),
            q(x[j] + v.second, y[j] - v.first),
            r(x[i] - v.second, y[i] + v.first),
            s(x[j] - v.second, y[j] + v.first);
        if ((st.find(p) != st.end() && st.find(q) != st.end()) ||
            (st.find(r) != st.end() && st.find(s) != st.end())) {
          ma = max(ma, v.first * v.first + v.second * v.second);
        }
      }
    }
    cout << ma << endl;
  }
}

int main() {
  solve();
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define FOR(i, n) for (int i = 0; i < (int)(n); i++)
#define FORR(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define ZERO(a) memset(a, 0, sizeof(a))
#define len(a) sizeof(a)
#define ll long long
#define pii pair<int, int>
#define INF 1 << 29
#define MAX 511
using namespace std;

int x[MAX], y[MAX];

void solve() {
  int n;
  for (;;) {
    cin >> n;
    if (!n)
      break;
    FOR(i, n) cin >> x[i] >> y[i];
    set<pii> st;
    FOR(i, n) st.insert(mp(x[i], y[i]));
    int ma = 0;
    FOR(i, n) {
      FORR(j, i + 1, n) {
        pii v(x[j] - x[i], y[j] - y[i]), p(x[i] + v.second, y[i] - v.first),
            q(x[j] + v.second, y[j] - v.first),
            r(x[i] - v.second, y[i] + v.first),
            s(x[j] - v.second, y[j] + v.first);
        if ((st.find(p) != st.end() && st.find(q) != st.end()) ||
            (st.find(r) != st.end() && st.find(s) != st.end())) {
          ma = max(ma, abs(2 * v.first * v.second));
        }
      }
    }
    cout << ma << endl;
  }
}

int main() {
  solve();
  return 0;
}