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

#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define INF (1 << 30)

int main() {
  int n, k, a;

  while (cin >> n >> k && n != 0) {
    int ans = 0;
    bool card[100001] = {false};

    for (int i = 0; i < k; ++i) {
      cin >> a;
      card[a] = true;
    }

    if (card[0]) {
      for (int i = 1, bk, cnt = 0, wh = 0; i <= n; ++i) {
        if (card[i])
          cnt++;
        else {
          if (wh == 0) {
            wh = 1;
            bk = i;
            cnt++;
          } else {
            cnt = 0;
            i = bk;
            wh = 0;
          }
        }
        ans = max(ans, cnt);
      }
    } else {
      for (int i = 1, cnt = 0; i <= n; ++i) {
        if (card[i])
          cnt++;
        else {
          ans = max(ans, cnt);
          cnt = 0;
        }
      }
    }

    cout << ans << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define INF (1 << 30)

int main() {
  int n, k, a;

  while (cin >> n >> k && n != 0) {
    int ans = 0;
    bool white = false;
    vector<int> v;

    for (int i = 0; i < k; ++i) {
      cin >> a;
      if (a == 0)
        white = true;
      else
        v.push_back(a);
    }
    sort(v.begin(), v.end());

    if (white) {
      k--;
      int l = 0, r = 1;
      bool wh = false;

      for (; r < k;) {
        if (wh == false && v[r] - v[r - 1] == 2) {
          wh = true; //???????£???°???
          r++;
          continue;
        }
        if (v[r] - v[r - 1] > 1) {
          ans = max(ans, v[r - 1] - v[l] + 1);
          wh = false;
          l = r - 1;
        } else {
          r++;
        }
      }
      if (wh == true) {
        ans = max(ans, v[k - 1] - v[l] + 1);
      }
    } else {
      for (int i = 0, num = 1; i + 1 < k; ++i, ++num) {
        if (v[i + 1] - v[i] > 1) {
          ans = max(ans, num);
          num = 0;
        }
      }
    }

    cout << ans << endl;
  }

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

#include <algorithm>
#include <iostream>
#include <math.h>
#include <queue>
#include <utility>
#include <vector>
#define INF 1000000007
using namespace std;

int main() {
  for (;;) {
    int n, k;
    cin >> n >> k;
    if (n == 0 && k == 0) {
      break;
    }
    vector<int> card(n, INF);
    for (int i = 0; i < k; i++) {
      cin >> card[i];
    }
    sort(card.begin(), card.end());
    int len = 0;
    if (card[0] == 0) {
      int p = 0, q = 1;
      while (p < k - 1 && q < k) {
        if (card[q] - card[p] == q - p) {
          if (q == k - 1 && p != 0) {
            len = max(len, q - p + 1);
          }
          len = max(len, q - p);
          q++;
        } else {
          if (card[q] - card[p] == 1 + q - p) {
            len = max(len, q - p + 1);
            q++;
          } else {
            if (card[q] - card[p] > 1 + q - p) {
              p++;
            }
          }
        }
      }
    } else {
      int p = 0, q = 1;
      while (p < k - 1 && q < k) {
        if (card[q] - card[p] == q - p) {
          len = max(len, q - p);
          q++;
        } else {
          if (card[q] - card[p] > q - p) {
            p++;
          }
        }
      }
    }
    cout << len + 1 << endl;
  }
}

Error: TLE

Fixed submission:

//
#include <algorithm>
#include <iostream>
#include <math.h>
#include <queue>
#include <utility>
#include <vector>
#define INF 1000000007
using namespace std;

int main() {
  for (;;) {
    int n, k;
    cin >> n >> k;
    if (n == 0 && k == 0) {
      break;
    }
    int card[k];
    for (int i = 0; i < k; i++) {
      cin >> card[i];
    }
    // for (int j=0; j<k; j++) {
    //   cout << card[j];
    //    }
    sort(card, card + k);
    /*  for (int i=0; i<k; i++) {
          cout << card[i];
      }*/
    int len = 0;
    if (card[0] == 0) {
      int p = 0, q = 1;
      while (p < k - 1 && q < k) {
        if (card[p] - card[q] == q - p) {
          if (q == k - 1 && p != 0) {
            len = max(len, q - p + 1);
          }
          len = max(len, q - p);
          q++;
        } else {
          if (card[p] - card[q] == 1 + q - p) {
            len = max(len, q - p + 1);
            q++;
          } else {
            if (card[p] - card[q] > 1 + q - p) {
              p++;
            }
          }
        }
      }
    } else {
      int p = 0, q = 1;
      while (p < k - 1 && q < k) {
        if (card[p] - card[q] == q - p) {
          len = max(len, q - p);
          q++;
        } else {
          if (card[p] - card[q] > q - p) {
            p++;
          }
        }
      }
    }
    cout << len << endl;
  }
}
Problem p00441 (C++) — buggy submission, verdict: Runtime Error

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

const int MAX_N = 3000;
const int MAX_XY = 5000;
int n;
int a[MAX_N][2];
bool b[MAX_XY][MAX_XY];

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

    for (int i = 0; i < MAX_N; i++)
      for (int j = 0; j < 2; j++)
        a[i][j] = 0;
    for (int i = 0; i < MAX_XY; i++)
      for (int j = 0; j < MAX_XY; j++)
        b[i][j] = false;

    for (int i = 0; i < n; i++) {
      scanf("%d %d", &a[i][0], &a[i][1]);
      b[a[i][0]][a[i][1]] = true;
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        int dx, dy;
        dx = a[j][0] - a[i][0];
        dy = a[j][1] - a[i][1];
        for (int k = 0; k < 2; k++) {
          int nx, ny;
          nx = a[i][0] + (2 * k - 1) * dy;
          ny = a[i][1] - (2 * k - 1) * dx;
          if (0 <= nx && nx <= MAX_XY && 0 <= ny && ny <= MAX_XY) {
            if (0 <= nx + dx && nx + dx <= MAX_XY && 0 <= ny + dy &&
                ny + dy <= MAX_XY) {
              if (b[nx][ny] == true && b[nx + dx][ny + dy] == true) {
                ans = max(ans, dx * dx + dy * dy);
              }
            }
          }
        }
      }
    }
    printf("%d\\n", ans);
  }
  return 0;
}

Error: 0

Fixed submission:

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

const int MAX_N = 3000;
const int MAX_XY = 5000;
int n;
int a[MAX_N][2];
bool b[MAX_XY][MAX_XY];

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

    for (int i = 0; i < MAX_N; i++)
      for (int j = 0; j < 2; j++)
        a[i][j] = 0;
    for (int i = 0; i < MAX_XY; i++)
      for (int j = 0; j < MAX_XY; j++)
        b[i][j] = false;

    for (int i = 0; i < n; i++) {
      scanf("%d %d", &a[i][0], &a[i][1]);
      b[a[i][0]][a[i][1]] = true;
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        int dx, dy;
        dx = a[j][0] - a[i][0];
        dy = a[j][1] - a[i][1];
        for (int k = 0; k < 2; k++) {
          int nx, ny;
          nx = a[i][0] + (2 * k - 1) * dy;
          ny = a[i][1] - (2 * k - 1) * dx;
          if (0 <= nx && nx <= MAX_XY && 0 <= ny && ny <= MAX_XY) {
            if (b[nx][ny] == true && b[nx + dx][ny + dy] == true) {
              ans = max(ans, dx * dx + dy * dy);
            }
          }
        }
      }
    }
    printf("%d\\n", ans);
  }
  return 0;
}
Problem p00441 (C++) — buggy submission, verdict: Runtime Error

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

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

const int MAXP = 5010;

struct pall {
  int x, y;
  pall(int x, int y) : x(x), y(y){};
};

char p[MAXP][MAXP];
vector<pall> palls;

int main() {
  int n;
  while (cin >> n && n) {
    palls.clear();
    int ans = 0;
    memset(p, 0, sizeof(p));
    int x, y;
    REP(n) {
      cin >> x >> y;
      p[x][y] = true;
      pall temp = pall(x, y);
      palls.push_back(temp);
    }
    if (n < 4)
      break;
    for (int i = 0; i < n; i++)
      for (int j = i + 1; j < n; j++) {
        int xa, xb, ya, yb, dx, dy;
        xa = palls[i].x;
        ya = palls[i].y;
        xb = palls[j].x;
        yb = palls[j].y;
        dx = xa - xb;
        dy = ya - yb;
        if ((xa - dy >= 0) && xa - dy <= 5000 && (ya + dx >= 0) &&
            ya + dx <= 5000 && (xb - dy >= 0) && xb - dy <= 5000 &&
            (yb + dx >= 0) && yb + dx <= 5000)
          if (p[xa - dy][ya + dx] && p[xb - dy][yb + dx])
            ans = max(ans, dx * dx + dy * dy);

        if ((xa + dy >= 0) && xa + dy <= 5000 && (ya - dx >= 0) &&
            ya - dx <= 5000 && (xb + dy >= 0) && xb + dy <= 5000 &&
            (yb - dx >= 0) && yb - dx <= 5000)
          if (p[xa + dy][ya - dx] && p[xb + dy][yb - dx])
            ans = max(ans, dx * dx + dy * dy);
      }
    cout << ans << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;

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

const int MAXP = 5010;

struct pall {
  int x, y;
  pall(int x, int y) : x(x), y(y){};
};

bool p[MAXP][MAXP];

int main() {
  int n;
  while (cin >> n && n) {
    int ans = 0;
    vector<pall> palls;
    memset(p, false, sizeof(p));
    int x, y;
    REP(n) {
      cin >> x >> y;
      p[x][y] = true;
      palls.push_back(pall(x, y));
    }
    if (n < 4)
      break;
    for (int i = 0; i < n; i++)
      for (int j = i + 1; j < n; j++) {
        int xa, xb, ya, yb, dx, dy;
        xa = palls[i].x;
        ya = palls[i].y;
        xb = palls[j].x;
        yb = palls[j].y;
        dx = xa - xb;
        dy = ya - yb;
        if ((xa - dy >= 0) && (ya + dx >= 0) && (xb - dy >= 0) &&
            (yb + dx >= 0))
          if (p[xa - dy][ya + dx] && p[xb - dy][yb + dx])
            ans = max(ans, dx * dx + dy * dy);

        if ((xa + dy >= 0) && (ya - dx >= 0) && (xb + dy >= 0) &&
            (yb - dx >= 0))
          if (p[xa + dy][ya - dx] && p[xb + dy][yb - dx])
            ans = max(ans, dx * dx + dy * dy);
      }
    cout << ans << endl;
  }

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

#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef pair<double, double> P;
int n, x[3001], y[3001];
set<P> st;
int main() {
  while (cin >> n, n) {
    st.clear();
    r(i, n) {
      cin >> x[i] >> y[i];
      st.insert(P(x[i], y[i]));
    }
    int ans = 0;
    r(i, n) r(j, n) if (i != j) {
      int tx1 = x[i] - x[j], ty1 = y[i] - y[j];
      int tx2 = x[i] + ty1, ty2 = y[i] - tx1;
      int tx3 = x[j] + ty1, ty3 = y[j] - tx1;
      int tx4 = x[i] - ty1, ty4 = y[i] + tx1;
      int tx5 = x[j] - ty1, ty5 = y[j] + tx1;
      if (st.count(P(tx2, ty2)) && st.count(P(tx3, ty3)) ||
          st.count(P(tx4, ty4)) && st.count(P(tx5, ty5))) {
        ans = max(ans, tx1 * tx1 + ty1 * ty1);
      }
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef pair<double, double> P;
int n;
double x[3001], y[3001];
set<P> st;
int main() {
  while (cin >> n, n) {
    st.clear();
    r(i, n) {
      cin >> x[i] >> y[i];
      st.insert(P(x[i], y[i]));
    }
    double ans = 0;
    r(i, n) r(j, n) if (i != j) {
      if (st.count(P(x[i] + (x[j] - x[i]), y[j] + (y[i] - y[j]))) ||
          st.count(P(x[j] + (x[i] - x[j]), y[i] + (y[j] - y[i]))) ||
          st.count(P(y[i] + (y[j] - y[i]), x[j] + (x[i] - x[j]))) ||
          st.count(P(y[j] + (y[i] - y[j]), x[i] + (x[j] - x[i])))) {
        ans = max(ans, (sqrt(abs(x[i] - x[j]) + abs(y[i] - y[j]))) *
                           (sqrt(abs(x[i] - x[j]) + abs(y[i] - y[j]))));
      }
    }
    cout << ans << endl;
  }
}
Problem p00441 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define For(i, a, b) for (int(i) = (a); (i) < (b); (i)++)

typedef pair<int, int> P;

vector<P> v;

bool issquare(int i, int j) {
  P p1 = v[i];
  P p2 = v[j];
  int p1top2x = p2.first - p1.first;
  if (p1top2x <= 0)
    return false;
  int p1top2y = p2.second - p1.second;
  if (p1top2y > 0)
    return false;
  P q1 = make_pair(p1.first - p1top2y, p1.second + p1top2x);
  P q2 = make_pair(p2.first - p1top2y, p2.second + p1top2x);
  if (binary_search(v.begin() + i, v.end(), q1) &&
      binary_search(v.begin() + j, v.end(), q2)) {
    return true;
  } else {
    return false;
  }
}

void solve18(int a) {
  v.clear();
  REP(i, a) {
    int p, q;
    scanf("%d%d", &p, &q);
    v.push_back(make_pair(p, q));
  }
  sort(v.begin(), v.end());
  int ans = 0;
  for (int i = 0; i < a - 1; i++) {
    for (int j = i + 1; j < a; j++) {
      if (issquare(i, j)) {
        int r = v[i].first - v[j].first;
        int s = v[i].second - v[j].second;
        ans = max(ans, r * r + s * s);
      }
    }
  }
  cout << ans << endl;
}

int main() {
  int a;
  while (cin >> a, a) {
    solve18(a);
  }
  return 0;
}

Error: TLE

Fixed submission:

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

#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define For(i, a, b) for (int(i) = (a); (i) < (b); (i)++)

typedef pair<int, int> P;

bool issquare(P p1, P p2, vector<P> v) {
  int p1top2x = p2.first - p1.first;
  int p1top2y = p2.second - p1.second;
  if (p1top2x <= 0 || p1top2y > 0)
    return false;
  if (p1top2x == p1top2y)
    return false;
  P q1 = make_pair(p1.first - p1top2y, p1.second + p1top2x);
  P q2 = make_pair(p2.first - p1top2y, p2.second + p1top2x);
  if (binary_search(v.begin(), v.end(), q1) &&
      binary_search(v.begin(), v.end(), q2)) {
    return true;
  } else {
    return false;
  }
}

void solve18(int a) {
  vector<P> v;
  REP(i, a) {
    int p, q;
    cin >> p >> q;
    v.push_back(make_pair(p, q));
  }
  sort(v.begin(), v.end());
  int ans = 0;
  for (int i = 0; i < a - 1; i++) {
    for (int j = i + 1; j < a; j++) {
      if (issquare(v[i], v[j], v)) {
        ans = max(ans, (v[i].first - v[j].first) * (v[i].first - v[j].first) +
                           (v[i].second - v[j].second) *
                               (v[i].second - v[j].second));
      }
    }
  }
  cout << ans << endl;
}

int main() {
  int a;
  while (cin >> a, a) {
    solve18(a);
  }
  return 0;
}
Problem p00441 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

bool c[5002][5002];

int main() {
  int i, j, n, w, h;
  long long max, s;
  int a[3001], b[3001];

  while (1) {
    scanf("%d", &n);
    if (n == 0)
      break;
    for (i = 0; i <= 5000; i++) {
      for (j = 0; j <= 5000; j++) {
        c[i][j] = false;
      }
    }
    for (i = 0; i <= n - 1; i++) {
      scanf("%d%d", &a[i], &b[i]);
      c[a[i]][b[i]] = true;
    }
    max = 0;
    for (i = 0; i <= n - 1; i++) {
      for (j = i + 1; j <= n - 1; j++) {
        w = abs(a[j] - a[i]);
        if (a[j] > a[i])
          h = b[j] - b[i];
        else
          h = b[i] - b[j];
        if (a[i] - h >= 0 && a[i] - h <= 5000 && a[j] - h >= 0 &&
            a[j] - h <= 5000 && b[i] + w <= 5000 && b[j] + w <= 5000) {
          if (c[a[i] - h][b[i] + w] == true && c[a[j] - h][b[j] + w] == true) {
            s = w * w + h * h;
            if (max < s)
              max = s;
          }
        }
      }
    }
    printf("%lld\\n", max);
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

int c[5002][5002];

int main() {
  int i, j, n, A, B, w, h, max, s;
  vector<int> a, b;

  while (1) {
    scanf("%d", &n);
    if (n == 0)
      break;
    for (i = 0; i <= 5000; i++) {
      for (j = 0; j <= 5000; j++) {
        c[i][j] = 0;
      }
    }
    for (i = 0; i <= n - 1; i++) {
      scanf("%d%d", &A, &B);
      a.push_back(A);
      b.push_back(B);
      c[A][B] = 1;
    }
    max = 0;
    for (i = 0; i <= n - 2; i++) {
      for (j = i + 1; j <= n - 1; j++) {
        w = abs(a[j] - a[i]);
        h = b[j] - b[i];
        if (a[i] - h >= 0 && a[i] - h <= 5000 && a[j] - h >= 0 &&
            a[j] - h <= 5000 && b[i] + w <= 5000 && b[j] + w <= 5000) {
          if (c[a[i] - h][b[i] + w] == 1 && c[a[j] - h][b[j] + w] == 1) {
            s = w * w + h * h;
            if (max < s)
              max = s;
          }
        }
      }
    }
    printf("%d\\n", max);
  }
  return 0;
}
Problem p00441 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

pair<int, int> point[3000];
bool ch[5001][5001];
int n, ans;

int main() {
  while (true) {
    cin >> n;
    if (n == 0)
      break;

    memset(ch, 0, sizeof(ch));
    REP(i, n) {
      int a, b;
      scanf("%d %d", &a, &b);
      point[i] = make_pair(a, b);
      ch[a][b] = true;
    }

    ans = 0;
    REP(i, n) {
      REP(j, n) {
        int x1 = point[i].first, y1 = point[i].second;
        int x2 = point[j].first, y2 = point[j].second;
        int pos = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
        if (pos < ans)
          continue;

        int x3 = y1 - y2 + x2, y3 = x2 - x1 + y2;
        if (x3 < 0 || x3 > 5000 || y3 < 0 || y3 > 5000 || !ch[x3][y3])
          continue;

        int x4 = y1 - y2 + x1, y4 = x2 - x1 + y1;
        if (x4 < 0 || x4 > 5000 || y4 < 0 || y4 > 5000 || !ch[x4][y4])
          continue;

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

Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>
#include <map>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define culc(a, b)                                                             \\
  ((point[a].first - point[b].first) * (point[a].first - point[b].first) +     \\
   (point[a].second - point[b].second) * (point[a].second - point[b].second))

typedef pair<int, int> PII;

int main() {
  PII point[501];
  int n;
  long long ans;
  while (true) {
    cin >> n;
    if (n == 0)
      break;
    REP(i, n) {
      int a, b;
      scanf("%d %d", &a, &b);
      point[i] = make_pair(a, b);
    }
    ans = 0;
    REP(i, n) {
      REP(j, n) {
        REP(k, n) {
          if (culc(i, j) != culc(j, k))
            continue;
          REP(l, n) {
            if (i == j || i == k || i == l || j == k || j == l || k == l)
              continue;
            if (culc(j, k) != culc(k, l) || culc(k, l) != culc(l, i))
              continue;
            ans = ans > culc(i, j) ? ans : culc(i, j);
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00441 (C++) — buggy submission, verdict: Memory Limit Exceeded

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0518
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  while (true) {
    int n;
    cin >> n;
    if (n == 0)
      break;
    vector<pair<int, int>> P(n);
    vector<vector<bool>> m(5010, vector<bool>(5010));
    for (int i = 0; i < n; i++) {
      int x, y;
      cin >> x >> y;
      m[x][y] = true;
      P[i] = make_pair(x, y);
    }
    sort(P.begin(), P.end());
    int ans = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        pair<int, int> p1, p2;
        p1.first = P[j].first - (P[j].second - P[i].second);
        p1.second = P[j].second + (P[j].first - P[i].first);

        p2.first = P[i].first - (P[j].second - P[i].second);
        p2.second = P[i].second + (P[j].first - P[i].first);

        if (p1.first < 0 || p1.first > 5000)
          continue;
        if (p1.second < 0 || p1.second > 5000)
          continue;
        if (p2.first < 0 || p2.first > 5000)
          continue;
        if (p2.second < 0 || p2.second > 5000)
          continue;

        if (m[p1.first][p1.second] && m[p2.first][p2.second]) {
          ans = max(ans, (int)pow(P[i].first - P[j].first, 2) +
                             (int)pow(P[i].second - P[j].second, 2));
        }
      }
    }
    cout << ans << endl;
  }
}

Error: MLE

Fixed submission:

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0518
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  map<pair<double, double>, int> m;
  while (true) {
    int n;
    cin >> n;
    if (n == 0)
      break;
    m.clear();
    vector<pair<double, double>> P(n);
    for (int i = 0; i < n; i++) {
      double x, y;
      cin >> x >> y;
      m[make_pair(x, y)]++;
      P[i] = make_pair(x, y);
    }
    sort(P.begin(), P.end());
    double ans = -1;
    pair<double, double> p1, p2;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        p1.first = P[j].first - (P[j].second - P[i].second);
        p1.second = P[j].second + (P[j].first - P[i].first);

        p2.first = P[i].first - (P[j].second - P[i].second);
        p2.second = P[i].second + (P[j].first - P[i].first);

        if (m[p1] != 0 && m[p2] != 0) {
          ans = max(ans, pow(P[i].first - P[j].first, 2) +
                             pow(P[i].second - P[j].second, 2));
        }
      }
    }
    cout << ans << endl;
  }
}
Problem p00441 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <complex>
#include <cstdio>
using namespace std;
typedef complex<int> P;

int n, x, y;
int d[5001][5001];
P p[5000];

int square(int x) { return x * x; }

bool isOk(P p) { return d[p.real()][p.imag()] == 1; }

int main() {
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      break;
    for (int i = 0; i <= 5000; i++)
      for (int j = 0; j <= 5000; j++)
        d[i][j] = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d%d", &x, &y);
      d[y][x] = 1;
      p[i] = P(y, x);
    }
    int ans = 0;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < i; j++) {
        P dir1 = p[i] - p[j];
        P dir2 = P(dir1.imag(), -dir1.real());
        for (int i = -1; i <= 1; i += 2) {
          P p1 = dir2 * i + p[j];
          P p2 = p1 + dir1;
          if (p1.real() < 0 || p1.imag() < 0 || p2.real() < 0 || p2.imag() < 0)
            continue;
          if (p1.real() >= 5001 || p1.imag() >= 5001 || p2.real() >= 5001 ||
              p2.imag() >= 5001)
            continue;
          if (isOk(p1) && isOk(p2))
            ans = max(ans, square(dir1.real()) + square(dir1.imag()));
        }
      }
    printf("%d\\n", ans);
  }
}


Error: 0

Fixed submission:

#include <algorithm>
#include <complex>
#include <cstdio>
using namespace std;
typedef complex<int> P;

int n, x, y;
int d[5001][5001];
P p[5000];

int square(int x) { return x * x; }

bool isOk(P p) { return d[p.real()][p.imag()] == 1; }

int main() {
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      break;
    for (int i = 0; i <= 5000; i++)
      for (int j = 0; j <= 5000; j++)
        d[i][j] = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d%d", &x, &y);
      d[y][x] = 1;
      p[i] = P(y, x);
    }
    int ans = 0;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < i; j++) {
        P dir1 = p[i] - p[j];
        P dir2 = P(dir1.imag(), -dir1.real());
        for (int i = -1; i <= 1; i += 2) {
          P p1 = dir2 + p[j] * i;
          P p2 = p1 + dir1;
          if (p1.real() < 0 || p1.imag() < 0 || p2.real() < 0 || p2.imag() < 0)
            continue;
          if (isOk(p1) && isOk(p2))
            ans = max(ans, square(dir1.real()) + square(dir1.imag()));
        }
      }
    printf("%d\\n", ans);
  }
}