做法是题解里的非乱搞的人类智慧 set 做法
// Problem: A. 平面最近点对
// Contest: BNDSOJProblemParser
// URL: https://onlinejudge.bnds.cn/contest/problem?id=157
// Memory Limit: 512 MB
// Time Limit: 2 ms
#include<stdio.h>
#include<algorithm>
#include<set>
#include<cmath>
typedef long long ll;
struct node{
int x,y;
node(int a=0,int b=0):x(a),y(b){}
bool operator<(const node&o)const{return y<o.y;}
}a[400001];
ll dist(const node&x,const node&y){return (ll)(x.x-y.x)*(ll)(x.x-y.x)+(ll)(x.y-y.y)*(ll)(x.y-y.y);}
ll min(ll x,ll y){return x<y?x:y;}
std::multiset<node>S;
int main(){
int n;
scanf("%d",&n);
for(int i=1;i<=n;++i)scanf("%d%d",&a[i].x,&a[i].y);
std::sort(a+1,a+n+1,[](const node&x,const node&y){return x.x<y.x;});
ll d=dist(a[1],a[2]),j=1;
S.insert(a[1]),S.insert(a[2]);
for(int i=3;i<=n;++i){
for(;j<i&&d<(a[i].x-a[j].x)*(a[i].x-a[j].x);++j)S.erase(a[j]);
auto cur=S.insert(a[i]);
for(auto k=cur;(k--)!=S.begin()&&((k->y)-a[i].y)*((k->y)-a[i].y)<d;)d=min(d,dist(*k,a[i]));
for(auto k=cur;(++k)!=S.end()&&((k->y)-a[i].y)*((k->y)-a[i].y)<d;)d=min(d,dist(*k,a[i]));
}
printf("%lld",d);
return 0;
}