Problem p00441 (C++) — buggy submission, verdict: Runtime Error

// Bokan ga bokka--nn!!
// Daily Lunch Special Tanoshii !!
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#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 s(x) scanf("%d", &x)
#define rep(i, x) for (int i = 0; i < x; i++)
bool e[5005][5005] = {};
P za[3005];
int main() {
  int n;
  while (1) {
    scanf("%d", &n);
    if (!n)
      return 0;
    rep(i, n) {
      int x, y;
      scanf("%d %d", &x, &y);
      e[x][y] = true;
      za[i] = mp(x, y);
    }
    int ret = 0;
    rep(i, n) {
      for (int j = i + 1; j < n; j++) {
        int x1 = za[i].first;
        int y1 = za[i].second;
        int x2 = za[j].first;
        int y2 = za[j].second;

        if ((x1 + x2 + y1 - y2) % 2 == 1 || (x1 + x2 + y1 - y2) < 0 ||
            (x1 + x2 + y1 - y2) > 10000)
          continue;
        if ((x1 + x2 - y1 + y2) % 2 == 1 || (x1 + x2 - y1 + y2) < 0 ||
            (x1 + x2 - y1 + y2) > 10000)
          continue;
        if ((y1 + y2 + x1 - x2) % 2 == 1 || (y1 + y2 + x1 - x2) < 0 ||
            (y1 + y2 + x1 - x2) > 10000)
          continue;
        if ((y1 + y2 - x1 + x2) % 2 == 1 || (y1 + y2 - x1 + x2) < 0 ||
            (y1 + y2 - x1 + x2) > 10000)
          continue;
        if (e[(x1 + x2 + y1 - y2) / 2][(y1 + y2 - x1 + x2) / 2]) {
          if (e[(x1 + x2 - y1 + y2) / 2]
               [(y1 + y2 + x1 - x2) / 2]) { // printf("%d %d\\n",i,j);
            ret = max(ret, ((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) / 2);
          }
        }
      }
    }
    printf("%d\\n", ret);
  }
}

Error: 0

Fixed submission:

// Bokan ga bokka--nn!!
// Daily Lunch Special Tanoshii !!
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#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 s(x) scanf("%d", &x)
#define rep(i, x) for (int i = 0; i < x; i++)
bool e[5005][5005] = {};
P za[3005];
int main() {
  int n;
  while (1) {
    scanf("%d", &n);
    if (!n)
      return 0;
    rep(i, n) {
      int x, y;
      scanf("%d %d", &x, &y);
      e[x][y] = true;
      za[i] = mp(x, y);
    }
    int ret = 0;
    rep(i, n) {
      for (int j = i + 1; j < n; j++) {
        int x1 = za[i].first;
        int y1 = za[i].second;
        int x2 = za[j].first;
        int y2 = za[j].second;

        if ((x1 + x2 + y1 - y2) % 2 == 1 || (x1 + x2 + y1 - y2) < 0)
          continue;
        if ((x1 + x2 - y1 + y2) % 2 == 1 || (x1 + x2 - y1 + y2) < 0)
          continue;
        if ((y1 + y2 + x1 - x2) % 2 == 1 || (y1 + y2 + x1 - x2) < 0)
          continue;
        if ((y1 + y2 - x1 + x2) % 2 == 1 || (y1 + y2 - x1 + x2) < 0)
          continue;
        if (e[(x1 + x2 + y1 - y2) / 2][(y1 + y2 - x1 + x2) / 2]) {
          if (e[(x1 + x2 - y1 + y2) / 2]
               [(y1 + y2 + x1 - x2) / 2]) { // printf("%d %d\\n",i,j);
            ret = max(ret, ((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) / 2);
          }
        }
      }
    }
    printf("%d\\n", ret);
  }
}