Problem:
最古の遺跡
問題
昔, そこには集落があり, 多くの人が暮らしていた. 人々は形も大きさも様々な建物を建てた. だが, それらの建造物は既に失われ, 文献と, 遺跡から見つかった柱だけが建造物の位置を知る手がかりだった.
文献には神殿の記述がある. 神殿は上から見ると正確に正方形になっており, その四隅には柱があった. 神殿がどの向きを向いていたかはわからない. また, 辺上や内部に柱があったかどうかもわからない. 考古学者たちは, 遺跡から見つかった柱の中で, 正方形になっているもののうち, 面積が最大のものが神殿に違いないと考えた.
柱の位置の座標が与えられるので, 4 本の柱でできる正方形のうち面積が最大のものを探し, その面積を出力するプログラムを書け. なお, 正方形の辺は座標軸に平行とは限らないことに注意せよ.
例
下の図の例では, 10 本の柱があり, 座標 (4, 2), (5, 2), (5, 3), (4, 3) にある 4 本と座標 (1, 1), (4, 0), (5, 3), (2, 4) にある 4 本が正方形をなしている. 面積が最大の正方形は後者で, その面積は 10 である.
入力
入力は複数のデータセットからなる．各データセットは以下の形式で与えられる．入力はゼロ１つを含む行で終了する．
1 行目には, 遺跡から見つかった柱の本数 n が書かれている.
2 行目から n + 1 行目までの n 行の各々には, 柱の x 座標と y 座標が空白区切りで書かれている.
1 本の柱が 2 度以上現れることはない.
n は 1 ≤ n ≤ 3000 を満たす整数であり, 柱の x 座標と y 座標は 0 以上 5000 以下の整数である.
採点用データのうち, 配点の 30% 分は 1 ≤   n ≤ 100 を満たし, 配点の 60% 分は1 ≤ n ≤ 500 を満たす.
データセットの数は 10 を超えない．
出力
データセットごとに 1 個の整数を出力する. 4 本の柱からなる正方形が存在する場合は, そのような正方形のうち面積が最大のものの面積を出力し, そのような正方形が存在しない場合は 0 を出力せよ.
入出力例
入力例
10
9 4
4 3
1 1
4 2
2 4
5 8
4 0
5 3
0 5
5 2
10
9 4
4 3
1 1
4 2
2 4
5 8
4 0
5 3
0 5
5 2
0
出力例
10
10
上記問題文と自動審判に使われるデータは、
情報オリンピック日本委員会
が作成し公開している問題文と採点用テストデータです。

Submitted solutions:

code_snippet: #include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
using ll = long long;
int main(){
    while(true){
        int N;
        cin >> N;
        if(N == 0) break;
        vector<int> x(N,0);
        vector<int> y(N,0);
        for(int i = 0;i < N;i++){
            cin >> x[i];
            cin >> y[i];
        }
        vector<vector<int>> vv(N,vector<int>(N,0));
        for(int i = 0;i < N;i++){
            for(int j = 0;j < N;j++){
                vv[i][j] = ((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
            }
        }
        ll ans = 0;
        for(int i = 0;i < N;i++){
            for(int j = i+1;j < N;j++){
                int def = vv[i][j];
                for(int k = j+1;k < N;k++){
                    if(vv[i][k] == def){
                        if(vv[i][j] * 2 == vv[j][k]){
                            int shahen = vv[j][k];
                            for(int l = i+1;l < N;l++){
                                if(vv[i][l] == shahen){
                                    if(vv[j][l] == def){
                                        if(def > ans) ans = def;
                                    }
                                }
                            }
                        }
                    }
                }   
            }
        }
        cout << ans << endl;
    }
}
accuracy: 1
time_ms: 4280
memory_kb: 38176
final_rank: 20

code_snippet: #include <iostream>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <cmath>
using namespace std;

// 座標を一意に識別するためのハッシュ関数
inline int encode(int x, int y) {
    return x * 5001 + y;
}

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

        vector<int> X(N), Y(N);
        unordered_set<int> point_set;

        for (int i = 0; i < N; i++) {
            cin >> X[i] >> Y[i];
            point_set.insert(encode(X[i], Y[i]));
        }

        int ans = 0;

        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                int x1 = X[i], y1 = Y[i];
                int x2 = X[j], y2 = Y[j];

                // 正方形の3,4点目を計算（90度回転）
                int x3 = x1 - (y2 - y1), y3 = y1 + (x2 - x1);
                int x4 = x2 - (y2 - y1), y4 = y2 + (x2 - x1);

                if (0 <= x3 && x3 <= 5000 && 0 <= y3 && y3 <= 5000 &&
                    0 <= x4 && x4 <= 5000 && 0 <= y4 && y4 <= 5000) {
                    if (point_set.count(encode(x3, y3)) && point_set.count(encode(x4, y4))) {
                        int dist = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
                        ans = max(ans, dist);
                    }
                }

                // もう一方に90度回転した場合
                x3 = x1 + (y2 - y1), y3 = y1 - (x2 - x1);
                x4 = x2 + (y2 - y1), y4 = y2 - (x2 - x1);

                if (0 <= x3 && x3 <= 5000 && 0 <= y3 && y3 <= 5000 &&
                    0 <= x4 && x4 <= 5000 && 0 <= y4 && y4 <= 5000) {
                    if (point_set.count(encode(x3, y3)) && point_set.count(encode(x4, y4))) {
                        int dist = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
                        ans = max(ans, dist);
                    }
                }
            }
        }

        cout << ans << endl;
    }

    return 0;
}
accuracy: 1
time_ms: 510
memory_kb: 3284
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    // n==0 で終了
    while ( (cin >> n) && n ) {
        vector<pair<int,int>> v(n);
        // 都市の座標を読み込み
        for (auto& p : v) {
            cin >> p.first >> p.second;
        }
        // 二分探索での検索用にソートしておく
        sort(v.begin(), v.end());

        ll ans = 0;
        // すべての点対 (i,j) を試す O(n^2)
        for (int i = 0; i < n - 1; ++i) {
            auto [xi, yi] = v[i];
            for (int j = i + 1; j < n; ++j) {
                auto [xj, yj] = v[j];
                // ベクトル (dx,dy) = v[i] -> v[j]
                ll dx = ll(xj) - xi;
                ll dy = ll(yj) - yi;
                // 90° 回転させたベクトルを足し引きして正方形の他の頂点を得る
                // 回転方向１： (dx,dy) → (  dy, -dx )
                pair<int,int> p1{ int(xi + dy), int(yi - dx) };
                pair<int,int> p2{ int(xj + dy), int(yj - dx) };
                if (binary_search(v.begin(), v.end(), p1)
                 && binary_search(v.begin(), v.end(), p2)) {
                    ans = max(ans, dx*dx + dy*dy);
                }
                // 回転方向２： (dx,dy) → ( -dy, dx )
                p1 = { int(xi - dy), int(yi + dx) };
                p2 = { int(xj - dy), int(yj + dx) };
                if (binary_search(v.begin(), v.end(), p1)
                 && binary_search(v.begin(), v.end(), p2)) {
                    ans = max(ans, dx*dx + dy*dy);
                }
            }
        }

        // 答えを出力（最大辺長の自乗）
        cout << ans << "\n";
    }

    return 0;
}
accuracy: 1
time_ms: 1280
memory_kb: 3584
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

int main(){
    while(1){
        int n;
        cin >> n;
        if(n==0) break;
        
        vector<pair<int,int>> points(n);
        set<pair<int,int>> point_set;
        rep(i,n){
            cin >> points[i].first >> points[i].second;
            point_set.insert(points[i]);
        }
        
        int res=0;
        rep(i,n){
            for(int j=i+1;j<n;j++){
                int a=points[i].first,b=points[i].second;
                int c=points[j].first,d=points[j].second;
                int dx=c-a,dy=d-b;

                if(point_set.count({a-dy,b+dx}) && point_set.count({c-dy,d+dx})){
                    res=max(res,dx*dx+dy*dy);
                }
                if(point_set.count({a+dy,b-dx}) && point_set.count({c+dy,d-dx})){
                    res = max(res,dx*dx+dy*dy);
                }
            }
        }
        cout << res << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 1570
memory_kb: 3224
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
const int inf = INT_MAX;
using ll = long long;
const ll INF = 1e18;
using P = pair<int,int>;
struct Edge{
    int to;
    ll cost;
    Edge(int to,ll cost):to(to),cost(cost){}
};
using kEdge = pair<int,pair<int,int>>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;


struct UnionFind{
   vector<int> par,rank,siz;
   UnionFind(int n) : par(n,-1),rank(n,0),siz(n,1){ }

   int root(int x){
       if(par[x]==-1)return x;
       else return par[x]=root(par[x]);
   }

   bool issame(int x,int y){
       return root(x)==root(y);
   }

   bool unite(int x,int y){
       int rx=root(x),ry=root(y);
       if(rx==ry)return false;
       if(rank[rx]<rank[ry])swap(rx,ry);
       par[ry]=rx;
       if(rank[rx]==rank[ry])rank[rx]++;
       siz[rx]+=siz[ry];
       return true;
   }

   int size(int x){
       return siz[root(x)];
   }
};

class SegmentTree{
   public:
   vector<int>dat;
   int siz=1;

   void init(int N){
       siz=1;
       while(siz<N)siz*=2;
       dat=vector<int>(2*siz,0);
   }

   void update(int pos,int x){
       pos=pos+siz-1;
       dat[pos]=x;
       while(pos>=2){
           pos/=2;
           dat[pos]=max(dat[pos*2],dat[pos*2+1]);
       }
   }

   int query(int l,int r,int a,int b,int u){
       if(r<=a || b<=l)return -100000000;
       if(l<=a && b<=r)return dat[u];
       int m=(a+b)/2;
       int AnsL=query(l,r,a,m,u*2);
       int AnsR=query(l,r,m,b,u*2+1);
       return max(AnsL,AnsR);
   }
};

template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}

vector<int>dxs={1,0,-1,0};
vector<int>dys={0,1,0,-1};

//fixed << setprecision(10)
//A[i].erase(unique(ALL(A[i])),A[i].end());

int main(){
    int n;
    while(cin >> n){
        if(n==0)break;
        vector<int>x(n),y(n);
        rep(i,n)cin >> x[i] >> y[i];

        vector<vector<bool>>g(6000,vector<bool>(6000,false));
        rep(i,n)g[x[i]][y[i]]=true;

        auto check=[&](int p,int q)->bool{
            if(p<0 || p>=6000 || q<0 || q>=6000)return false;
            return g[p][q];
        };

        int ans=0;
        rep(i,n){
            for(int j=i+1;j<n;j++){
                int dx=x[j]-x[i],dy=y[j]-y[i];
                if(check(x[j]-dy,y[j]+dx) && check(x[i]-dy,y[i]+dx)){
                    chmax(ans,dx*dx+dy*dy);
                }
                if(check(x[j]+dy,y[j]-dx) && check(x[i]+dy,y[i]-dx)){
                    chmax(ans,dx*dx+dy*dy);
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 130
memory_kb: 8176
final_rank: 1

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

const int MAX_N = 3e3 + 10;
int n;
bool p[5005][5005];
int px[MAX_N];
int py[MAX_N];


int main(){
  while(cin >> n){
    if(n == 0)break;
    int ans = 0;
    memset(p, 0, sizeof(p));
    for(int i = 0; i < n; i++) {
        cin >> px[i] >> py[i];
        p[px[i]][py[i]] = 1;
    }

    for(int i = 0; i < n; i++)
      for(int j = i + 1; j < n; j++) {
        int dx = px[i] - px[j], dy = py[i] - py[j];
        int x1 = px[i] - dy, y1 = py[i] + dx;
        int x2 = px[j] - dy, y2 = py[j] + dx;
        if (0 <= x1 && x1 <= 5000 && 0 <= y1 && y1 <= 5000 && p[x1][y1] &&
            0 <= x2 && x2 <= 5000 && 0 <= y2 && y2 <= 5000 && p[x2][y2]) {
            ans = max(ans, dx * dx + dy * dy);
        }

        int x3 = px[i] + dy, y3 = py[i] - dx;
        int x4 = px[j] + dy, y4 = py[j] - dx;
        if (0 <= x3 && x3 <= 5000 && 0 <= y3 && y3 <= 5000 && p[x3][y3] &&
            0 <= x4 && x4 <= 5000 && 0 <= y4 && y4 <= 5000 && p[x4][y4]) {
            ans = max(ans, dx * dx + dy * dy);
        }
      }

    cout << ans << '\n';
  }

  return 0;
}
accuracy: 1
time_ms: 210
memory_kb: 27548
final_rank: 12

code_snippet: #line 1 "/opt/library/template.hpp"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using i64 = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
using f128 = __float128;

template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'000'001'000;
template <>
constexpr ll infty<ll> = ll(infty<int>) * infty<int> * 2;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * infty<ll>;
template <>
constexpr double infty<double> = infty<ll>;
template <>
constexpr long double infty<long double> = infty<ll>;
#define inf infty<ll>

using pi = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vector<ll>>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vc<T>>;
template <class T>
using vvvc = vector<vvc<T>>;
template <class T>
using vvvvc = vector<vvvc<T>>;
template <class T>
using vvvvvc = vector<vvvvc<T>>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;

#define vv(type, name, h, ...) \
  vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...)   \
  vector<vector<vector<type>>> name( \
      h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)       \
  vector<vector<vector<vector<type>>>> name( \
      a, vector<vector<vector<type>>>(       \
             b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))

#define rep1(a) for (ll _ = 0; _ < (ll)(a); ++_)
#define rep2(i, a) for (ll i = 0; i < (ll)(a); ++i)
#define rep3(i, a, b) for (ll i = a; i < (ll)(b); ++i)
#define rep4(i, a, b, c) for (ll i = a; i < (ll)(b); i += (c))
#define rrep1(a) for (ll i = (a)-1; i >= (ll)(0); --i)
#define rrep2(i, a) for (ll i = (a)-1; i >= (ll)(0); --i)
#define rrep3(i, a, b) for (ll i = (b)-1; i >= (ll)(a); --i)
#define rrep4(i, a, b, c) for (ll i = (b)-1; i >= (ll)(a); i -= (c))
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)

#define all(x) (x).begin(),(x).end()
#define len(x) (ll)(x.size())
#define elif else if
#define bit(x, i) (((x)>>(i))&1)

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second

#define stoi stoll
#define abs llabs

#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define UNIQUE(x) \
  sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit()

ll popcnt(ll x) { return __builtin_popcountll(x); }
ll popcnt(u64 x) { return __builtin_popcountll(x); }
ll popcnt_mod_2(ll x) { return __builtin_parityll(x); }
ll popcnt_mod_2(u64 x) { return __builtin_parityll(x); }
ll topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
ll topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
ll lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
ll lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }

template <typename T>
T floor(T a, T b) {
  return a / b - (a % b && (a ^ b) < 0);
}
template <typename T>
T ceil(T x, T y) {
  return floor(x + y - 1, y);
}
template <typename T>
T bmod(T x, T y) {
  return x - y * floor(x, y);
}
template <typename T>
pair<T, T> divmod(T x, T y) {
  T q = floor(x, y);
  return {q, x - q * y};
}

template<typename T> T SUM(const vector<T> &A) {
  T s = 0; for (auto &&a: A) s += a;
  return s;
}

template <typename T>
T POP(queue<T> &que) {
  T a = que.front();
  que.pop();
  return a;
}
template <typename T>
T POP(deque<T> &que) {
  T a = que.front();
  que.pop_front();
  return a;
}
template <typename T>
T POP(pq<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(pqg<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(vc<T> &que) {
  T a = que.back();
  que.pop_back();
  return a;
}

template <typename F>
ll binary_search(F check, ll ok, ll ng, bool check_ok = true) {
  if (check_ok) assert(check(ok));
  while (abs(ok - ng) > 1) {
    auto x = (ng + ok) / 2;
    (check(x) ? ok : ng) = x;
  }
  return ok;
}
template <typename F>
f128 binary_search_real(F check, f128 ok, f128 ng, ll iter = 100) {
  rep(iter) {
    f128 x = (ok + ng) / 2;
    (check(x) ? ok : ng) = x;
  }
  return (ok + ng) / 2;
}

// ? は -1
vc<int> s_to_vi(const string &S, char first_char) {
  vc<int> A(S.size());
  rep(i, S.size()) { A[i] = (S[i] != '?' ? S[i] - first_char : -1); }
  return A;
}

template <typename T, typename U>
vc<T> cumsum(vc<U> &A, ll off = 1) {
  ll N = A.size();
  vc<T> B(N + 1);
  rep(i, N) { B[i + 1] = B[i] + A[i]; }
  if (off == 0) B.erase(B.begin());
  return B;
}

// stable sort
template <typename T>
vi argsort(const vector<T> &A) {
  vi ids(len(A));
  iota(all(ids), 0);
  sort(all(ids),
       [&](ll i, ll j) { return (A[i] == A[j] ? i < j : A[i] < A[j]); });
  return ids;
}

// A[I[0]], A[I[1]], ...
template <typename T>
vc<T> rearrange(const vc<T> &A, const vi &I) {
  vc<T> B(len(I));
  rep(i, len(I)) B[i] = A[I[i]];
  return B;
}

template<typename T> inline bool chmax(T &a, T b) {return ((a<b)?(a=b,true):(false));}
template<typename T> inline bool chmin(T &a, T b) {return ((a>b)?(a=b,true):(false));}

inline void wt(const char c) { cout << c; }
inline void wt(const string s) { cout << s; }
inline void wt(const char *s) { cout << s; }

template <typename T>
void wt_integer(T x) {
  if (x < 0) { cout << (i64)(x); }
  else { cout << (u64)(x); }
}
template <typename T>
void wt_real(T x) {
  cout << fixed << setprecision(15) << (long double)(x);
}

inline void wt(int x) { wt_integer(x); }
inline void wt(ll x) { wt_integer(x); }
inline void wt(i128 x) { wt_integer(x); }
inline void wt(u32 x) { wt_integer(x); }
inline void wt(u64 x) { wt_integer(x); }
inline void wt(u128 x) { wt_integer(x); }
inline void wt(double x) { wt_real(x); }
inline void wt(long double x) { wt_real(x); }
inline void wt(f128 x) { wt_real(x); }

template <class T, class U>
void wt(const pair<T, U> val) {
  wt(val.first); wt(' '); wt(val.second);
}
template <size_t N = 0, typename T>
void wt_tuple(const T t) {
  if constexpr (N < std::tuple_size<T>::value) {
    if constexpr (N > 0) { wt(' '); }
    const auto x = std::get<N>(t);
    wt(x);
    wt_tuple<N + 1>(t);
  }
}
template <class... T>
void wt(tuple<T...> tpl) {
  wt_tuple(tpl);
}
template <class T, size_t S>
void wt(const array<T, S> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}
template <class T>
void wt(const vector<T> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}

void print() { wt('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
  wt(head);
  if (sizeof...(Tail)) wt(' ');
  print(forward<Tail>(tail)...);
}

void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }
void onez(bool t = 1) { print(t ? 1 : 0); }
#define endl '\n'
#define dump(x) {cerr << #x " = " << x << '\n';}
#line 2 "main.cpp"

int solve();
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  while (!solve()) {}
  return 0;
}

int solve() {
  ll n, x, y;
  cin >> n;
  if (n == 0) return 1;
  set<pi> s;
  rep(n) {
    cin >> x >> y;
    s.emplace(mp(x, y));
  }
  ll ans = 0;
  auto i = s.begin();
  while (i != s.end()) {
    auto [xi, yi] = *i;
    i++;
    if (i == s.end()) break;
    auto j = i;
    for ( ; j != s.end(); j++) {
      auto [xj, yj] = *j;
      if (s.count(mp(xj-yj+yi, yj+xj-xi)) and s.count(mp(xi-yj+yi, yi+xj-xi))) {
        ll xx = xi - xj;
        ll yy = yi - yj;
        chmax(ans, xx*xx + yy*yy);
      }
    }
  }
  print(ans);
  return 0;
}
accuracy: 1
time_ms: 960
memory_kb: 3500
final_rank: 8

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




int main(){
    while(1){
        int N;
        cin>>N;
        if(N==0)return 0;

        set<pair<int,int>> S;
        vector<pair<int,int>> P(N);
        for(int i=0;i<N;i++){
            cin>>P[i].first>>P[i].second;
            S.insert(P[i]);
        }
        int an=0;
        for(int i=0;i<N;i++)for(int j=i+1;j<N;j++){
            int dx=P[j].first-P[i].first;
            int dy=P[j].second-P[i].second;
            int nx=P[j].first-dy;
            int ny=P[j].second+dx;
            if(!S.count({nx,ny}))continue;
            nx-=dx;
            ny-=dy;
            if(!S.count({nx,ny}))continue;
            an=max(an,dx*dx+dy*dy);
        }
        cout<<an<<endl;
        //return 0;




    }
}
accuracy: 1
time_ms: 850
memory_kb: 3512
final_rank: 7

code_snippet: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
int main(void)
{
    while (true)
    {
        int n; cin >> n; if (n == 0) break;
        vector<pair<int, int>> p(n);
        rep(i, n) cin >> p.at(i).first >> p.at(i).second;
        sort(all(p));
        int ans = 0;
        rep(i, n)for(int j=i+1;j<n;j++)
        {
            pair<int, int> a = {p[i].first, p[i].second}, b = {p[j].first, p[j].second};
            pair<int, int> q = {b.first - b.second + a.second, b.second + b.first - a.first}, r = {a.first - b.second + a.second, a.second + b.first - a.first};
            if (binary_search(all(p), q) && binary_search(all(p), r))
            {
                ans = max(ans, (int)pow(a.first-b.first, 2) + (int)pow(a.second-b.second, 2));
            }
        }
        cout << ans << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 660
memory_kb: 3360
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;

pii add(pii a, pii b) {
    return {a.first + b.first, a.second + b.second};
}

pii diff(pii a, pii b) {
    return {a.first - b.first, a.second - b.second};
}

int dot(pii a) {
    return a.first*a.first + a.second*a.second;
}

bool judge(pii a) {
    int x = a.first, y = a.second;
    bool res = true;
    if ((x + y) & 1) res = false;
    if (abs(x - y) & 1) res = false;
    if (abs(-x + y) & 1) res = false;
    return res;
}

void out(pii a) {
    cout << a.first << ' ' << a.second << endl;
}

int solve(int n) {
    vector<int> xs(n), ys(n);
    for (int i = 0 ; i < n ; i++) cin >> xs[i] >> ys[i];
    set<pii> st;
    for (int i = 0 ; i < n ; i++) st.emplace(xs[i], ys[i]);

    int res = 0;
    for (int i = 0 ; i < n ; i++) for (int j = 0 ; j < n ; j++) {
        if (i == j) continue;
        int vecx = xs[j] - xs[i], vecy = ys[j] - ys[i];
        if (!judge({vecx, vecy})) continue;
        pii a = add(make_pair(xs[i], ys[i]), {(vecx + vecy)/2, (-vecx + vecy)/2});
        pii b = add(make_pair(xs[i], ys[i]), {(vecx - vecy)/2, (vecx + vecy)/2});
        if (st.count(a) and st.count(b)) {
            int s = dot(diff(make_pair(xs[i], ys[i]), a));
            if (s > res) res = s;
        }
    }
    
    return res;
}

int main() {
    while(1) {
        int n; cin >> n;
        if (!n) break;
        cout << solve(n) << endl;
    }
}
accuracy: 1
time_ms: 1200
memory_kb: 3308
final_rank: 10

code_snippet: #include <bits/stdc++.h>

using namespace std;

using P = pair<int, int>;
using VP = vector<P>;
using Long = long long;

// 面積計算
Long area(VP& v) {
    sort(v.begin(), v.end());
    int max_x = 0, max_y = 0;
    int min_x = 50000, min_y = 50000;

    for (int i = 0; i < 4; ++i) {
        max_x = max(max_x, v[i].first);
        min_x = min(min_x, v[i].first);
        max_y = max(max_y, v[i].second);
        min_y = min(min_y, v[i].second);
    }
    Long outer_area = (max_x - min_x) * (max_y - min_y);
    Long triangle =
        abs(v[0].first - v[1].first) * abs(v[0].second - v[1].second);
    return (outer_area - triangle * 4 / 2);
}
// めぐる式二分探索
bool search(const VP& v, const P& x) {
    int left = -1;
    int right = (int)v.size();
    while (right - left > 1) {
        int mid = (left + right) / 2;
        if (v[mid] == x) {
            return true;
        } else if (v[mid] > x) {
            right = mid;
        } else {
            left = mid;
        }
    }
    return false;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

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

        VP p;

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

        sort(p.begin(), p.end());
        Long max_area = 0;
        for (int i = 0; i < n; ++i) {
            for (int j = i + 1; j < n; ++j) {
                int diff_x = abs(p[i].first - p[j].first);
                int diff_y = abs(p[i].second - p[j].second);
                P left_down =
                    make_pair(p[i].first - diff_y, p[i].second + diff_x);
                if (search(p, left_down)) {
                    P left_up =
                        make_pair(p[j].first - diff_y, p[j].second + diff_x);
                    if (search(p, left_up)) {
                        VP v = {p[i], p[j], left_down, left_up};
                        max_area = max(max_area, area(v));
                    }
                }
            }
        }
        cout << max_area << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 650
memory_kb: 3416
final_rank: 4

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
typedef long long ll;
typedef pair<int,int> P;


int main(void){
	int i,j,k;

	cin.tie(0);  ios_base::sync_with_stdio(false);

	while(1){
	int N;
	cin >> N;
	if(N==0) break;
	vector<P> v(N);
	set<P> s;
	for(i=0;i<N;i++){
		cin >> v[i].first >> v[i].second;
		s.insert(v[i]);
	}

	int mx=0;
	for(i=0;i<N;i++){
		for(j=i+1;j<N;j++){
			int x1=v[i].first,y1=v[i].second,x2=v[j].first,y2=v[j].second;
			P q1=make_pair(y1-y2+x1,x2-x1+y1),p1=make_pair(y1-y2+x2,x2-x1+y2);
			P q2=make_pair(y2-y1+x1,x1-x2+y1),p2=make_pair(y2-y1+x2,x1-x2+y2);
			if((s.count(p1) && s.count(q1)) || (s.count(p2) && s.count(q2))) mx=max(mx,(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));

		}
	}

	cout << mx << endl;

	}

	return 0;
}
accuracy: 1
time_ms: 1720
memory_kb: 3280
final_rank: 17

code_snippet: #include <stdio.h>
#include <unordered_set>
using namespace std;

int point[4096][2];
unordered_set<int> st;

int main(void) {
    int n, r, x, y, dx, dy;
    for (int tt = 0;; tt++) {
        scanf("%d", &n);
        if (n == 0) break;
        r = 0;
        for (int i = 0; i < n; i++) {
            scanf("%d %d", &point[i][0], &point[i][1]);
            st.insert((point[i][0] << 16) | point[i][1]);
        }
        for (int i = 0; i < n; i++) {
            x = point[i][0];
            y = point[i][1];
            for (int j = i + 1; j < n; j++) {
                dx = point[j][0] - x;
                dy = point[j][1] - y;
                if (st.find(((x + dy) << 16) | (y - dx)) != st.end() &&
                    st.find(((x + dx + dy) << 16) | (y - dx + dy)) != st.end()) {
                    if (dx * dx + dy * dy > r) r = dx * dx + dy * dy;
                }
                if (st.find(((x - dy) << 16) | (y + dx)) != st.end() &&
                    st.find(((x + dx - dy) << 16) | (y + dx + dy)) != st.end()) {
                    if (dx * dx + dy * dy > r) r = dx * dx + dy * dy;
                }
            }
        }
        printf("%d\n", r);
        st.clear();
    }
    return 0;
}
accuracy: 1
time_ms: 770
memory_kb: 2960
final_rank: 6

code_snippet: #include <stdio.h>
#include <set>
using namespace std;

int point[4096][2];
set<pair<int, int>> st;

int main(void) {
    int n, r, x, y, dx, dy;
    pair<int, int> p1, p2;
    for (int tt = 0;; tt++) {
        scanf("%d", &n);
        if (n == 0) break;
        r = 0;
        for (int i = 0; i < n; i++) {
            scanf("%d %d", &point[i][0], &point[i][1]);
            st.insert(pair<int, int>(point[i][0], point[i][1]));
        }
        for (int i = 0; i < n; i++) {
            x = point[i][0];
            y = point[i][1];
            for (int j = i + 1; j < n; j++) {
                dx = point[j][0] - x;
                dy = point[j][1] - y;
                p1.first = x + dy;
                p1.second = y - dx;
                p2.first = x + dx + dy;
                p2.second = y + dy - dx;
                if (st.find(p1) != st.end() &&
                    st.find(p2) != st.end()) {
                    if (dx * dx + dy * dy > r) r = dx * dx + dy * dy;
                }
                p1.first = x - dy;
                p1.second = y + dx;
                p2.first = x + dx - dy;
                p2.second = y + dx + dy;
                if (st.find(p1) != st.end() &&
                    st.find(p2) != st.end()) {
                    if (dx * dx + dy * dy > r) r = dx * dx + dy * dy;
                }
            }
        }
        printf("%d\n", r);
        st.clear();
    }
    return 0;
}
accuracy: 1
time_ms: 1550
memory_kb: 3024
final_rank: 14

code_snippet: #include <stdio.h>
#include <set>
using namespace std;

int point[4096][2];
set<pair<int, int>> st;

int main(void) {
    int n, r, x, y, dx, dy;
    for (int tt = 0;; tt++) {
        scanf("%d", &n);
        if (n == 0) break;
        r = 0;
        for (int i = 0; i < n; i++) {
            scanf("%d %d", &point[i][0], &point[i][1]);
            st.insert(pair<int, int>(point[i][0], point[i][1]));
        }
        for (int i = 0; i < n; i++) {
            x = point[i][0];
            y = point[i][1];
            for (int j = i + 1; j < n; j++) {
                dx = point[j][0] - x;
                dy = point[j][1] - y;
                if (st.find(make_pair(x + dy, y - dx)) != st.end() &&
                    st.find(make_pair(x + dx + dy, y + dy - dx)) != st.end()) {
                    if (dx * dx + dy * dy > r) r = dx * dx + dy * dy;
                }
                if (st.find(make_pair(x - dy, y + dx)) != st.end() &&
                    st.find(make_pair(x + dx - dy, y + dx + dy)) != st.end()) {
                    if (dx * dx + dy * dy > r) r = dx * dx + dy * dy;
                }
            }
        }
        printf("%d\n", r);
        st.clear();
    }
    return 0;
}
accuracy: 1
time_ms: 1610
memory_kb: 2956
final_rank: 16

code_snippet: #include "bits/stdc++.h"

#define REP(i,num) for(ll i=0;i<(num);++i)
#define FOR(i,c,num) for(ll (i)=(c);(i)<(num);++(i))
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
//using ll = long long;
using ll = int;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){ T x; cin >> x; return (x); }
template<typename T=ll,typename C=vector<T>>
C vecin(int N){ C x(N);REP(i,N){ x[i]=in<T>(); }return x; }
template<typename T=ll,size_t N>
array<T,N> arrin(){array<T,N> x;REP(i,N){ x[i]=in<T>(); }return x;}

void vout(){ cout << endl; }
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){ cout << ' ' << h;vout(forward<Tail>(t)...); }
void out(){ cout << endl; }
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){ cout << h;vout(forward<Tail>(t)...); }

template<typename T>
bool chmax(T& a,T b){ if(a<b){ a=b;return true; }return false; }
template<typename T>
bool chmin(T& a,T b){ if(a>b){ a=b;return true; }return false; }

ll search(vvll& M,pair<ll,ll>& start,pair<ll,ll>& end){
	ll area=0;
	pair<ll,ll> vect(end.first-start.first,end.second-start.second);

	bool exist = true;
	pair<ll,ll> now(end);
	for(int i=0;i<3;i++){
		swap(vect.first,vect.second);
		vect.second = -vect.second;
		pair<ll,ll> next(now.first+vect.first,now.second+vect.second);
		if(next.first<0 || next.second<0 || next.first>5000 || next.second>5000 || (!M[next.first][next.second])){
			exist = false;
			break;
		}
		now = next;
	}

	if(exist) area = (end.first-start.first)*(end.first-start.first)+(end.second-start.second)*(end.second-start.second);

	return area;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	while(true){
		ll N=in();
		if(!N) break;
		
		vvll M(5001,vll(5001,0));
		vector<pair<ll,ll>> P(N);
		REP(i,N){
			P[i].first=in(),P[i].second=in();
			M[P[i].first][P[i].second]=1;
		}

		ll maxA=0;
		REP(i,N){
			FOR(j,i+1,N){
				maxA = max(maxA,search(M,P[i],P[j]));
				maxA = max(maxA,search(M,P[j],P[i]));
			}
		}
		out(maxA);
	}
	return 0;
}
accuracy: 1
time_ms: 650
memory_kb: 101048
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;
const long long MOD1 = 1000000007;
const long long MOD2 = 998244353;
typedef long long ll;
typedef pair<long long, long long> P;
const long long INF = 1e18;
const ll MOD = INF;
template <typename T>
void input_arr(vector<T>& A, ll N) {
	for (ll i = 0; i < N; i++) {
		cin >> A[i];
	}
}
template <typename T, typename Q>
void input_arr(vector<pair<T, Q>>& A, ll N) {
	for (ll i = 0; i < N; i++) {
		cin >> A[i].first >> A[i].second;
	}
}
template <typename T>
void input_arr(vector<vector<T>>& A, ll H, ll W) {
	for (ll i = 0; i < H; i++) {
		for (ll j = 0; j < W; j++) {
			cin >> A[i][j];
		}
	}
}
int main() {
	ll N; cin >> N;
	while (N != 0) {
		vector<P>A(N); input_arr(A, N);
		vector<vector<bool>>Map(6000, vector<bool>(6000, false));
		for (ll i = 0; i < N; i++) {
			Map[A[i].first][A[i].second] = true;
		}
		ll ans = 0;
		for (ll i = 0; i < N; i++) {
			for (ll j = 0; j < N; j++) {
				if (i == j) continue;
				ll dx = A[i].first - A[j].first;
				ll dy = A[i].second - A[j].second;
				P point1 = {A[i].first - dy, A[i].second + dx};
				P point2 = {A[j].first - dy, A[j].second + dx};
				if (point1.first < 0 || point1.second < 0 || point2.first < 0 || point2.second < 0) continue;
				if (point1.first > 5000 || point1.second > 5000 || point2.first > 5000 || point2.second > 5000) continue;
				if (Map[point1.first][point1.second] && Map[point2.first][point2.second]) {
					ll S = (abs(dx) + abs(dy)) * (abs(dx) + abs(dy));
					S -= 2 * abs(dx) * abs(dy);
				    ans = max(ans, S);
				}
			}
		}
		cout << ans << endl;
		cin >> N;
	}
}
accuracy: 1
time_ms: 180
memory_kb: 8196
final_rank: 2

code_snippet: #include<cstdio>
#include<cstdlib>

using namespace std;

int main(){
	bool (*map)[5010] = (bool(*)[5010])malloc(5010*5010*sizeof(bool));
	int n,x[3010],y[3010],dx,dy,best=0;
	while(1){
		best=0;
		scanf("%d",&n);
		if(n==0) break;
		for(int i=0;i<n;i++){
			scanf("%d %d",&x[i],&y[i]);
			map[x[i]][y[i]]=true;
		}
		for(int i=0;i<n-1;i++){
			for(int j=i+1;j<n;j++){
				dx=x[j]-x[i];
				dy=y[j]-y[i];
				if(y[i]-dx>=0&&y[j]-dx>=0&&x[i]+dy>=0&&x[j]+dy>=0){
					if(y[i]-dx<=5000&&y[j]-dx<=5000&&x[i]+dy<=5000&&x[j]+dy<=5000){
						if(map[x[i]+dy][y[i]-dx]&&map[x[j]+dy][y[j]-dx]){
							if(best<dx*dx+dy*dy)best=dx*dx+dy*dy;
						}
					}
				}
				if(x[i]-dy>=0&&x[j]-dy>=0&&y[i]+dx>=0&&y[j]+dx>=0){
					if(x[i]-dy<=5000&&x[j]-dy<=5000&&y[i]+dx<=5000&&y[j]+dx<=5000){
						if(map[x[i]-dy][y[i]+dx]&&map[x[j]-dy][y[j]+dx]){
							if(best<dx*dx+dy*dy)best=dx*dx+dy*dy;
						}
					}
				}
			}
		}
		printf("%d\n",best);
	}
	return 0;
}
accuracy: 1
time_ms: 210
memory_kb: 22372
final_rank: 9

code_snippet: #include<iostream>
#include<set>
#include<cmath>

using namespace std;

int main()
{
	while (true)
	{
		int n;
		cin >> n;
		if (n == 0)
			break;
		int x, y;
		set<pair<int, int>> points;
		for (int i = 0; i < n; i++)
		{
			cin >> x >> y;
			points.insert(make_pair(x, y));
		}
		int ans = 0;
		for (auto iter1 = points.begin(); iter1 != points.end(); iter1++)
		{
			auto iter2 = iter1;
			while (++iter2 != points.end())
			{
				int x1 = iter1->first;
				int y1 = iter1->second;
				int x2 = iter2->first;
				int y2 = iter2->second;
				int dx = x2 - x1;
				int dy = y2 - y1;
				for (int i = 0; i <= 1; i++)
				{
					int x3 = x1 + int(pow(-1, i)) * dy;
					int y3 = y1 - int(pow(-1, i)) * dx;
					if (points.count(make_pair(x3, y3)) == 0)
						continue;
					int x4 = x2 + x3 - x1;
					int y4 = y2 + y3 - y1;
					if (points.count(make_pair(x4, y4)) != 0)
						ans = max(ans, dx * dx + dy * dy);
				}
			}
		}
		cout << ans << endl;
	}

	//system("pause");
}
accuracy: 1
time_ms: 2220
memory_kb: 3276
final_rank: 18

code_snippet: #include<stdio.h>
#include<string.h>
#include<iostream>

int x[3000];
int y[3000];
bool coordiate[5001][5001];
int n;

int max(int a, int b)
{
	return a > b ? a : b;
}

bool check(int y1, int x1)
{
	if (y1 >= 0 && y1 <= 5000 &&
		x1 >= 0 && x1 <= 5000)
	{
		return true;
	}
	return false;
}

int main()
{
	int dx, dy;
	int area;
	while (1)
	{
		std::cin >> n;
		if (n == 0) break;
		memset(coordiate, 0, sizeof(coordiate));
		area = 0;
		for (int i = 0; i < n; i++)
		{
			std::cin >> x[i] >> y[i];
			coordiate[y[i]][x[i]] = true;
		}

		for (int i = 0; i < n; i++)
		{
			for (int j = i + 1; j < n; j++)
			{
				dx = x[j] - x[i];
				dy = y[j] - y[i];
				if (check(y[i] - dx, x[i] + dy) && coordiate[y[i] - dx][x[i] + dy] == true &&
					check(y[j] - dx, x[j] + dy) && coordiate[y[j] - dx][x[j] + dy] == true)
				{
					area = max(area, dx * dx + dy * dy);
				}

				if (check(y[i] + dx, x[i] - dy) && coordiate[y[i] + dx][x[i] - dy] == true &&
					check(y[j] + dx, x[j] - dy) && coordiate[y[j] + dx][x[j] - dy] == true)
				{
					area = max(area, dx * dx + dy * dy);
				}
			}
		}
		std::cout << area << std::endl;
	}
}
accuracy: 1
time_ms: 210
memory_kb: 27524
final_rank: 11