acwing数据比洛谷数据强一点
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<list>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<deque>
using namespace std;
#define inf 0x3f3f3f3f
#define HH cout<<"\n";
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
const int N=1e5+5;
int x[N],y[N];
struct Node
{
int p,q;
}ca[N];
bool cmp(Node a,Node b)
{
return a.p<b.p;
}
int main()
{
int a,b,c,d;
cin>>a>>b>>c>>d;
int n;
cin>>n;
for(int i=1;i<=n;++i)
{
cin>>x[i]>>y[i];
int p=(x[i]-a)*(x[i]-a)+(y[i]-b)*(y[i]-b);
int q=(x[i]-c)*(x[i]-c)+(y[i]-d)*(y[i]-d);
ca[i]={p,q};
}
sort(ca+1,ca+n+1,cmp);
int res=1e9;
int r2=0;
for(int i=n;i>=0;--i)
{
r2=max(r2,ca[i+1].q);
res=min(res,ca[i].p+r2) ;
}
cout<<res;
return 0;
}