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

// Bokan ga bokka--nn!!
// Daily Lunch Special Tanoshii !!
// これは、頭が悪く競プロが世界で一番できないHIR180が
// IOI2014日本代表になるまでのN日間の記録である。
#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: 0

Fixed submission:

// Bokan ga bokka--nn!!
// Daily Lunch Special Tanoshii !!
// これは、頭が悪く競プロが世界で一番できないHIR180が
// IOI2014日本代表になるまでのN日間の記録である。
#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 (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);
  }
}