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

#if DEBUG && !ONLINE_JUDGE
    #define debug(args...)  (Debugger()),args
    class Debugger{
        public:
            Debugger(const string& _seperator = ", "):
                fi(true),seperator(_seperator){}
            template<typename T> Debugger& operator , (const T& v){
                if(!fi)
                    cerr<<seperator;
                cerr<<v;
                fi=false;
                return *this;
            }
            ~Debugger() {cerr<<endl;}
        private:
            bool fi;
            string seperator;
    };
    #define DBG(x) {cerr << #x << " = "; debug(x);}
    template<typename T> inline ostream& operator << (ostream& os,const vector<T>& v){
        bool fi=true;
        os<<"[";
        for(auto i:v){
            if(!fi)
                os<<", ";
            os<<i;
            fi=false;
        }
        return os<<"]";
    }
#else
    #define debug(args...)
    #define DBG(x)
#endif

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef map<int,int> mii;
typedef map<string,int> msi;
typedef long long lli;

#define pb push_back
#define IT iterator
#define PQ priority_queue
#define GI greater<int>
#define _1 first
#define _2 second
#define fi first
#define se second
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define REP(i,a) FOR(i,0,(int)(a)-1)
#define FORd(i,a,b) for(int i=(a);i>=(b);i--)
#define TR(c,it) for(auto it:(c))
#define all(x) x.begin(), x.end()
#define uni(x) x.erase(unique(all(x)), x.end())
#define sqr(x) ((x)*(x))
#define L(x) ((x)<<1)
#define R(x) (((x)<<1)+1)
#define EPS 1e-9
#define EULER 2.7182818284
#define MOD 1000000007

const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
template<typename T> inline T gcd(T a,T b) {if(a==0)return b;return gcd(b%a,a);}
template<typename T> inline void amin(T& x,T y) {if(x>y)x=y;}
template<typename T> inline void amax(T& x,T y) {if(x<y)x=y;}
class comp{
public:
    bool operator()(const ii& a, const ii& b){
        if(a.fi!=b.fi){
            return a._1<b._1;
        }else{
            return a._2>b._2;
        }
    }
};
//global variables

//end global variables

void preprocess(void){
    return;
}

int main(void){
    //freopen("output.txt","w",stdout);
    //freopen("input.txt","r",stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(20);
    preprocess();
    int teeee;
    //cin>>t;
    teeee=1;
    FOR(zeeee,1,teeee){
        //printf("Case #%d: ",z);
        string s,t;
        cin>>s>>t;
        int len=s.size();
        int q=0;
        vi s1(26,0),t1(26,0);
        REP(i,len){
            if(s[i]=='?'){
                q++;
            }else{
                s1[s[i]-'a']++;
            }
            t1[t[i]-'a']++;
        }
        int l=0,r=len;
        while(l<r){
            int m=(l+r)>>1;
            int tans=0;
            REP(i,26){
                tans+=t1[i]*m-min(t1[i]*m,s1[i]);
            }
            debug(l,r,tans,m,q);
            if(q==0){
                if(tans<=q){
                    l=0;
                    break;
                }
            }
            if(l==r-1){
                if(l==0){
                    l++;
                }
                break;
            }
            if(tans<=q){
                l=m;
            }else{
                r=m-1;
            }
        }
        int ind=0;
        int cur=0;
        REP(i,len){
            while(cur==0){
                cur=t1[ind]*l-min(t1[ind]*l,s1[ind]);
                if(ind>26){
                    break;
                }
                ind++;
            }
            debug(cur,ind);
            if(s[i]=='?'){
                if(ind>26){
                    ind=26;
                }
                s[i]='a'+ind-1;
                cur--;
            }
        }
        cout<<s<<endl;
    }
    return 0;
}


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

#if DEBUG && !ONLINE_JUDGE
    #define debug(args...)  (Debugger()),args
    class Debugger{
        public:
            Debugger(const string& _seperator = ", "):
                fi(true),seperator(_seperator){}
            template<typename T> Debugger& operator , (const T& v){
                if(!fi)
                    cerr<<seperator;
                cerr<<v;
                fi=false;
                return *this;
            }
            ~Debugger() {cerr<<endl;}
        private:
            bool fi;
            string seperator;
    };
    #define DBG(x) {cerr << #x << " = "; debug(x);}
    template<typename T> inline ostream& operator << (ostream& os,const vector<T>& v){
        bool fi=true;
        os<<"[";
        for(auto i:v){
            if(!fi)
                os<<", ";
            os<<i;
            fi=false;
        }
        return os<<"]";
    }
#else
    #define debug(args...)
    #define DBG(x)
#endif

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef map<int,int> mii;
typedef map<string,int> msi;
typedef long long lli;

#define pb push_back
#define IT iterator
#define PQ priority_queue
#define GI greater<int>
#define _1 first
#define _2 second
#define fi first
#define se second
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define REP(i,a) FOR(i,0,(int)(a)-1)
#define FORd(i,a,b) for(int i=(a);i>=(b);i--)
#define TR(c,it) for(auto it:(c))
#define all(x) x.begin(), x.end()
#define uni(x) x.erase(unique(all(x)), x.end())
#define sqr(x) ((x)*(x))
#define L(x) ((x)<<1)
#define R(x) (((x)<<1)+1)
#define EPS 1e-9
#define EULER 2.7182818284
#define MOD 1000000007

const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
template<typename T> inline T gcd(T a,T b) {if(a==0)return b;return gcd(b%a,a);}
template<typename T> inline void amin(T& x,T y) {if(x>y)x=y;}
template<typename T> inline void amax(T& x,T y) {if(x<y)x=y;}
class comp{
public:
    bool operator()(const ii& a, const ii& b){
        if(a.fi!=b.fi){
            return a._1<b._1;
        }else{
            return a._2>b._2;
        }
    }
};
//global variables

//end global variables

void preprocess(void){
    return;
}

int main(void){
    //freopen("output.txt","w",stdout);
    //freopen("input.txt","r",stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(20);
    preprocess();
    int teeee;
    //cin>>t;
    teeee=1;
    FOR(zeeee,1,teeee){
        //printf("Case #%d: ",z);
        string s,t;
        cin>>s>>t;
        int len=s.size();
        int q=0;
        vi s1(26,0),t1(26,0);
        REP(i,len){
            if(s[i]=='?'){
                q++;
            }else{
                s1[s[i]-'a']++;
            }
        }
        int re=t.size();
        REP(i,re){
            t1[t[i]-'a']++;
        }
        int l=0;
        while(l<=min(len,re)){
            int tans=0;
            REP(i,26){
                tans+=t1[i]*l-min(t1[i]*l,s1[i]);
            }
            DBG(tans);
            if(tans>q){
                l--;
                break;
            }
            l++;
        }
        DBG(l);
        int ind=0;
        int cur=0;
        REP(i,len){
            if(q==0){
                break;
            }
            while(cur==0){
                if(ind>=26){
                    ind=26;
                    break;
                }
                cur=t1[ind]*l-min(t1[ind]*l,s1[ind]);
                ind++;
            }
            debug(cur,ind);
            if(s[i]=='?'){
                s[i]='a'+ind-1;
                cur--;
            }
        }
        cout<<s<<endl;
    }
    return 0;
}


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

#if DEBUG && !ONLINE_JUDGE
    #define debug(args...)  (Debugger()),args
    class Debugger{
        public:
            Debugger(const string& _seperator = ", "):
                fi(true),seperator(_seperator){}
            template<typename T> Debugger& operator , (const T& v){
                if(!fi)
                    cerr<<seperator;
                cerr<<v;
                fi=false;
                return *this;
            }
            ~Debugger() {cerr<<endl;}
        private:
            bool fi;
            string seperator;
    };
    #define DBG(x) {cerr << #x << " = "; debug(x);}
    template<typename T> inline ostream& operator << (ostream& os,const vector<T>& v){
        bool fi=true;
        os<<"[";
        for(auto i:v){
            if(!fi)
                os<<", ";
            os<<i;
            fi=false;
        }
        return os<<"]";
    }
#else
    #define debug(args...)
    #define DBG(x)
#endif

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef map<int,int> mii;
typedef map<string,int> msi;
typedef long long lli;

#define pb push_back
#define IT iterator
#define PQ priority_queue
#define GI greater<int>
#define _1 first
#define _2 second
#define fi first
#define se second
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define REP(i,a) FOR(i,0,(int)(a)-1)
#define FORd(i,a,b) for(int i=(a);i>=(b);i--)
#define TR(c,it) for(auto it:(c))
#define all(x) x.begin(), x.end()
#define uni(x) x.erase(unique(all(x)), x.end())
#define sqr(x) ((x)*(x))
#define L(x) ((x)<<1)
#define R(x) (((x)<<1)+1)
#define EPS 1e-9
#define EULER 2.7182818284
#define MOD 1000000007

const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
template<typename T> inline T gcd(T a,T b) {if(a==0)return b;return gcd(b%a,a);}
template<typename T> inline void amin(T& x,T y) {if(x>y)x=y;}
template<typename T> inline void amax(T& x,T y) {if(x<y)x=y;}
class comp{
public:
    bool operator()(const ii& a, const ii& b){
        if(a.fi!=b.fi){
            return a._1<b._1;
        }else{
            return a._2>b._2;
        }
    }
};
//global variables

//end global variables

void preprocess(void){
    return;
}

int main(void){
    //freopen("output.txt","w",stdout);
    //freopen("input.txt","r",stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(20);
    preprocess();
    int teeee;
    //cin>>t;
    teeee=1;
    FOR(zeeee,1,teeee){
        //printf("Case #%d: ",z);
        string s,t;
        cin>>s>>t;
        int len=s.size();
        int q=0;
        vi s1(26,0),t1(26,0);
        REP(i,len){
            if(s[i]=='?'){
                q++;
            }else{
                s1[s[i]-'a']++;
            }
            t1[t[i]-'a']++;
        }
        int l=0,r=len;
        while(l<r){
            int m=(l+r)>>1;
            int tans=0;
            REP(i,26){
                tans+=t1[i]*m-min(t1[i]*m,s1[i]);
            }
            debug(l,r,tans,m,q);
            if(q==0){
                if(tans>q){
                    l=0;
                    break;
                }
            }
            if(l==r-1){
                if(l==0){
                    l++;
                }
                break;
            }
            if(tans<=q){
                l=m;
            }else{
                r=m-1;
            }
        }
        int ind=0;
        int cur=0;
        REP(i,len){
            while(cur==0){
                if(ind>=26){
                    break;
                }
                cur=t1[ind]*l-min(t1[ind]*l,s1[ind]);
                ind++;
            }
            debug(cur,ind);
            if(s[i]=='?'){
                if(ind>26){
                    ind=26;
                }
                s[i]='a'+ind-1;
                cur--;
            }
        }
        cout<<s<<endl;
    }
    return 0;
}


#include <cstdio>
#include <vector>
#include <queue>
#include <cstring>
#include <algorithm>
#include <stdexcept>
#include <iostream>
#include <string>
using namespace std;
char str[1000010];
int temp1[30],temp2[30];
int ans[30];
int main()
{
	memset(temp1,0,sizeof(temp1));
	memset(temp2,0,sizeof(temp2));
	memset(ans,0,sizeof(ans));
	cin.getline(str,1000010);
	char t;
	while((t=getchar())!='\n') temp2[t-'a']++;
	int len=strlen(str);
	int tt=0;
	for(int i=0;i<len;i++)
		if(str[i]=='?') tt++;
		else temp1[str[i]-'a']++;

	while(tt){
		for(int i=0;i<26;i++){
			if(temp1[i]>=temp2[i])
				temp1[i]-=temp2[i];
			else{
				int dis=temp2[i]-temp1[i];
				temp1[i]=0;
				if(dis<=tt){
					tt-=dis;
					ans[i]+=dis;
				}
				else{
					tt=0;
					ans[i]+=tt;
				}
			}
			if(!tt) break;
		}
	}
	int pos=0;
	for(int i=0;i<len;i++){
		if(str[i]=='?'){
			while(pos<26&&ans[pos]<=0) pos++;
			ans[pos]--;
			printf("%c",'a'+pos);
		}
		else
			printf("%c",str[i]);

	}
	printf("\n");
	return 0;
}


/*
 * Problem Solving OJ
 * 2018-03-14 C:Flowers
 */
#include <iostream>
using namespace std;

int n = 0, x1 = 0, y1 = 0, x2 = 0, y2 = 0;
int tx = 0, ty = 0;
long long min1 = -1, min2 = -1;
long long max1 = -1, max2 = -1;
long long dis1[2005] = {}, dis2[2005] = {};

bool isOK(long long r) {
  bool flag = true;
  long long r1 = 0, r2 = 0;
  for (int i = 0; i < n; ++i) {
    r1 = dis1[i];
    if (r1 > r) continue;
    r2 = r - dis1[i];
    flag = true;
    for (int j = 0; j < n; ++j) {
      if (dis1[j] > r1 && dis2[j] > r2) {
        flag = false;
        break;
      }
    }
    if (flag) {
      //cout << "(" << r1 << ", " << r2 << ")";
      return true;
    }
  }
  return false;
}

long long search(long long left, long long right) {
  long long mid = (left + right) / 2;

  //cout << "left:" << left << ", right:" << right
  //     << ", testing " << mid << "... ";

  if (mid == left) {
    if (isOK(mid)) {
      return mid;
    } else {
      return right;
    }
  } else {
    if (isOK(mid)) {
      //cout << "PASS" << endl;
      return search(left, mid);
    } else {
      //cout << "FAIL" << endl;
      return search(mid, right);
    }
  }
}

int main() {
  //freopen("test.in", "r", stdin);
  cin >> n >> x1 >> y1 >> x2 >> y2;
  //i = 0
  cin >> tx >> ty;
  dis1[0] = (tx - x1) * (tx - x1)
      + (ty - y1) * (ty - y1);
  dis2[0] = (tx - x2) * (tx - x2)
      + (ty - y2) * (ty - y2);
  min1 = dis1[0];
  min2 = dis2[0];
  max1 = dis1[0];
  max2 = dis2[0];

  for (int i = 1; i < n; i++) {
    cin >> tx >> ty;
    dis1[i] = (tx - x1) * (tx - x1)
        + (ty - y1) * (ty - y1);
    dis2[i] = (tx - x2) * (tx - x2)
        + (ty - y2) * (ty - y2);
    if (dis1[i] < min1) min1 = dis1[i];
    if (dis2[i] < min2) min2 = dis2[i];
    if (dis1[i] > max1) max1 = dis1[i];
    if (dis2[i] > max2) max2 = dis2[i];
  }

  cout << search(min1 + min2, max1 + max2);
  return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#define ll long long
using namespace std;
ll x[3000],y[3000];
ll dis(int i,int j)	{
	return (x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
}
int main()	{
	int n;
	cin>>n>>x[1]>>y[1]>>x[2]>>y[2];
	for(int i=1;i<=n;i++)
		cin>>x[i+2]>>y[i+2];
	ll ans=INT_MAX*INT_MAX;
	for(int i=1;i<=n;i++)	{
		ll ldis=dis(1,i+2);
		ll rdis=0;
		for(int j=1;j<=n;j++)
			if(ldis<dis(1,j+2))
				rdis=max(rdis,dis(2,j+2));
		ans=min(ans,ldis+rdis);
	}
	ll xdis=0;
	for(int j=1;j<=n;j++)	{
		xdis=max(xdis,dis(j+2,2));
	}
	ans=min(ans,xdis);
	cout<<ans<<endl;
}


#include <iostream>
#include <cstring>
using namespace std;

class node{
 public:
  long long int x;
  long long int y;
  long long int d1;
  long long int d2;
  bool exist;
  node(){
      exist = false;
  }
  node(int _x,int _y){
      x = _x,y = _y;
      exist = true;
  }
};

void initialize(int term);
void show(int term);
void distance(int m);
void sort(int term);
void jiaohuan(int n, int lun);
void showSort(int term);
void doSign(int lun,int term);
bool exmaine(int term);

node p1,p2;
node f[2000];
long long int s1[2][2000];
long long int s2[2][2000];
bool sign[2000];
long long int answer[2000+2];

int main(){
    int term(0);
    cin >> term;
    initialize(term);
    //show(term);

    //show(term);
    sort(term);
    //showSort(term);
    memset(answer,9223372036854775807 , sizeof(answer));
    for(int i(0);i < term;i++){
        memset(sign,0, sizeof(sign));
        doSign(i,term);
        for(int j(term-1);j > 0;j--){
            sign[s2[0][j]] = 1;
            if(exmaine(term) == true){
                answer[i] = s1[1][i] + s2[1][j];
                break;
            }
        }
        //memset(sign,0, sizeof(sign));
    }

    answer[term] = s1[1][0];
    answer[term+1] = s2[1][0];
    long long int min(9223372036854775807);
    for(int i(0);i < term+2;i++){
        if(answer[i] < min && answer[i] >= 0) min = answer[i];
    }
///*
    showSort(term);

    for(int i(0);i < term+2;i++){
        cout << answer[i] << " ";
    }
    cout << endl;
//*/
    cout << min;
}

void initialize(int term){
    int term1,term2,term3,term4;
    cin >> term1 >> term2 >> term3 >> term4;
    p1 = node(term1,term2);
    p2 = node(term3,term4);
    for(int i(0);i < term;i++){
        cin >> term1 >> term2;
        f[i] = node(term1,term2);
        distance(i);
        s1[0][i] = i, s2[0][i] = i;
        s1[1][i] = f[i].d1, s2[1][i] = f[i].d2;
    }
}

void show(int term){
    cout << p1.x << " " << p1.y << " " << p2.x << " " << p2.y << endl;
    for(int i(0);i < term;i++){
        cout << f[i].x << " " << f[i].y << " " << f[i].d1 << " " << f[i].d2 << endl;
    }
}

void distance(int m){
    f[m].d1 = (p1.x - f[m].x)*(p1.x - f[m].x) + (p1.y - f[m].y)*(p1.y - f[m].y);
    f[m].d2 = (p2.x - f[m].x)*(p2.x - f[m].x) + (p2.y - f[m].y)*(p2.y - f[m].y);
}

void sort(int term){
    for(int i(1);i < term;i++){
        for(int j(i); j >= 1; j--){
            if(s1[1][j-1] < s1[1][j]){
                jiaohuan(1,j);
            }
            if(s2[1][j-1] < s2[1][j]){
                jiaohuan(2,j);
            }
        }
    }
}

void jiaohuan(int n, int lun){
    if(n != 1 && n != 2){
        cout << "出错";
        return;
    }

    if(n == 1){
        long long int term0,term1;
        term0 = s1[0][lun-1];
        term1 = s1[1][lun-1];
        s1[0][lun-1] = s1[0][lun];
        s1[1][lun-1] = s1[1][lun];
        s1[0][lun]   = term0;
        s1[1][lun]   = term1;
    }

    if(n == 2){
        long long int term0,term1;
        term0 = s2[0][lun-1];
        term1 = s2[1][lun-1];
        s2[0][lun-1] = s2[0][lun];
        s2[1][lun-1] = s2[1][lun];
        s2[0][lun]   = term0;
        s2[1][lun]   = term1;
    }
}

void showSort(int term){
    for(int i(0);i < term;i++){
        cout << s1[0][i] << " " << s1[1][i] <<" " << s2[0][i] << " " << s2[1][i] << endl;
    }
}

void doSign(int lun,int term){
    for(int i(lun);i < term;i++){
        sign[s1[0][i]] = 1;
    }
}

bool exmaine(int term){
    for(int i(0);i < term;i++){
        if(sign[i] != 1){
            return false;
        }
    }

    return true;
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

struct flower {
	long long int x, y ;
	long long int dis1 ;
	long long int dis2 ;
};

bool compare(const flower &a, const flower & b) {
	return b.dis1<a.dis1;
}

int main()
{

		int n;
		long long int x1, y1;
		long long int x2, y2;
		vector<flower> fs;
		cin >> n >> x1 >> y1 >> x2 >> y2;
		for (int i = 0; i < n; ++i) {
			flower temp;
			cin >> temp.x >> temp.y;
			temp.dis1 = (temp.x - x1)*(temp.x - x1) + (temp.y - y1)*(temp.y - y1);
			temp.dis2 = (temp.x - x2)*(temp.x - x2) + (temp.y - y2)*(temp.y - y2);
			fs.push_back(temp);
		}
		sort(fs.begin(), fs.end(), compare);
		long long int R1 = 0, R2 = 0;
		long long int S = 0;
		for (int i = 0; i < n; ++i) {
			if (fs[i].dis2 >= R2) {
				R2 = fs[i].dis2;
			}
		}
		S = R2;
		for (int i = 0; i < n; ++i) {
			R1 = fs[i].dis1;
			R2 = 0;
			for (int j = 0; j < i; ++j) {
				if (fs[j].dis2 >= R2) {
					R2 = fs[j].dis2;
				}
			}
			if (R1 + R2 <= S) {
				S = R1 + R2;
			}
		}

		cout << S;

    return 0;
}


#include<stdio.h>

#define NUMFLOWER 2000

typedef struct {
	int x;
	int y;
} point;

typedef struct {
	point coor;
	long long d1;
	long long d2;
} flowers;

void ReadInAndPre(int *NumP, point* fount1, point* fount2, flowers* flower);
void MergeSort(flowers* flower, flowers* tmp, int (*Dis1)(flowers, flowers), int s, int e);
void GetMin(long long *MinDis, flowers* flower, int NumP);
void Merge(flowers* flower, flowers* tmp, int(*Dis1)(flowers, flowers), int s, int e);
int Dis1(flowers, flowers);
int Dis2(flowers, flowers);
void GetMin2(long long *MinDis, flowers* flower, int NumP);
int min(int a, int b);
int max(int a, int b);

int main()
{
	flowers flower[NUMFLOWER + 5], tmp[NUMFLOWER + 5];
	int NumP = 0;
   	long long MinDis, MinDis2;
	point fount1, fount2;

	ReadInAndPre(&NumP, &fount1, &fount2, flower);
	if (NumP == 1) {
		if (flower[0].d1 < flower[0].d2) {
			printf("%lld\n", flower[0].d1);
		}
		else {
			printf("%lld\n", flower[0].d2);
		}
		return 0;
	}
	MergeSort(flower, tmp, Dis1, 0, NumP - 1);
	GetMin(&MinDis, flower, NumP);
	MergeSort(flower, tmp, Dis2, 0, NumP - 1);
	GetMin2(&MinDis2, flower, NumP);
	if (MinDis < MinDis2) {
		printf("%lld\n", MinDis);
	}
	else {
		printf("%lld\n", MinDis2);
	}

	return 0;
}

int min(int a, int b)
{
	if (a < b) {
		return a;
	}
	return b;
}

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

void ReadInAndPre(int *NumP, point* fount1, point* fount2, flowers* flower) {
	scanf("%d", NumP);
	scanf("%d %d %d %d", &fount1->x, &fount1->y, &fount2->x, &fount2->y);
	for (int i = 0; i < *NumP; i++) {
		scanf("%d %d", &flower[i].coor.x, &flower[i].coor.y);
		flower[i].d1 = (flower[i].coor.x - fount1->x) * (flower[i].coor.x - fount1->x) + (flower[i].coor.y - fount1->y) * (flower[i].coor.y - fount1->y);
		flower[i].d2 = (flower[i].coor.x - fount2->x) * (flower[i].coor.x - fount2->x) + (flower[i].coor.y - fount2->y) * (flower[i].coor.y - fount2->y);
	}
}

void MergeSort(flowers* flower, flowers* tmp, int (*Dis)(flowers, flowers), int s, int e) {
	if (s >= e) {
		return;
	}
	int mid = (s + e) / 2;
	MergeSort(flower, tmp, Dis, s, mid);
	MergeSort(flower, tmp, Dis, mid + 1, e);
	Merge(flower, tmp, Dis, s, e);
}

void GetMin(long long *MinDis, flowers* flower, int NumP)
{
	*MinDis = 10000000000000000;
	for (int i = 0; i < NumP; i++) {
		int Max = 0;
		for (int j = 0; j < i; j++) {
			Max = max(Max, flower[j].d2);
		}
		*MinDis = min(*MinDis, Max + flower[i].d1);
	}
}

void Merge(flowers* flower, flowers* tmp, int(*Dis1)(flowers, flowers), int s, int e)
{
	int mid = (s + e) / 2;
	int i = s, j = mid + 1, index = s;

	while (i <= mid && j <= e) {
		while (j <= e && i <= mid && Dis1(flower[i], flower[j])) {
			tmp[index] = flower[i];
			index++;
			i++;
		}
		while (j <= e && i <= mid && Dis1(flower[j], flower[i])) {
			tmp[index] = flower[j];
			index++;
			j++;
		}
	}
	while (i <= mid) {
		tmp[index] = flower[i];
		index++;
		i++;
	}
	while (j <= e) {
		tmp[index] = flower[j];
		index++;
		j++;
	}
	for (int i = s; i <= e; i++) {
		flower[i] = tmp[i];
	}
}

int Dis1(flowers a, flowers b) {
	if (a.d1 > b.d1) {
		return 1;
	}
	else if (a.d1 == b.d1 && a.d2 >= b.d2) {
		return 1;
	}
	return 0;
}

int Dis2(flowers a, flowers b) {
	if (a.d2 > b.d2) {
		return 1;
	}
	else if (a.d2 == b.d2 && a.d1 >= b.d1) {
		return 1;
	}
	return 0;
}

void GetMin2(long long *MinDis, flowers* flower, int NumP)
{
	*MinDis = 10000000000000000;
	for (int i = 0; i < NumP; i++) {
		int Max = 0;
		for (int j = 0; j < i; j++) {
			Max = max(Max, flower[j].d1);
		}
		*MinDis = min(*MinDis, Max + flower[i].d2);
	}
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <iomanip>
typedef long long LL;
using namespace std;
struct node{
    int x,y;
};
node p[3000], p1, p2;

int dis(node a,node b)
{
    return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}

bool cmp(node a, node b)
{
    return dis(a,p1)>dis(b,p1);
}

int main(){
    int n;
    cin >> n >> p1.x >> p1.y >> p2.x >> p2.y;
    for (int i=0;i<n;i++)
        cin >> p[i].x >> p[i].y;

    sort(p,p+n,cmp);
    p[n] = p1;

    int min = dis(p1, p[0]);
    int max = 0;
    for (int i = 0; i < n; i++)
    {
        if (dis(p2, p[i]) > max)
            max = dis(p2, p[i]);
        if (max + dis(p1, p[i + 1]) < min)
            min = max + dis(p1, p[i + 1]);
    }
    cout << min;
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
#define ll __int64
struct node
{
    ll dis1,dis2;
}a[12121];
ll dis(ll x,ll y,ll x2,ll y2)
{
    ll tmp1=(x-x2)*(x-x2)+(y-y2)*(y-y2);
    return tmp1;
}
int cmp(node a,node b)
{
    if(a.dis2==b.dis2)return a.dis1>b.dis1;
    else return a.dis2>b.dis2;
}
int cmp2(node a,node b)
{
    if(a.dis1==b.dis1)return a.dis2>b.dis2;
    else return a.dis1>b.dis1;
}
int main()
{
    int n;
    ll x1,y1,x2,y2;
    while(~scanf("%d%I64d%I64d%I64d%I64d",&n,&x1,&y1,&x2,&y2))
    {
        for(int i=0;i<n;i++)
        {
            ll x,y;
            scanf("%I64d%I64d",&x,&y);
            a[i].dis1=dis(x,y,x1,y1);
            a[i].dis2=dis(x,y,x2,y2);
        }
        sort(a,a+n,cmp);
        ll ans=100000000000000000;
        for(int i=0;i<n;i++)
        {
            ll tmpmaxn=0;
            for(int j=0;j<i;j++)
            {
                tmpmaxn=max(tmpmaxn,a[j].dis1);
            }
            ans=min(ans,tmpmaxn+a[i].dis2);
        }
        sort(a,a+n,cmp2);
        for(int i=0;i<n;i++)
        {
            ll tmpmaxn=0;
            for(int j=0;j<i;j++)
            {
                tmpmaxn=max(tmpmaxn,a[j].dis2);
            }
            ans=min(ans,tmpmaxn+a[i].dis1);
        }
        printf("%I64d\n",ans);
    }
}


#include<iostream>
#include<cmath>
#include<algorithm>
typedef struct {
    long long x;
    long long y;
} Pos;
int main() {
    long long n = 0;
    long long d1[2000] = {}, d2[2000];
    Pos m1, m2;
    Pos f[2000] = {};
    std::cin >> n >> m1.x >> m1.y >> m2.x >> m2.y;
    long long t2 = 0;
    for (int i = 0; i < n; i++) {
        std::cin >> f[i].x >> f[i].y;
        d1[i] = pow(m1.x - f[i].x, 2) + pow(m1.y - f[i].y, 2);
        d2[i] = pow(m2.x - f[i].x, 2) + pow(m2.y - f[i].y, 2);
        t2 = std::max(t2, d2[i]);
    }
    long long minans = 9223372036854775807;
    for (int i = 0; i < n; i++) {
        long long t=0;
        for (int j = 0; j < n; j++) {
            if (d1[j] > d1[i])
                t = std::max(t, d2[j]);
        }
        minans = std::min(minans, d1[i] + t);
    }
    std::cout << std::min(minans, t2);
}


#include <iostream>
#include <cstring>
using namespace std;

class node{
 public:
  int x;
  int y;
  long long int d1;
  long long int d2;
  bool exist;
  node(){
      exist = false;
  }
  node(int _x,int _y){
      x = _x,y = _y;
      exist = true;
  }
};

void initialize(int term);
void show(int term);
void distance(int m);
void sort(int term);
void jiaohuan(int n, int lun);
void showSort(int term);
void doSign(int lun,int term);
bool exmaine(int term);

node p1,p2;
node f[2000];
long long int s1[2][2000];
long long int s2[2][2000];
bool sign[2000];
long long int answer[2000+2];

int main(){
    int term(0);
    cin >> term;
    initialize(term);
    //show(term);

    //show(term);
    sort(term);
    //showSort(term);
    memset(answer,2147483647 , sizeof(answer));
    for(int i(0);i < term;i++){
        memset(sign,0, sizeof(sign));
        doSign(i,term);
        for(int j(term-1);j > 0;j--){
            sign[s2[0][j]] = 1;
            if(exmaine(term) == true){
                answer[i] = s1[1][i] + s2[1][j];
                break;
            }
        }
        memset(sign,-1, sizeof(sign));
    }

    answer[term] = s1[1][0];
    answer[term+1] = s2[1][0];
    long long int min(2147483647);
    for(int i(0);i < term+2;i++){
        if(answer[i] < min) min = answer[i];
    }
/*
    showSort(term);

    for(int i(0);i < term+2;i++){
        cout << answer[i] << " ";
    }
    cout << endl;
*/
    cout << min;
}

void initialize(int term){
    int term1,term2,term3,term4;
    cin >> term1 >> term2 >> term3 >> term4;
    p1 = node(term1,term2);
    p2 = node(term3,term4);
    for(int i(0);i < term;i++){
        cin >> term1 >> term2;
        f[i] = node(term1,term2);
        distance(i);
        s1[0][i] = i, s2[0][i] = i;
        s1[1][i] = f[i].d1, s2[1][i] = f[i].d2;
    }
}

void show(int term){
    cout << p1.x << " " << p1.y << " " << p2.x << " " << p2.y << endl;
    for(int i(0);i < term;i++){
        cout << f[i].x << " " << f[i].y << " " << f[i].d1 << " " << f[i].d2 << endl;
    }
}

void distance(int m){
    f[m].d1 = (p1.x - f[m].x)*(p1.x - f[m].x) + (p1.y - f[m].y)*(p1.y - f[m].y);
    f[m].d2 = (p2.x - f[m].x)*(p2.x - f[m].x) + (p2.y - f[m].y)*(p2.y - f[m].y);
}

void sort(int term){
    for(int i(1);i < term;i++){
        for(int j(i); j >= 1; j--){
            if(s1[1][j-1] < s1[1][j]){
                jiaohuan(1,j);
            }
            if(s2[1][j-1] < s2[1][j]){
                jiaohuan(2,j);
            }
        }
    }
}

void jiaohuan(int n, int lun){
    if(n != 1 && n != 2){
        cout << "出错";
        return;
    }

    if(n == 1){
        long long int term0,term1;
        term0 = s1[0][lun-1];
        term1 = s1[1][lun-1];
        s1[0][lun-1] = s1[0][lun];
        s1[1][lun-1] = s1[1][lun];
        s1[0][lun]   = term0;
        s1[1][lun]   = term1;
    }

    if(n == 2){
        long long int term0,term1;
        term0 = s2[0][lun-1];
        term1 = s2[1][lun-1];
        s2[0][lun-1] = s2[0][lun];
        s2[1][lun-1] = s2[1][lun];
        s2[0][lun]   = term0;
        s2[1][lun]   = term1;
    }
}

void showSort(int term){
    for(int i(0);i < term;i++){
        cout << s1[0][i] << " " << s1[1][i] <<" " << s2[0][i] << " " << s2[1][i] << endl;
    }
}

void doSign(int lun,int term){
    for(int i(lun);i < term;i++){
        sign[s1[0][i]] = 1;
    }
}

bool exmaine(int term){
    for(int i(0);i < term;i++){
        if(sign[i] != 1){
            return false;
        }
    }

    return true;
}


#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <vector>
struct cor{
	int x,y;
};
class hi{
public:
	long long a,b;
	bool operator <(const hi&i)const{return (a<i.a)||((a==i.a)&&(b<i.b));}
};
using std::vector;
int main(){
	cor f1,f2;
	vector <cor>flower;
	vector <hi>dis;
	cor tempc;
	hi temph;
	int i,j,n;
	long long r1=0,r2=0;
	long long ans=0,temp=0;
	scanf("%d%d%d%d%d",&n,&f1.x,&f1.y,&f2.x,&f2.y);
	for(i=0;i<n;++i){
		scanf("%d%d",&tempc.x,&tempc.y);
		flower.push_back(tempc);
		temph.a=pow(flower[i].x-f1.x,2)+pow(flower[i].y-f1.y,2);
		temph.b=pow(flower[i].x-f2.x,2)+pow(flower[i].y-f2.y,2);
		dis.push_back(temph);
	}
	std::sort(dis.begin(),dis.end());
	ans=dis[i].a;
	r2=0;
	for(i=n-1;i>=0;--i){
		r1=dis[i].a;
		temp=r1+r2;
		if(temp<ans){
			ans=temp;
		}
//		printf("T%d\t%d\t%d\n",r1,r2,temp);
		if(dis[i].b>r2){
			r2=dis[i].b;
		}
	}
	if(r2<ans){
		ans=r2;
	}
	printf("%d",ans);
}


#include<iostream>
#include <cmath>
using namespace std;
int main()
{
	long n,x1,y1,x2,y2;
	cin>>n>>x1>>y1>>x2>>y2;
	long long coord[2003][2];
	for(int i=0;i<n;i++)
	{
		cin>>coord[i][0]>>coord[i][1];
	}//输入

	long long dist[2003][2];
	for (int i=0;i<n;i++)//与A喷泉距离平方
	{
		dist[i][0]=(coord[i][0]-x1)*(coord[i][0]-x1)+(coord[i][1]-y1)*(coord[i][1]-y1);
	}

	for (int i=0;i<n;i++)//与A喷泉距离平方
	{
		dist[i][1]=(coord[i][0]-x2)*(coord[i][0]-x2)+(coord[i][1]-y2)*(coord[i][1]-y2);
	}

	long long best=9223372036854775807;

	for(int i=0;i<n+1;i++)
	{
		long long r2=0;
		for (int j=0;j<n;j++)
		{
			if(dist[j][0]>dist[i][0])
			{
				r2=max(r2,dist[j][1]);
			}
		}
		best=min(best,dist[i][0]+r2);
	}
	cout<<best<<endl;
	return 0;
}


#include<stdio.h>

#define NUMFLOWER 2000

typedef struct {
	int x;
	int y;
} point;

typedef struct {
	point coor;
	long long d1;
	long long d2;
} flowers;

void ReadInAndPre(int *NumP, point* fount1, point* fount2, flowers* flower);
void MergeSort(flowers* flower, flowers* tmp, int (*Dis1)(flowers, flowers), int s, int e);
void GetMin(long long *MinDis, flowers* flower, int NumP);
void Merge(flowers* flower, flowers* tmp, int(*Dis1)(flowers, flowers), int s, int e);
int Dis1(flowers, flowers);

int main()
{
	flowers flower[NUMFLOWER + 5], tmp[NUMFLOWER + 5];
	int NumP = 0;
   	long long MinDis;
	point fount1, fount2;

	ReadInAndPre(&NumP, &fount1, &fount2, flower);
	MergeSort(flower, tmp, Dis1, 0, NumP - 1);
	GetMin(&MinDis, flower, NumP);
	printf("%lld\n", MinDis);

	return 0;
}

void ReadInAndPre(int *NumP, point* fount1, point* fount2, flowers* flower) {
	scanf("%d", NumP);
	scanf("%d %d %d %d", &fount1->x, &fount1->y, &fount2->x, &fount2->y);
	for (int i = 0; i < *NumP; i++) {
		scanf("%d %d", &flower[i].coor.x, &flower[i].coor.y);
		flower[i].d1 = (flower[i].coor.x - fount1->x) * (flower[i].coor.x - fount1->x) + (flower[i].coor.y - fount1->y) * (flower[i].coor.y - fount1->y);
		flower[i].d2 = (flower[i].coor.x - fount2->x) * (flower[i].coor.x - fount2->x) + (flower[i].coor.y - fount2->y) * (flower[i].coor.y - fount2->y);
	}
	//puts("ReadInAndPre Done!");
}

void MergeSort(flowers* flower, flowers* tmp, int (*Dis)(flowers, flowers), int s, int e) {
	if (s >= e) {
		return;
	}
	int mid = (s + e) / 2;
	MergeSort(flower, tmp, Dis, s, mid);
	MergeSort(flower, tmp, Dis, mid + 1, e);
	Merge(flower, tmp, Dis, s, e);
}

void GetMin(long long *MinDis, flowers* flower, int NumP)
{
	*MinDis = flower[NumP - 1].d1;
	for (int i = NumP - 2; i >= 0; i--) {
		if (flower[i].d2 < flower[i + 1].d2) {
			flower[i].d2 = flower[i + 1].d2;
		}
	}
	for (int i = 0; i < NumP - 1; i++) {
		if (*MinDis > flower[i].d1 + flower[i + 1].d2) {
			*MinDis = flower[i].d1 + flower[i + 1].d2;
		}
	}
}

void Merge(flowers* flower, flowers* tmp, int(*Dis1)(flowers, flowers), int s, int e)
{
	int mid = (s + e) / 2;
	int i = s, j = mid + 1, index = s;

	//puts("Merge Begin!");
	while (i <= mid && j <= e) {
		//printf("%d %d \n", i , j);
		while (j <= e && i <= mid && Dis1(flower[i], flower[j])) {
			tmp[index] = flower[i];
			index++;
			i++;
		}
		while (j <= e && i <= mid && Dis1(flower[j], flower[i])) {
			tmp[index] = flower[j];
			index++;
			j++;
		}
	}
	//	printf("%d %d \n", i , j);
	while (i <= mid) {
		tmp[index] = flower[i];
		index++;
		i++;
	}
	while (j <= e) {
		tmp[index] = flower[j];
		index++;
		j++;
	}
	for (int i = s; i <= e; i++) {
		flower[i] = tmp[i];
	}
	//	printf("%d %d \n", i , j);
}

int Dis1(flowers a, flowers b) {
	return a.d1 <= b.d1;
}


#include<iostream>
long long int dis(long long int x1, long long int y1, long long int x2, long long int y2);
using namespace std;
int main()
{
	long long int n, x1, y1, x2, y2;
	cin >> n >> x1 >> y1 >> x2 >> y2;
	int i, j, k;
	long long int w, z, t;
	long long int t1max = 0, t2max = 0;
	long long int t1[2003] = { 0 };
	long long int t2[2003] = { 0 };
	long long int r1[2003] = { 0 };
	long long int r2[2003] = { 0 };
	long long int r[2003] = { 0 };
	long long int min = 10000000000000000;
	for (i = 0; i < n; i++)
	{
		cin >> w >> z;
		t1[i] = dis(x1, y1, w, z);
		t2[i] = dis(x2, y2, w, z);
		if (t1max < t1[i])
			t1max = t1[i];
		if (t2max < t2[i])
			t2max = t2[i];
	}
	t1[i] = 0, t2[i] = t2max;
	i++, n++;
	t1[i] = t1max, t2[i] = 0;
	i++, n++;
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < n; j++)
		{
			if (t1[j]>t1[i])
			if (t2[j]>r[i])
				r[i] = t2[j];
		}
		r[i] = r[i] + t1[i];
	}
	for (i = 0; i < n;i++)
	if (min > r[i])
		min = r[i];
	cout << min;
}
long long int dis(long long int x1, long long int y1, long long int x2, long long int y2)
{
	return (x2 - x1)*(x2 - x1) + (y1 - y2)*(y1 - y2);
}


#include<stdio.h>

#define NUMFLOWER 2000

typedef struct {
	int x;
	int y;
} point;

typedef struct {
	point coor;
	long long d1;
	long long d2;
} flowers;

void ReadInAndPre(int *NumP, point* fount1, point* fount2, flowers* flower);
void MergeSort(flowers* flower, flowers* tmp, int (*Dis1)(flowers, flowers), int s, int e);
void GetMin(long long *MinDis, flowers* flower, int NumP);
void Merge(flowers* flower, flowers* tmp, int(*Dis1)(flowers, flowers), int s, int e);
int Dis1(flowers, flowers);
int Dis2(flowers, flowers);
void GetMin2(long long *MinDis, flowers* flower, int NumP);

int main()
{
	flowers flower[NUMFLOWER + 5], tmp[NUMFLOWER + 5];
	int NumP = 0;
   	long long MinDis, MinDis2;
	point fount1, fount2;

	ReadInAndPre(&NumP, &fount1, &fount2, flower);
	if (NumP == 1) {
		if (flower[0].d1 < flower[0].d2) {
			printf("%lld\n", flower[0].d1);
		}
		else {
			printf("%lld\n", flower[0].d2);
		}
		return 0;
	}
	MergeSort(flower, tmp, Dis1, 0, NumP - 1);
	GetMin(&MinDis, flower, NumP);
	MergeSort(flower, tmp, Dis2, 0, NumP - 1);
	GetMin2(&MinDis2, flower, NumP);
	if (MinDis < MinDis2) {
		printf("%lld\n", MinDis);
	}
	else {
		printf("%lld\n", MinDis2);
	}

	return 0;
}

void ReadInAndPre(int *NumP, point* fount1, point* fount2, flowers* flower) {
	scanf("%d", NumP);
	scanf("%d %d %d %d", &fount1->x, &fount1->y, &fount2->x, &fount2->y);
	for (int i = 0; i < *NumP; i++) {
		scanf("%d %d", &flower[i].coor.x, &flower[i].coor.y);
		flower[i].d1 = (flower[i].coor.x - fount1->x) * (flower[i].coor.x - fount1->x) + (flower[i].coor.y - fount1->y) * (flower[i].coor.y - fount1->y);
		flower[i].d2 = (flower[i].coor.x - fount2->x) * (flower[i].coor.x - fount2->x) + (flower[i].coor.y - fount2->y) * (flower[i].coor.y - fount2->y);
	}
	//puts("ReadInAndPre Done!");
}

void MergeSort(flowers* flower, flowers* tmp, int (*Dis)(flowers, flowers), int s, int e) {
	if (s >= e) {
		return;
	}
	int mid = (s + e) / 2;
	MergeSort(flower, tmp, Dis, s, mid);
	MergeSort(flower, tmp, Dis, mid + 1, e);
	Merge(flower, tmp, Dis, s, e);
}

void GetMin(long long *MinDis, flowers* flower, int NumP)
{
	*MinDis = flower[NumP - 1].d1;
	/*for (int i = NumP - 2; i >= 0; i--) {
		if (flower[i].d2 < flower[i + 1].d2) {
			flower[i].d2 = flower[i + 1].d2;
		}
	}*/
	/*if (flower[0].d2 < *MinDis) {
		*MinDis = flower[0].d2;
	}*/
	int d2Max = 0;
	for (int i = 0; i < NumP; i++) {
		if (d2Max < flower[i].d2) {
			d2Max = flower[i].d2;
		}
	}
	if (d2Max < *MinDis) {
		*MinDis = d2Max;
	}
	for (int i = 0; i < NumP - 1; i++) {
		/*if (*MinDis > flower[i].d1 + flower[i + 1].d2) {
			*MinDis = flower[i].d1 + flower[i + 1].d2;
		}*/
		int j = i + 1, Max = 0;
		while (flower[j].d1 == flower[i].d1) {
			j++;
		}
		while (j < NumP) {
			if (Max < flower[j].d2) {
				Max = flower[j].d2;
			}
			j++;
		}
		if (*MinDis > flower[i].d1 + Max) {
			*MinDis = flower[i].d1 + Max;
		}
	}
}

void Merge(flowers* flower, flowers* tmp, int(*Dis1)(flowers, flowers), int s, int e)
{
	int mid = (s + e) / 2;
	int i = s, j = mid + 1, index = s;

	//puts("Merge Begin!");
	while (i <= mid && j <= e) {
		//printf("%d %d \n", i , j);
		while (j <= e && i <= mid && Dis1(flower[i], flower[j])) {
			tmp[index] = flower[i];
			index++;
			i++;
		}
		while (j <= e && i <= mid && Dis1(flower[j], flower[i])) {
			tmp[index] = flower[j];
			index++;
			j++;
		}
	}
	//	printf("%d %d \n", i , j);
	while (i <= mid) {
		tmp[index] = flower[i];
		index++;
		i++;
	}
	while (j <= e) {
		tmp[index] = flower[j];
		index++;
		j++;
	}
	for (int i = s; i <= e; i++) {
		flower[i] = tmp[i];
	}
	//	printf("%d %d \n", i , j);
}

int Dis1(flowers a, flowers b) {
	if (a.d1 < b.d1) {
		return 1;
	}
	else if (a.d1 == b.d1 && a.d2 >= b.d2) {
		return 1;
	}
	return 0;
}

int Dis2(flowers a, flowers b) {
	if (a.d2 < b.d2) {
		return 1;
	}
	else if (a.d2 == b.d2 && a.d1 >= b.d1) {
		return 1;
	}
	return 0;
}

void GetMin2(long long *MinDis, flowers* flower, int NumP)
{
	*MinDis = flower[NumP - 1].d2;
	/*for (int i = NumP - 2; i >= 0; i--) {
		if (flower[i].d2 < flower[i + 1].d2) {
			flower[i].d2 = flower[i + 1].d2;
		}
	}*/
	/*if (flower[0].d2 < *MinDis) {
		*MinDis = flower[0].d2;
	}*/
	int d1Max = 0;
	for (int i = 0; i < NumP; i++) {
		if (d1Max < flower[i].d1) {
			d1Max = flower[i].d1;
		}
	}
	if (d1Max < *MinDis) {
		*MinDis = d1Max;
	}
	for (int i = 0; i < NumP - 1; i++) {
		/*if (*MinDis > flower[i].d1 + flower[i + 1].d2) {
			*MinDis = flower[i].d1 + flower[i + 1].d2;
		}*/
		int j = i + 1, Max = 0;
		while (flower[j].d2 == flower[i].d2) {
			j++;
		}
		while (j < NumP) {
			if (Max < flower[j].d1) {
				Max = flower[j].d1;
			}
			j++;
		}
		if (*MinDis > flower[i].d2 + Max) {
			*MinDis = flower[i].d2 + Max;
		}
	}
}


#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    int n;
    long long int x1,y1,x2,y2;
    long long int firstfountain[2005];
    long long int secondfoutain[2005];
    long long int r1,r2,max1=0;
    while(cin>>n>>x1>>y1>>x2>>y2)
    {
        for(int i=0;i<n;i++)
        {
            cin>>firstfountain[i]>>secondfoutain[i];
        }
        for(int i=0;i<n;i++)
        {
            long long int mix=0;
            r1=pow(firstfountain[i]-x1,2)+pow(secondfoutain[i]-y1,2);
            for(int j=0;j<n;j++)
            {
                if(j!=i)
                {
                    r2=pow(firstfountain[j]-x2,2)+pow(secondfoutain[j]-y2,2);
                    if(pow(firstfountain[j]-x1,2)+pow(secondfoutain[j]-y1,2)>r1)
                    {
                        if(r2>=mix)
                            mix=r2;
                    }
                }
            }
            if(i==0)
                max1=mix+r1;
            else {
                if (max1 > mix + r1) {
                    max1=mix+r1;
                }
            }
        }
        long long int max=0;
        for(int i=0;i<n;i++)
        {
            long long int mix=0;
            r2=pow(firstfountain[i]-x2,2)+pow(secondfoutain[i]-y2,2);
            for(int j=0;j<n;j++)
            {
                if(j!=i)
                {
                    r1=pow(firstfountain[j]-x1,2)+pow(secondfoutain[j]-y1,2);
                    if(pow(firstfountain[j]-x2,2)+pow(secondfoutain[j]-y2,2)>r2)
                    {
                        if(r1>=mix)
                            mix=r1;
                    }
                }
            }
            if(i==0)
                max=mix+r2;
            else {
                if (max > mix + r2) {
                    max=mix+r2;
                }
            }
        }

        //cout<<max<<" "<<max1<<endl;
        if(max1>=max)
            cout<<max<<endl;
        else
            cout<<max1<<endl;
    }
    return 0;
}


#include<stdio.h>

#define NUMFLOWER 2000

typedef struct {
	int x;
	int y;
} point;

typedef struct {
	point coor;
	long long d1;
	long long d2;
} flowers;

void ReadInAndPre(int *NumP, point* fount1, point* fount2, flowers* flower);
void MergeSort(flowers* flower, flowers* tmp, int (*Dis1)(flowers, flowers), int s, int e);
void GetMin(long long *MinDis, flowers* flower, int NumP);
void Merge(flowers* flower, flowers* tmp, int(*Dis1)(flowers, flowers), int s, int e);
int Dis1(flowers, flowers);

int main()
{
	flowers flower[NUMFLOWER + 5], tmp[NUMFLOWER + 5];
	int NumP = 0;
   	long long MinDis;
	point fount1, fount2;

	ReadInAndPre(&NumP, &fount1, &fount2, flower);
	if (NumP == 1) {
		if (flower[0].d1 < flower[0].d2) {
			printf("%lld\n", flower[0].d1);
		}
		else {
			printf("%lld\n", flower[0].d2);
		}
		return 0;
	}
	MergeSort(flower, tmp, Dis1, 0, NumP - 1);
	GetMin(&MinDis, flower, NumP);
	printf("%lld\n", MinDis);

	return 0;
}

void ReadInAndPre(int *NumP, point* fount1, point* fount2, flowers* flower) {
	scanf("%d", NumP);
	scanf("%d %d %d %d", &fount1->x, &fount1->y, &fount2->x, &fount2->y);
	for (int i = 0; i < *NumP; i++) {
		scanf("%d %d", &flower[i].coor.x, &flower[i].coor.y);
		flower[i].d1 = (flower[i].coor.x - fount1->x) * (flower[i].coor.x - fount1->x) + (flower[i].coor.y - fount1->y) * (flower[i].coor.y - fount1->y);
		flower[i].d2 = (flower[i].coor.x - fount2->x) * (flower[i].coor.x - fount2->x) + (flower[i].coor.y - fount2->y) * (flower[i].coor.y - fount2->y);
	}
	//puts("ReadInAndPre Done!");
}

void MergeSort(flowers* flower, flowers* tmp, int (*Dis)(flowers, flowers), int s, int e) {
	if (s >= e) {
		return;
	}
	int mid = (s + e) / 2;
	MergeSort(flower, tmp, Dis, s, mid);
	MergeSort(flower, tmp, Dis, mid + 1, e);
	Merge(flower, tmp, Dis, s, e);
}

void GetMin(long long *MinDis, flowers* flower, int NumP)
{
	*MinDis = flower[NumP - 1].d1;
	for (int i = NumP - 2; i >= 0; i--) {
		if (flower[i].d2 < flower[i + 1].d2) {
			flower[i].d2 = flower[i + 1].d2;
		}
	}
	for (int i = 0; i < NumP - 1; i++) {
		if (*MinDis > flower[i].d1 + flower[i + 1].d2) {
			*MinDis = flower[i].d1 + flower[i + 1].d2;
		}
	}
}

void Merge(flowers* flower, flowers* tmp, int(*Dis1)(flowers, flowers), int s, int e)
{
	int mid = (s + e) / 2;
	int i = s, j = mid + 1, index = s;

	//puts("Merge Begin!");
	while (i <= mid && j <= e) {
		//printf("%d %d \n", i , j);
		while (j <= e && i <= mid && Dis1(flower[i], flower[j])) {
			tmp[index] = flower[i];
			index++;
			i++;
		}
		while (j <= e && i <= mid && Dis1(flower[j], flower[i])) {
			tmp[index] = flower[j];
			index++;
			j++;
		}
	}
	//	printf("%d %d \n", i , j);
	while (i <= mid) {
		tmp[index] = flower[i];
		index++;
		i++;
	}
	while (j <= e) {
		tmp[index] = flower[j];
		index++;
		j++;
	}
	for (int i = s; i <= e; i++) {
		flower[i] = tmp[i];
	}
	//	printf("%d %d \n", i , j);
}

int Dis1(flowers a, flowers b) {
	if (a.d1 < b.d1) {
		return 1;
	}
	else if (a.d1 == b.d1 && a.d2 > b.d2) {
		return 1;
	}
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

struct flower {
	int x = 0, y = 0;
	int dis1 = 0;
	int dis2 = 0;
};

bool compare(const flower &a, const flower & b) {
	return b.dis1<a.dis1;
}

int main()
{
	int n;
	int x1, y1;
	int x2, y2;
	vector<flower> fs;
	cin >> n >> x1 >> y1 >> x2 >> y2;
	for (int i = 0; i < n; ++i) {
		flower temp;
		cin >> temp.x >> temp.y;
		temp.dis1 = (temp.x - x1)*(temp.x - x1) + (temp.y - y1)*(temp.y - y1);
		temp.dis2 = (temp.x - x2)*(temp.x - x2) + (temp.y - y2)*(temp.y - y2);
		fs.push_back(temp);
	}
	sort(fs.begin(), fs.end(), compare);
	int R1 = 0, R2 = 0;
	int S=0;
	for (int i = 0; i < n; ++i) {
		if (fs[i].dis2 >= R2) {
			R2 = fs[i].dis2;
		}
	}
	S = R2;
	for (int i = 0; i < n; ++i) {
		R1 = fs[i].dis1;
		R2 = 0;
		for (int j = 0; j < i; ++j) {
			if (fs[j].dis2 >= R2) {
				R2 = fs[j].dis2;
			}
		}
		if (R1 + R2 <= S) {
			S = R1 + R2;
		}
	}
	cout << S ;
    return 0;
}


#include <iostream>
using namespace std;
int main(){
	int times,x1,y1,x2,y2;
	cin>>times>>x1>>y1>>x2>>y2;
	long long*distance1=new long long[times],*distance2=new long long[times];
	for (int i=0;i<times;i++){
		long x,y;
		cin>>x>>y;
		distance1[i]=(x1-x)*(x1-x)+(y1-y)*(y1-y);
	    distance2[i]=(x2-x)*(x2-x)+(y2-y)*(y2-y);
	}
	long long result=10000000000000;
	for (int i=0;i<times-1;i++){
		for (int j=times;j>i;j--){
			if (distance1[j-1]>distance1[j]){
			long temp1=distance1[j-1];
			distance1[j-1]=distance1[j];
			distance1[j]=temp1;
			long temp2=distance2[j-1];
			distance2[j-1]=distance2[j];
			distance2[j]=temp2;
			}
		}
	}//sort
	for(int i=0;i<times;i++){
	    int r1=distance1[i];
	    int r2=distance2[i+1];
		for(int j=i+2;j<times;j++){
	    	if (distance2[j]>r2){r2=distance2[j];}
		}
		if(r1+r2<result){result=r1+r2;}
	}
	for (int i=0;i<times-1;i++){
		for (int j=times;j>i;j--){
			if (distance2[j-1]>distance2[j]){
			long temp1=distance1[j-1];
			distance1[j-1]=distance1[j];
			distance1[j]=temp1;
			long temp2=distance2[j-1];
			distance2[j-1]=distance2[j];
			distance2[j]=temp2;
			}
		}
	}//sort
	for(int i=0;i<times;i++){
	    int r1=distance2[i];
	    int r2=distance1[i+1];
		for(int j=i+2;j<times;j++){
	    	if (distance1[j]>r2){r2=distance1[j];}
		}
		if(r1+r2<result){result=r1+r2;}
	}
	cout<<result;
}


#include<iostream>
int qian(long long int t1[], long long int t2[], int n, int i);
long long int dis(int x1, int y1, int x2, int y2);
using namespace std;
int main()
{
	int n, x1, y1, x2, y2;
	cin >> n >> x1 >> y1 >> x2 >> y2;
	int i, j, k;
	int w, z, t, length;
	long long int t1max = 0, t2max = 0;
	long long int min = 400000000000000;
	long long int t1[2003] = { 0 };
	long long int t2[2003] = { 0 };
	for (i = 0; i < n; i++)
	{
		cin >> w >> z;
		t1[i] = dis(x1, y1, w, z);
		t2[i] = dis(x2, y2, w, z);
		if (t1max < t1[i])
			t1max = t1[i];
		if (t2max < t2[i])
			t2max = t2[i];
	}
	t1[i] = 0, t2[i] = t2max;
	i++, n++;
	t1[i] = t1max, t2[i] = 0;
	i++, n++;
	for (i = 0; i < n; i++)
	for (j = 1; j < n; j++)
	{
		if (t1[j - 1]>t1[j])
		{
			t = t2[j];
			t2[j] = t2[j - 1];
			t2[j - 1] = t;
			t = t1[j];
			t1[j] = t1[j - 1];
			t1[j - 1] = t;
		}
	}
	length = n;
	for (j = 0; j < 2 * length; j++)
	{
		for (i = 0; i < length - 1; i++)
		{
			if (t2[i] < t2[i + 1])
			{
				length = qian(t1, t2, length, i);
				i--;
			}
		}
	}
	for (i = 0; i < length - 1; i++)
	{
		t = t1[i] + t2[i + 1];
		if (min>t)
			min = t;
	}
	cout << min;
}
int qian(long long int t1[], long long int t2[], int n, int i)
{
	for (; i < n; i++)
	{
		t1[i] = t1[i + 1];
		t2[i] = t2[i + 1];
	}
	return n - 1;
}
long long int dis(int x1, int y1, int x2, int y2)
{
	return (x2 - x1)*(x2 - x1) + (y1 - y2)*(y1 - y2);
}


#include<iostream>
using namespace std;
bool covered(long long bestr1,long long bestr2,long long dist[][2],long long n);
int main()
{
	long long n,x1,y1,x2,y2;
	cin>>n>>x1>>y1>>x2>>y2;
	long long coord[2000][2];
	for(int i=0;i<n;i++)
	{
		cin>>coord[i][0]>>coord[i][1];
	}//输入

	long long dist[2000][2];
	for (int i=0;i<n;i++)//与A喷泉距离平方
	{
		dist[i][0]=(coord[i][0]-x1)*(coord[i][0]-x1)+(coord[i][1]-y1)*(coord[i][1]-y1);
	}
	dist[n][0]=0;//加一个为0的情况

	for (int i=0;i<n;i++)//与A喷泉距离平方
	{
		dist[i][1]=(coord[i][0]-x2)*(coord[i][0]-x2)+(coord[i][1]-y2)*(coord[i][1]-y2);
	}
	dist[n][1]=0;//加一个为0的情况

	long long best=dist[0][0]+dist[0][1];
	long long bestr1=dist[0][0];
	long long bestr2=dist[0][1];
	for(int i=0;i<n+1;i++)
	{
		for (int j=0;j<n+1;j++)
		{
			if(covered(dist[i][0],dist[j][1],dist,n) && (dist[i][0]+dist[j][1] < best))
			{
				best=dist[i][0]+dist[j][1];
				bestr1=dist[i][0];
				bestr2=dist[j][1];
			}
		}
	}
	cout<<best;
	return 0;
}
bool covered(long long r1s,long long r2s,long long dist[][2],long long n)
{
	for(int k=0;k<n;k++)
	{
		if (r1s<dist[k][0] && r2s<dist[k][1])
		{
			return false;
		}
	}
	return true;
}


#include <iostream>
#include <cstring>
using namespace std;

class node{
 public:
  long long int x;
  long long int y;
  long long int d1;
  long long int d2;
  bool exist;
  node(){
      exist = false;
  }
  node(int _x,int _y){
      x = _x,y = _y;
      exist = true;
  }
};

void initialize(int term);
void show(int term);
void distance(int m);
void sort(int term);
void jiaohuan(int n, int lun);
void showSort(int term);
void doSign(int lun,int term);
bool exmaine(int term);

node p1,p2;
node f[2000];
long long int s1[2][2000];
long long int s2[2][2000];
bool sign[2000];
long long int answer[2000+2];

int main(){
    int term(0);
    cin >> term;
    initialize(term);
    //show(term);

    //show(term);
    sort(term);
    //showSort(term);
    memset(answer,2147483647 , sizeof(answer));
    for(int i(0);i < term;i++){
        memset(sign,0, sizeof(sign));
        doSign(i,term);
        for(int j(term-1);j > 0;j--){
            sign[s2[0][j]] = 1;
            if(exmaine(term) == true){
                answer[i] = s1[1][i] + s2[1][j];
                break;
            }
        }
        memset(sign,0, sizeof(sign));
    }

    answer[term] = s1[1][0];
    answer[term+1] = s2[1][0];
    long long int min(2147483647);
    for(int i(0);i < term+2;i++){
        if(answer[i] < min) min = answer[i];
    }
/*
    showSort(term);

    for(int i(0);i < term+2;i++){
        cout << answer[i] << " ";
    }
    cout << endl;
*/
    cout << min;
}

void initialize(int term){
    int term1,term2,term3,term4;
    cin >> term1 >> term2 >> term3 >> term4;
    p1 = node(term1,term2);
    p2 = node(term3,term4);
    for(int i(0);i < term;i++){
        cin >> term1 >> term2;
        f[i] = node(term1,term2);
        distance(i);
        s1[0][i] = i, s2[0][i] = i;
        s1[1][i] = f[i].d1, s2[1][i] = f[i].d2;
    }
}

void show(int term){
    cout << p1.x << " " << p1.y << " " << p2.x << " " << p2.y << endl;
    for(int i(0);i < term;i++){
        cout << f[i].x << " " << f[i].y << " " << f[i].d1 << " " << f[i].d2 << endl;
    }
}

void distance(int m){
    f[m].d1 = (p1.x - f[m].x)*(p1.x - f[m].x) + (p1.y - f[m].y)*(p1.y - f[m].y);
    f[m].d2 = (p2.x - f[m].x)*(p2.x - f[m].x) + (p2.y - f[m].y)*(p2.y - f[m].y);
}

void sort(int term){
    for(int i(1);i < term;i++){
        for(int j(i); j >= 1; j--){
            if(s1[1][j-1] < s1[1][j]){
                jiaohuan(1,j);
            }
            if(s2[1][j-1] < s2[1][j]){
                jiaohuan(2,j);
            }
        }
    }
}

void jiaohuan(int n, int lun){
    if(n != 1 && n != 2){
        cout << "出错";
        return;
    }

    if(n == 1){
        long long int term0,term1;
        term0 = s1[0][lun-1];
        term1 = s1[1][lun-1];
        s1[0][lun-1] = s1[0][lun];
        s1[1][lun-1] = s1[1][lun];
        s1[0][lun]   = term0;
        s1[1][lun]   = term1;
    }

    if(n == 2){
        long long int term0,term1;
        term0 = s2[0][lun-1];
        term1 = s2[1][lun-1];
        s2[0][lun-1] = s2[0][lun];
        s2[1][lun-1] = s2[1][lun];
        s2[0][lun]   = term0;
        s2[1][lun]   = term1;
    }
}

void showSort(int term){
    for(int i(0);i < term;i++){
        cout << s1[0][i] << " " << s1[1][i] <<" " << s2[0][i] << " " << s2[1][i] << endl;
    }
}

void doSign(int lun,int term){
    for(int i(lun);i < term;i++){
        sign[s1[0][i]] = 1;
    }
}

bool exmaine(int term){
    for(int i(0);i < term;i++){
        if(sign[i] != 1){
            return false;
        }
    }

    return true;
}


#include<stdio.h>

#define NUMFLOWER 2000

typedef struct {
	long long x;
	long long y;
} point;

typedef struct {
	point coor;
	long long d1;
	long long d2;
} flowers;

void ReadInAndPre(long long *NumP, point* fount1, point* fount2, flowers* flower);
void MergeSort(flowers* flower, flowers* tmp, long long (*Dis1)(flowers, flowers), long long s, long long e);
void GetMin(long long *MinDis, flowers* flower, long long NumP);
void Merge(flowers* flower, flowers* tmp, long long(*Dis1)(flowers, flowers), long long s, long long e);
long long Dis1(flowers, flowers);
long long Dis2(flowers, flowers);
void GetMin2(long long *MinDis, flowers* flower, long long NumP);
long long min(long long a, long long b);
long long max(long long a, long long b);

int main()
{
	flowers flower[NUMFLOWER + 5], tmp[NUMFLOWER + 5];
	long long NumP = 0;
   	long long MinDis, MinDis2;
	point fount1, fount2;

	ReadInAndPre(&NumP, &fount1, &fount2, flower);
	if (NumP == 1) {
		if (flower[0].d1 < flower[0].d2) {
			printf("%lld\n", flower[0].d1);
		}
		else {
			printf("%lld\n", flower[0].d2);
		}
		return 0;
	}
	MergeSort(flower, tmp, Dis1, 0, NumP - 1);
	GetMin(&MinDis, flower, NumP);
	MergeSort(flower, tmp, Dis2, 0, NumP - 1);
	GetMin2(&MinDis2, flower, NumP);
	if (MinDis < MinDis2) {
		printf("%lld\n", MinDis);
	}
	else {
		printf("%lld\n", MinDis2);
	}
	/*for (long long i = 0; i < NumP; i++) {
		printf("@ %lld %lld\n", flower[i].d1, flower[i].d2);
	}*/

	return 0;
}

long long min(long long a, long long b)
{
	if (a < b) {
		return a;
	}
	return b;
}

long long max(long long a, long long b)
{
	if (a > b) {
		return a;
	}
	return b;
}

void ReadInAndPre(long long *NumP, point* fount1, point* fount2, flowers* flower) {
	scanf("%lld", NumP);
	scanf("%lld %lld %lld %lld", &fount1->x, &fount1->y, &fount2->x, &fount2->y);
	for (long long i = 0; i < *NumP; i++) {
		scanf("%lld %lld", &flower[i].coor.x, &flower[i].coor.y);
		flower[i].d1 = ((int)flower[i].coor.x - fount1->x) * (flower[i].coor.x - fount1->x) + ((int)flower[i].coor.y - fount1->y) * (flower[i].coor.y - fount1->y);
		flower[i].d2 = ((int)flower[i].coor.x - fount2->x) * (flower[i].coor.x - fount2->x) + ((int)flower[i].coor.y - fount2->y) * (flower[i].coor.y - fount2->y);
	}
}

void MergeSort(flowers* flower, flowers* tmp, long long (*Dis)(flowers, flowers), long long s, long long e) {
	if (s >= e) {
		return;
	}
	long long mid = (s + e) / 2;
	MergeSort(flower, tmp, Dis, s, mid);
	MergeSort(flower, tmp, Dis, mid + 1, e);
	Merge(flower, tmp, Dis, s, e);
}

void GetMin(long long *MinDis, flowers* flower, long long NumP)
{
	*MinDis = 10000000000000000;
	for (long long i = 0; i < NumP; i++) {
		long long Max = 0;
		for (long long j = 0; j < i; j++) {
			Max = max(Max, flower[j].d2);
		}
		*MinDis = min(*MinDis, Max + flower[i].d1);
	}
}

void Merge(flowers* flower, flowers* tmp, long long(*Dis1)(flowers, flowers), long long s, long long e)
{
	long long mid = (s + e) / 2;
	long long i = s, j = mid + 1, index = s;

	while (i <= mid && j <= e) {
		while (j <= e && i <= mid && Dis1(flower[i], flower[j])) {
			tmp[index] = flower[i];
			index++;
			i++;
		}
		while (j <= e && i <= mid && Dis1(flower[j], flower[i])) {
			tmp[index] = flower[j];
			index++;
			j++;
		}
	}
	while (i <= mid) {
		tmp[index] = flower[i];
		index++;
		i++;
	}
	while (j <= e) {
		tmp[index] = flower[j];
		index++;
		j++;
	}
	for (long long i = s; i <= e; i++) {
		flower[i] = tmp[i];
	}
}

long long Dis1(flowers a, flowers b) {
	if (a.d1 > b.d1) {
		return 1;
	}
	else if (a.d1 == b.d1 && a.d2 >= b.d2) {
		return 1;
	}
	return 0;
}

long long Dis2(flowers a, flowers b) {
	if (a.d2 > b.d2) {
		return 1;
	}
	else if (a.d2 == b.d2 && a.d1 >= b.d1) {
		return 1;
	}
	return 0;
}

void GetMin2(long long *MinDis, flowers* flower, long long NumP)
{
	*MinDis = 10000000000000000;
	for (long long i = 0; i < NumP; i++) {
		long long Max = 0;
		for (long long j = 0; j < i; j++) {
			Max = max(Max, flower[j].d1);
		}
		*MinDis = min(*MinDis, Max + flower[i].d2);
	}
}


#include<stdio.h>

#define NUMFLOWER 2000

typedef struct {
	int x;
	int y;
} point;

typedef struct {
	point coor;
	long long d1;
	long long d2;
} flowers;

void ReadInAndPre(int *NumP, point* fount1, point* fount2, flowers* flower);
void MergeSort(flowers* flower, flowers* tmp, int (*Dis1)(flowers, flowers), int s, int e);
void GetMin(long long *MinDis, flowers* flower, int NumP);
void Merge(flowers* flower, flowers* tmp, int(*Dis1)(flowers, flowers), int s, int e);
int Dis1(flowers, flowers);

int main()
{
	flowers flower[NUMFLOWER + 5], tmp[NUMFLOWER + 5];
	int NumP = 0;
   	long long MinDis;
	point fount1, fount2;

	ReadInAndPre(&NumP, &fount1, &fount2, flower);
	if (NumP == 1) {
		if (flower[0].d1 < flower[0].d2) {
			printf("%lld\n", flower[0].d1);
		}
		else {
			printf("%lld\n", flower[0].d2);
		}
		return 0;
	}
	MergeSort(flower, tmp, Dis1, 0, NumP - 1);
	GetMin(&MinDis, flower, NumP);
	printf("%lld\n", MinDis);

	return 0;
}

void ReadInAndPre(int *NumP, point* fount1, point* fount2, flowers* flower) {
	scanf("%d", NumP);
	scanf("%d %d %d %d", &fount1->x, &fount1->y, &fount2->x, &fount2->y);
	for (int i = 0; i < *NumP; i++) {
		scanf("%d %d", &flower[i].coor.x, &flower[i].coor.y);
		flower[i].d1 = (flower[i].coor.x - fount1->x) * (flower[i].coor.x - fount1->x) + (flower[i].coor.y - fount1->y) * (flower[i].coor.y - fount1->y);
		flower[i].d2 = (flower[i].coor.x - fount2->x) * (flower[i].coor.x - fount2->x) + (flower[i].coor.y - fount2->y) * (flower[i].coor.y - fount2->y);
	}
	//puts("ReadInAndPre Done!");
}

void MergeSort(flowers* flower, flowers* tmp, int (*Dis)(flowers, flowers), int s, int e) {
	if (s >= e) {
		return;
	}
	int mid = (s + e) / 2;
	MergeSort(flower, tmp, Dis, s, mid);
	MergeSort(flower, tmp, Dis, mid + 1, e);
	Merge(flower, tmp, Dis, s, e);
}

void GetMin(long long *MinDis, flowers* flower, int NumP)
{
	*MinDis = flower[NumP - 1].d1;
	/*for (int i = NumP - 2; i >= 0; i--) {
		if (flower[i].d2 < flower[i + 1].d2) {
			flower[i].d2 = flower[i + 1].d2;
		}
	}*/
	if (flower[0].d2 < *MinDis) {
		*MinDis = flower[0].d2;
	}
	for (int i = 0; i < NumP - 1; i++) {
		/*if (*MinDis > flower[i].d1 + flower[i + 1].d2) {
			*MinDis = flower[i].d1 + flower[i + 1].d2;
		}*/
		int j = i + 1, Max = 0;
		while (flower[j].d1 == flower[i].d1) {
			j++;
		}
		while (j < NumP) {
			if (Max < flower[j].d2) {
				Max = flower[j].d2;
			}
			j++;
		}
		if (*MinDis > flower[i].d1 + Max) {
			*MinDis = flower[i].d1 + Max;
		}
	}
}

void Merge(flowers* flower, flowers* tmp, int(*Dis1)(flowers, flowers), int s, int e)
{
	int mid = (s + e) / 2;
	int i = s, j = mid + 1, index = s;

	//puts("Merge Begin!");
	while (i <= mid && j <= e) {
		//printf("%d %d \n", i , j);
		while (j <= e && i <= mid && Dis1(flower[i], flower[j])) {
			tmp[index] = flower[i];
			index++;
			i++;
		}
		while (j <= e && i <= mid && Dis1(flower[j], flower[i])) {
			tmp[index] = flower[j];
			index++;
			j++;
		}
	}
	//	printf("%d %d \n", i , j);
	while (i <= mid) {
		tmp[index] = flower[i];
		index++;
		i++;
	}
	while (j <= e) {
		tmp[index] = flower[j];
		index++;
		j++;
	}
	for (int i = s; i <= e; i++) {
		flower[i] = tmp[i];
	}
	//	printf("%d %d \n", i , j);
}

int Dis1(flowers a, flowers b) {
	if (a.d1 < b.d1) {
		return 1;
	}
	else if (a.d1 == b.d1 && a.d2 >= b.d2) {
		return 1;
	}
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

struct flower {
	int x, y ;
	int dis1 ;
	int dis2 ;
};

bool compare(const flower &a, const flower & b) {
	return b.dis1<a.dis1;
}

int main()
{

		int n;
		int x1, y1;
		int x2, y2;
		vector<flower> fs;
		cin >> n >> x1 >> y1 >> x2 >> y2;
		for (int i = 0; i < n; ++i) {
			flower temp;
			cin >> temp.x >> temp.y;
			temp.dis1 = (temp.x - x1)*(temp.x - x1) + (temp.y - y1)*(temp.y - y1);
			temp.dis2 = (temp.x - x2)*(temp.x - x2) + (temp.y - y2)*(temp.y - y2);
			fs.push_back(temp);
		}
		sort(fs.begin(), fs.end(), compare);
		int R1 = 0, R2 = 0;
		int S = 0;
		for (int i = 0; i < n; ++i) {
			if (fs[i].dis2 >= R2) {
				R2 = fs[i].dis2;
			}
		}
		S = R2;
		for (int i = 0; i < n; ++i) {
			R1 = fs[i].dis1;
			R2 = 0;
			for (int j = 0; j < i; ++j) {
				if (fs[j].dis2 >= R2) {
					R2 = fs[j].dis2;
				}
			}
			if (R1 + R2 <= S) {
				S = R1 + R2;
			}
		}

		cout << S;

    return 0;
}


#include<iostream>
using namespace std;
bool covered(long bestr1,long bestr2,long dist[][2],long n);
int main()
{
	long n,x1,y1,x2,y2;
	cin>>n>>x1>>y1>>x2>>y2;
	long coord[2000][2];
	for(int i=0;i<n;i++)
	{
		cin>>coord[i][0]>>coord[i][1];
	}

	long dist[2000][2];
	for (int i=0;i<n;i++)
	{
		dist[i][0]=(coord[i][0]-x1)*(coord[i][0]-x1)+(coord[i][1]-y1)*(coord[i][1]-y1);
	}
	dist[n][0]=0;
	for (int i=0;i<n;i++)
	{
		dist[i][1]=(coord[i][0]-x2)*(coord[i][0]-x2)+(coord[i][1]-y2)*(coord[i][1]-y2);
	}
	dist[n][1]=0;
	long best=dist[0][0]+dist[0][1];
	long bestr1=dist[0][0];
	long bestr2=dist[0][1];
	for(int i=0;i<n+1;i++)
	{
		for (int j=0;j<n+1;j++)
		{
			if(covered(dist[i][0],dist[j][1],dist,n) && (dist[i][0]+dist[j][1] < best))
			{
				best=dist[i][0]+dist[j][1];
				bestr1=dist[i][0];
				bestr2=dist[j][1];
			}
		}
	}
	cout<<best;
	return 0;
}
bool covered(long bestr1,long bestr2,long dist[][2],long n)
{
	for(int k=0;k<n;k++)
	{
		if (bestr1<dist[k][0] && bestr2<dist[k][1])
		{
			return false;
		}
	}
	return true;
}


#include <iostream>
using namespace std;

long long cor[2000][2]={0};
long long res[2000]={0};
void sort(int num,int index);
int main(){
    int num=0;
    int x,y,x1,y1,x2,y2=0;
    long long r1_2=0;
    long long r2_2=0;
    long long ans=0;
    cin>>num>>x1>>y1>>x2>>y2;
    for (int i = 0; i < num; ++i) {
        cin>>x>>y;
        cor[i][0]=(x-x1)*(x-x1)+(y-y1)*(y-y1);
        cor[i][1]=(x-x2)*(x-x2)+(y-y2)*(y-y2);
    }
    sort(num,0);

    for (int j = 0; j < num; ++j) {
        r1_2=cor[j][0];
        for (int i = j+1; i < num; ++i) {
            if(cor[i][1]>r2_2)r2_2=cor[i][1];
        }
        res[j]=r1_2+r2_2;
    }
    ans=res[0];
    for (int k = 0; k < num; ++k) {
        if(ans>res[k])ans=res[k];
    }
    cout<<ans<<endl;
    return 0;
}

void sort(int num,int index){
    long long temp1,temp2=0;
    for (int i = 0; i < num; ++i) {
        for (int j = 0; j < num - 1; ++j) {
            if(cor[j][index]>cor[j+1][index]){
                temp1=cor[j][index];
                cor[j][index]=cor[j+1][index];
                cor[j+1][index]=temp1;

                temp2=cor[j][1-index];
                cor[j][1-index]=cor[j+1][1-index];
                cor[j+1][1-index]=temp2;
            }
        }
    }
}


#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

struct flower{
	long long d1,d2;
}a[2001]={};

long long distance(long long x,long long y,long long a,long long b){
	return (x-a)*(x-a)+(y-b)*(y-b);
}

int main(){
  int n;
  long long r1,r2,mini=1e17,x1,x2,y1,y2,i,x,y;
  cin>>n>>x1>>y1>>x2>>y2;
  for(i=1;i<=n;i++) {
  	cin>>x>>y;
  	a[i].d1=distance(x,y,x1,y1);
  	a[i].d2=distance(x,y,x2,y2);
  }
  a[++n].d1=a[n].d2=0;

  if(n==2) mini=min(a[1].d1,a[1].d2);
  else for(i=1;i<=n;i++){
  	     r1=a[i].d1;
  	     r2=0;
  	     for(int j=1;j<=n;j++)
  		    if(a[j].d1>r1&&a[j].d2>r2) r2=a[j].d2;
       	if(r1+r2<mini) mini=r1+r2;

  }
  cout<<mini<<endl;

return 0;
}


#include<iostream>
int qian(long long int t1[], long long int t2[], int n, int i);
long long int dis(long long int x1, long long int y1, long long int x2, long long int y2);
using namespace std;
int main()
{
	long long int n, x1, y1, x2, y2;
	cin >> n >> x1 >> y1 >> x2 >> y2;
	int i, j, k;
	long long int w, z, t, length;
	long long int t1max = 0, t2max = 0;
	long long int min = 40000000000000000;
	long long int t1[2003] = { 0 };
	long long int t2[2003] = { 0 };
	for (i = 0; i < n; i++)
	{
		cin >> w >> z;
		t1[i] = dis(x1, y1, w, z);
		t2[i] = dis(x2, y2, w, z);
		if (t1max < t1[i])
			t1max = t1[i];
		if (t2max < t2[i])
			t2max = t2[i];
	}
	t1[i] = 0, t2[i] = t2max;
	i++, n++;
	t1[i] = t1max, t2[i] = 0;
	i++, n++;
	for (i = 0; i < n; i++)
	for (j = 1; j < n; j++)
	{
		if (t1[j - 1]>t1[j])
		{
			t = t2[j];
			t2[j] = t2[j - 1];
			t2[j - 1] = t;
			t = t1[j];
			t1[j] = t1[j - 1];
			t1[j - 1] = t;
		}
	}
	length = n;
	for (j = 0; j < length; j++)
	{
		for (i = 0; i < length - 1; i++)
		{
			if (t2[i] < t2[i + 1])
			{
				length = qian(t1, t2, length, i);
				i--;
			}
		}
	}
	for (i = 0; i < length - 1; i++)
	{
		t = t1[i] + t2[i + 1];
		if (min>t)
			min = t;
	}
	cout << min << endl;
}
int qian(long long int t1[], long long int t2[], int n, int i)
{
	for (; i < n; i++)
	{
		t1[i] = t1[i + 1];
		t2[i] = t2[i + 1];
	}
	return n - 1;
}
long long int dis(long long int x1, long long int y1, long long int x2, long long int y2)
{
	return (x2 - x1)*(x2 - x1) + (y1 - y2)*(y1 - y2);
}


#include<iostream>
using namespace std;

struct node
{
	int r1;
	int r2;
};
int n;
int x1,y1,x2,y2;
int r2_max;
int r1_max;
int minium;
node points[2001];
node points2[2001];
int main(void)
{
	cin>>n;
	cin>>x1>>y1>>x2>>y2;
	for(int i=1;i<=n;i++)
	{
		int x,y;
		cin>>x>>y;
		points2[i].r1=points[i].r1=(x1-x)*(x1-x)+(y1-y)*(y1-y);
		points2[i].r2=points[i].r2=(x2-x)*(x2-x)+(y2-y)*(y2-y);

		if (i==1)
			continue;
		else
			for(int j=i;j>=2;j--)
			{
				if(points[j].r1>points[j-1].r1)
				{
					node tmp;
					tmp=points[j];
					points[j]=points[j-1];
					points[j-1]=tmp;
				}
				if(points2[j].r2>points2[j-1].r2)
				{
					node tmp;
					tmp=points2[j];
					points2[j]=points2[j-1];
					points2[j-1]=tmp;
				}
			}
	}
	r2_max=points[1].r2;
	minium=points[1].r1;
	for(int i=2;i<=n;i++)
	{
		r2_max=max(r2_max,points[i-1].r2);
		minium=min(minium,points[i].r1+r2_max);
	}
	r2_max=max(r2_max,points[n].r2);
	minium=min(minium,r2_max);

	r1_max=points2[1].r1;
	minium=min(minium,points2[1].r2);
	for(int i=2;i<=n;i++)
	{
		r1_max=max(r1_max,points2[i-1].r1);
		minium=min(minium,points2[i].r2+r1_max);
	}
	r1_max=max(r1_max,points2[n].r1);
	minium=min(minium,r1_max);

	cout<<minium;

}


#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;

const int MAX_N = 2005;
int n;

struct point{
	long long x,y,da,db,m;
};

point a[MAX_N],A,B;

bool operator<(point A,point B){
	return A.da<B.da;
}

long long dist(point A,point B){
	return (A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y);
}

int main(){
	cin>>n;
	cin>>A.x>>A.y>>B.x>>B.y;
	for (int i=1;i<=n;i++){
		cin>>a[i].x>>a[i].y;
		a[i].da = dist(a[i],A);
		a[i].db = dist(a[i],B);
	}
	sort(a+1,a+1+n);

	a[n].m = a[n].db;
	for (int i=n-1;i>=1;i--) a[i].m = max(a[i+1].m,a[i].db);

	long long ans = a[1].db; a[n+1].db = 0;
	for (int i=1;i<=n;i++){
		int v = a[i].da+a[i+1].db;
		if (v<ans) ans = v;
	}

	cout<<ans<<endl;
	return 0;
}


#include<stdio.h>

#define NUMFLOWER 2000

typedef struct {
	int x;
	int y;
} point;

typedef struct {
	point coor;
	long long d1;
	long long d2;
} flowers;

void ReadInAndPre(int *NumP, point* fount1, point* fount2, flowers* flower);
void MergeSort(flowers* flower, flowers* tmp, int (*Dis1)(flowers, flowers), int s, int e);
void GetMin(long long *MinDis, flowers* flower, int NumP);
void Merge(flowers* flower, flowers* tmp, int(*Dis1)(flowers, flowers), int s, int e);
int Dis1(flowers, flowers);

int main()
{
	flowers flower[NUMFLOWER + 5], tmp[NUMFLOWER + 5];
	int NumP = 0;
   	long long MinDis;
	point fount1, fount2;

	ReadInAndPre(&NumP, &fount1, &fount2, flower);
	if (NumP == 1) {
		if (flower[0].d1 < flower[0].d2) {
			printf("%lld\n", flower[0].d1);
		}
		else {
			printf("%lld\n", flower[0].d2);
		}
		return 0;
	}
	MergeSort(flower, tmp, Dis1, 0, NumP - 1);
	GetMin(&MinDis, flower, NumP);
	printf("%lld\n", MinDis);

	return 0;
}

void ReadInAndPre(int *NumP, point* fount1, point* fount2, flowers* flower) {
	scanf("%d", NumP);
	scanf("%d %d %d %d", &fount1->x, &fount1->y, &fount2->x, &fount2->y);
	for (int i = 0; i < *NumP; i++) {
		scanf("%d %d", &flower[i].coor.x, &flower[i].coor.y);
		flower[i].d1 = (flower[i].coor.x - fount1->x) * (flower[i].coor.x - fount1->x) + (flower[i].coor.y - fount1->y) * (flower[i].coor.y - fount1->y);
		flower[i].d2 = (flower[i].coor.x - fount2->x) * (flower[i].coor.x - fount2->x) + (flower[i].coor.y - fount2->y) * (flower[i].coor.y - fount2->y);
	}
	//puts("ReadInAndPre Done!");
}

void MergeSort(flowers* flower, flowers* tmp, int (*Dis)(flowers, flowers), int s, int e) {
	if (s >= e) {
		return;
	}
	int mid = (s + e) / 2;
	MergeSort(flower, tmp, Dis, s, mid);
	MergeSort(flower, tmp, Dis, mid + 1, e);
	Merge(flower, tmp, Dis, s, e);
}

void GetMin(long long *MinDis, flowers* flower, int NumP)
{
	*MinDis = flower[NumP - 1].d1;
	for (int i = NumP - 2; i >= 0; i--) {
		if (flower[i].d2 < flower[i + 1].d2) {
			flower[i].d2 = flower[i + 1].d2;
		}
	}
	if (flower[0].d2 < *MinDis) {
		*MinDis = flower[0].d2;
	}
	for (int i = 0; i < NumP - 1; i++) {
		if (*MinDis > flower[i].d1 + flower[i + 1].d2) {
			*MinDis = flower[i].d1 + flower[i + 1].d2;
		}
		/*
		int j = i + 1, Max = 0;
		while (flower[j].d1 == flower[i].d1) {
			j++;
		}
		while (j < NumP) {
			if (Max < flower[j].d2) {
				Max = flower[j].d2;
			}
			j++;
		}
		if (*MinDis > flower[i].d1 + Max) {
			*MinDis = flower[i].d1 + Max;
		}*/
	}
}

void Merge(flowers* flower, flowers* tmp, int(*Dis1)(flowers, flowers), int s, int e)
{
	int mid = (s + e) / 2;
	int i = s, j = mid + 1, index = s;

	//puts("Merge Begin!");
	while (i <= mid && j <= e) {
		//printf("%d %d \n", i , j);
		while (j <= e && i <= mid && Dis1(flower[i], flower[j])) {
			tmp[index] = flower[i];
			index++;
			i++;
		}
		while (j <= e && i <= mid && Dis1(flower[j], flower[i])) {
			tmp[index] = flower[j];
			index++;
			j++;
		}
	}
	//	printf("%d %d \n", i , j);
	while (i <= mid) {
		tmp[index] = flower[i];
		index++;
		i++;
	}
	while (j <= e) {
		tmp[index] = flower[j];
		index++;
		j++;
	}
	for (int i = s; i <= e; i++) {
		flower[i] = tmp[i];
	}
	//	printf("%d %d \n", i , j);
}

int Dis1(flowers a, flowers b) {
	if (a.d1 < b.d1) {
		return 1;
	}
	else if (a.d1 == b.d1 && a.d2 >= b.d2) {
		return 1;
	}
	return 0;
}


#include<iostream>
#include<cmath>
#include<algorithm>
typedef struct {
    int x;
    int y;
} Pos;
int main() {
    int n = 0;
    int d1[2000] = {}, d2[2000];
    Pos m1, m2;
    Pos f[2000] = {};
    std::cin >> n >> m1.x >> m1.y >> m2.x >> m2.y;
    for (int i = 0; i < n; i++) {
        std::cin >> f[i].x >> f[i].y;
        d1[i] = pow(m1.x - f[i].x, 2) + pow(m1.y - f[i].y, 2);
        d2[i] = pow(m2.x - f[i].x, 2) + pow(m2.y - f[i].y, 2);
    }
    int minans = 2147483647;
    for (int i = 0; i < n; i++) {
        int t=0;
        for (int j = 0; j < n; j++) {
            if (d1[j] > d1[i])
                t = std::max(t, d2[j]);
        }
        minans = std::min(minans, d1[i] + t);
    }
    for (int i = 0; i < n; i++) {
        int t=0;
        t = std::max(t, d2[i]);
        minans = std::min(minans, d1[i] + t);
    }
    std::cout << minans;
}


#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

struct flower{
	long long d1,d2;
}a[2001]={};

long long distance(long long x,long long y,long long a,long long b){
	return (x-a)*(x-a)+(y-b)*(y-b);
}

int main(){
  int n;
  long long r1,r2,mini=1e17,x1,x2,y1,y2,i,x,y;
  cin>>n>>x1>>y1>>x2>>y2;
  for(i=1;i<=n;i++) {
  	cin>>x>>y;
  	a[i].d1=distance(x,y,x1,y1);
  	a[i].d2=distance(x,y,x2,y2);
  }

  if(n==1) mini=min(a[1].d1,a[1].d2);
  else for(i=1;i<=n;i++){
  	     r1=a[i].d1;
  	     r2=0;
  	     for(int j=1;j<=n;j++)
  		    if(a[j].d1>r1&&a[j].d2>r2) r2=a[j].d2;
       	if(r1+r2<mini) mini=r1+r2;

  }
  cout<<mini<<endl;

return 0;
}


#include<iostream>
int qian(long long int t1[], long long int t2[], int n, int i);
long long int dis(int x1, int y1, int x2, int y2);
using namespace std;
int main()
{
	int n, x1, y1, x2, y2;
	cin >> n >> x1 >> y1 >> x2 >> y2;
	int i, j, k;
	int x, y;
	long long int w, z, t, length, r1 = 0, r2 = 0;
	long long int t1max = 0, t2max = 0;
	long long int min = 400000000000000;
	long long int t1[2003] = { 0 };
	long long int t2[2003] = { 0 };
	for (i = 0; i < n; i++)
	{
		cin >> t1[i] >> t2[i];
		if (r1 < dis(x1, y1, t1[i], t2[i]))
		{
			r1 = dis(x1, y1, t1[i], t2[i]);
		}
		if (r2 < dis(x2, y2, t1[i], t2[i]))
		{
			r2 = dis(x2, y2, t1[i], t2[i]);
		}
	}
	for (i = 0; i < n; i++)
	for (j = 1; j < n; j++)
	{
		if (dis(x1, y1, t1[j - 1], t2[j - 1])>dis(x1, y1, t1[j], t2[j]))
		{
			t = t2[j];
			t2[j] = t2[j - 1];
			t2[j - 1] = t;
			t = t1[j];
			t1[j] = t1[j - 1];
			t1[j - 1] = t;
		}
	}
	length = n;
	for (j = 0; j < length; j++)
	{
		for (i = 0; i < length - 1; i++)
		{
			if (dis(x2, y2, t1[i], t2[i]) < dis(x2, y2, t1[i + 1], t2[i + 1]))
			{
				length = qian(t1, t2, length, i);
				i--;
			}
		}
	}
	if (length == 1)
	{
		if (min > r1)
			min = r1;
		if (min > r2)
			min = r2;
	}
	else
	{
		for (i = 0; i < length - 1; i++)
		{
			t = dis(x1, y1, t1[i], t2[i]) + dis(x2, y2, t1[i + 1], t2[i + 1]);
			if (min>t)
				min = t;
		}
	}
	cout << min;
	return 0;
}
int qian(long long int t1[], long long int t2[], int n, int i)
{
	for (; i < n; i++)
	{
		t1[i] = t1[i + 1];
		t2[i] = t2[i + 1];
	}
	return n - 1;
}
long long int dis(int x1, int y1, int x2, int y2)
{
	return (x2 - x1)*(x2 - x1) + (y1 - y2)*(y1 - y2);
}


#include <stdio.h>
int one_zero(int change,int a){
	if (change>a){
		return 0;
	}else return 1;
}

int main(){
	long long s[1000][2];
	int judge_point[1000][2];
	//Zero.
	for (int i=0;i<1000;i++){
		judge_point[i][0]=0;
		judge_point[i][1]=0;
	}
	int n;
	long long point[2][2];
	long long point_i[1000][2];
	scanf("%d %lld %lld %lld %lld",&n,&point[0][0],&point[0][1],&point[1][0],&point[1][1]);
	//Count the distance between any point and two O.
	for (int i=0;i<n;i++){
		scanf("%lld %lld",&point_i[i][0],&point_i[i][1]);//input the place of points.
		s[i][0]=(point_i[i][0]-point[0][0])*(point_i[i][0]-point[0][0])+(point_i[i][1]-point[0][1])*(point_i[i][1]-point[0][1]);
		s[i][1]=(point_i[i][0]-point[1][0])*(point_i[i][0]-point[1][0])+(point_i[i][1]-point[1][1])*(point_i[i][1]-point[1][1]);
	}
	long long min[1000];
	long long r2[1000];
	//Zero.
	for (int i=0;i<1000;i++){
		r2[i]=0;
	}
	//Find the min of the r_1^2 and r_2^2.
	for (int i=0;i<n;i++){
		for (int j=0;j<n;j++){
			judge_point[j][0]=one_zero(s[j][0],s[i][0]);
		}
		for (int j=0;j<n;j++){
			if (judge_point[j][0]==0){
				if (r2[i]<s[j][1]){
					r2[i]=s[j][1];
				}
			}
		}
	    min[i] = r2[i] + s[i][0];
	}

	long long mmin = min[0];
	for (int i=0;i<n;i++){
		if (min[i]<mmin){
			mmin=min[i];
     	}
    }
	printf("%lld\n",mmin);
}


#include<iostream>
using namespace std;

int main() {
	int n, x1, y1, x2, y2, sqr_r1, sqr_r2, max1, max2, choose;
	int dis1[2001], dis2[2001], x[2001], y[2001];

    cin >> n >> x1 >> y1 >> x2 >> y2;
    //sqr_r1 = 0; sqr_r2 = 0;
    max1 = 0;
	for (int i = 1; i <= n; i++) {
	    cin >> x[i] >> y[i];
	    dis1[i] = (x[i] - x1) * (x[i] - x1) + (y[i] - y1) * (y[i] - y1);
	    dis2[i] = (x[i] - x2) * (x[i] - x2) + (y[i] - y2) * (y[i] - y2);
	    if (dis1[i] < dis2[i]) {
	    	//if (dis1[i] > sqr_r1) sqr_r1 = dis1[i];
	    	if (dis1[i] > max1) {
			    max1 = dis1[i];
			    choose = 1;
		    }
		}
		else {
			//if (dis2[i] > sqr_r2) sqr_r2 = dis2[i];
			if (dis2[i] > max1) {
				max1 = dis2[i];
				choose = 2;
			}
		}
    }
    //cout << max1 << " " << choose << endl;
    if (choose == 1) {
    	sqr_r1 = max1;
    	max2 = 0;
    	for (int i = 1; i <= n; i++) {
    		if ((dis1[i] > sqr_r1) and (dis2[i] > max2)) {
    			max2 = dis2[i];
			}
		}
    	sqr_r2 = max2;
    	//cout << "sqr_r2: " << sqr_r2 << endl;
	}
	else {
	    sqr_r2 = max1;
    	max2 = 0;
    	for (int i = 1; i <= n; i++) {
    		if ((dis2[i] > sqr_r2) and (dis1[i] > max2)) {
    			max2 = dis1[i];
			}
		}
    	sqr_r1 = max2;
	}
	cout << sqr_r1 + sqr_r2;
	return 0;
}


#include<stdio.h>

#define NUMFLOWER 2000

typedef struct {
	int x;
	int y;
} point;

typedef struct {
	point coor;
	long long d1;
	long long d2;
} flowers;

void ReadInAndPre(int *NumP, point* fount1, point* fount2, flowers* flower);
void MergeSort(flowers* flower, flowers* tmp, int (*Dis1)(flowers, flowers), int s, int e);
void GetMin(long long *MinDis, flowers* flower, int NumP);
void Merge(flowers* flower, flowers* tmp, int(*Dis1)(flowers, flowers), int s, int e);
int Dis1(flowers, flowers);

int main()
{
	flowers flower[NUMFLOWER + 5], tmp[NUMFLOWER + 5];
	int NumP = 0;
   	long long MinDis;
	point fount1, fount2;

	ReadInAndPre(&NumP, &fount1, &fount2, flower);
	if (NumP == 1) {
		if (flower[0].d1 < flower[0].d2) {
			printf("%lld\n", flower[0].d1);
		}
		else {
			printf("%lld\n", flower[0].d2);
		}
		return 0;
	}
	MergeSort(flower, tmp, Dis1, 0, NumP - 1);
	GetMin(&MinDis, flower, NumP);
	printf("%lld\n", MinDis);

	return 0;
}

void ReadInAndPre(int *NumP, point* fount1, point* fount2, flowers* flower) {
	scanf("%d", NumP);
	scanf("%d %d %d %d", &fount1->x, &fount1->y, &fount2->x, &fount2->y);
	for (int i = 0; i < *NumP; i++) {
		scanf("%d %d", &flower[i].coor.x, &flower[i].coor.y);
		flower[i].d1 = (flower[i].coor.x - fount1->x) * (flower[i].coor.x - fount1->x) + (flower[i].coor.y - fount1->y) * (flower[i].coor.y - fount1->y);
		flower[i].d2 = (flower[i].coor.x - fount2->x) * (flower[i].coor.x - fount2->x) + (flower[i].coor.y - fount2->y) * (flower[i].coor.y - fount2->y);
	}
	//puts("ReadInAndPre Done!");
}

void MergeSort(flowers* flower, flowers* tmp, int (*Dis)(flowers, flowers), int s, int e) {
	if (s >= e) {
		return;
	}
	int mid = (s + e) / 2;
	MergeSort(flower, tmp, Dis, s, mid);
	MergeSort(flower, tmp, Dis, mid + 1, e);
	Merge(flower, tmp, Dis, s, e);
}

void GetMin(long long *MinDis, flowers* flower, int NumP)
{
	*MinDis = flower[NumP - 1].d1;
	for (int i = NumP - 2; i >= 0; i--) {
		if (flower[i].d2 < flower[i + 1].d2) {
			flower[i].d2 = flower[i + 1].d2;
		}
	}
	for (int i = 0; i < NumP - 1; i++) {
		if (*MinDis > flower[i].d1 + flower[i + 1].d2) {
			*MinDis = flower[i].d1 + flower[i + 1].d2;
		}
	}
}

void Merge(flowers* flower, flowers* tmp, int(*Dis1)(flowers, flowers), int s, int e)
{
	int mid = (s + e) / 2;
	int i = s, j = mid + 1, index = s;

	//puts("Merge Begin!");
	while (i <= mid && j <= e) {
		//printf("%d %d \n", i , j);
		while (j <= e && i <= mid && Dis1(flower[i], flower[j])) {
			tmp[index] = flower[i];
			index++;
			i++;
		}
		while (j <= e && i <= mid && Dis1(flower[j], flower[i])) {
			tmp[index] = flower[j];
			index++;
			j++;
		}
	}
	//	printf("%d %d \n", i , j);
	while (i <= mid) {
		tmp[index] = flower[i];
		index++;
		i++;
	}
	while (j <= e) {
		tmp[index] = flower[j];
		index++;
		j++;
	}
	for (int i = s; i <= e; i++) {
		flower[i] = tmp[i];
	}
	//	printf("%d %d \n", i , j);
}

int Dis1(flowers a, flowers b) {
	return a.d1 <= b.d1;
}


#include <iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;

int main(){
    int n;
    long long x,y,p,q,max_1,max_2,result,tmp_1,tmp_2;
    long long A[2000];
    long long B[2000];
    long long C[2000];
    scanf("%d%lld%lld%lld%lld",&n,&x,&y,&p,&q);
    for(int i=0;i<n;i++){
        scanf("%lld%lld",&tmp_1,&tmp_2);
        A[i]=(tmp_1-x)*(tmp_1-x)+(tmp_2-y)*(tmp_2-y);
        B[i]=(tmp_1-p)*(tmp_1-p)+(tmp_2-q)*(tmp_2-q);
        C[i]=A[i];
    }
    sort(A,A+n);
    result=10000;
    for(int j=0;j<n;j++){
        max_1=A[j];
        max_2=0;
        for(int k=0;k<n;k++) {
            if (C[k] > max_1 && B[k] > max_2) {
                max_2 = B[k];

            }
        }
        if(max_1+max_2<result){
            result=max_1+max_2;
        }

    }
    printf("%lld\n",result);

}


#include<iostream>
using namespace std;

struct node
{
	long long r1;
	long long r2;
};
int n;
long long  x1,y1,x2,y2;
long long  r2_max;
long long  r1_max;
long minium;
node points[2001];
node points2[2001];
long long min(long long a, long long b);
long long max(long long a,long long b);
int main(void)
{
	cin>>n;
	cin>>x1>>y1>>x2>>y2;
	for(int i=1;i<=n;i++)
	{
		long long x,y;
		cin>>x>>y;
		points2[i].r1=points[i].r1=(x1-x)*(x1-x)+(y1-y)*(y1-y);
		points2[i].r2=points[i].r2=(x2-x)*(x2-x)+(y2-y)*(y2-y);

		if (i==1)
			continue;
		else
			for(int j=i;j>=2;j--)
			{
				if(points[j].r1>points[j-1].r1)
				{
					node tmp;
					tmp=points[j];
					points[j]=points[j-1];
					points[j-1]=tmp;
				}
				if(points2[j].r2>points2[j-1].r2)
				{
					node tmp;
					tmp=points2[j];
					points2[j]=points2[j-1];
					points2[j-1]=tmp;
				}
			}
	}
	r2_max=points[1].r2;
	minium=points[1].r1;
	for(int i=2;i<=n;i++)
	{
		r2_max=max(r2_max,points[i-1].r2);
		minium=min(minium,points[i].r1+r2_max);
	}
	r2_max=max(r2_max,points[n].r2);
	minium=min(minium,r2_max);

	r1_max=points2[1].r1;
	minium=min(minium,points2[1].r2);
	for(int i=2;i<=n;i++)
	{
		r1_max=max(r1_max,points2[i-1].r1);
		minium=min(minium,points2[i].r2+r1_max);
	}
	r1_max=max(r1_max,points2[n].r1);
	minium=min(minium,r1_max);

	cout<<minium;

}

long long min(long long a, long long b)
{
	if(a<b)
		return a;
	else
		return b;
}

long long max(long long a,long long b)
{
	if(a>b)
		return a;
	else
		return b;
}


#include <iostream>
using namespace std;
int main()
{
	struct flower
	{
		long long x, y, s1, s2;
	}f[2005];
	int n;
	long long x1, x2, y1, y2;
	cin >> n >> x1 >> y1 >> x2 >> y2;
	for (int i = 0; i < n; ++i)
	{
		cin >> f[i].x >> f[i].y;
		f[i].s1 = (f[i].x - x1)*(f[i].x - x1) + (f[i].y - y1)*(f[i].y - y1);
		f[i].s2 = (f[i].x - x2)*(f[i].x - x2) + (f[i].y - y2)*(f[i].y - y2);
	}
	long long ans;
	for (int i = 0; i < n; ++i)//取f[i].s1为r1平方
	{
		long long temp = 0;
		for (int j = 0; j < n; ++j)//取f[i].s1为r1平方
		{
			if (f[j].s1 > f[i].s1&&f[j].s2 > temp)
				temp = f[j].s2;
		}
		if (i == 0 || temp + f[i].s1 < ans)
			ans = temp + f[i].s1;
	}
	cout << ans;
	return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#define ll long long
using namespace std;
ll x[3000],y[3000];
ll dis(int i,int j)	{
	return (x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
}
int main()	{
	int n;
	cin>>n>>x[1]>>y[1]>>x[2]>>y[2];
	for(int i=1;i<=n;i++)
		cin>>x[i+2]>>y[i+2];
	ll ans=INT_MAX;
	for(int i=1;i<=n;i++)	{
		ll ldis=dis(1,i+2);
		ll rdis=0;
		for(int j=1;j<=n;j++)
			if(ldis<dis(1,j+2))
				rdis=max(rdis,dis(2,j+2));
		ans=min(ans,ldis+rdis);
	}
	ll xdis=0;
	for(int j=1;j<=n;j++)	{
		xdis=max(xdis,dis(j+2,2));
	}
	ans=min(ans,xdis);
	cout<<ans<<endl;
}


#include <iostream>
using namespace std;

long long int cor[2000][2]={0};
long long int res[2000]={0};
void sort(int num,int index);

int main(){
    int num=0;
    long long x,y,x1,y1,x2,y2=0;
    long long r1_2=0;
    long long r2_2=0;
    long long ans=0;
    cin>>num>>x1>>y1>>x2>>y2;
    for (int i = 0; i < num; ++i) {
        cin>>x>>y;
        cor[i][0]=(x-x1)*(x-x1)+(y-y1)*(y-y1);
        cor[i][1]=(x-x2)*(x-x2)+(y-y2)*(y-y2);
    }

    sort(num,0);
    for (int j = 0; j < num; ++j) {
        r2_2=0;
        r1_2=cor[j][0];
        for (int i = j+1; i < num; ++i) {
            if(cor[i][1]>r2_2)r2_2=cor[i][1];
        }
        res[j]=r1_2+r2_2;
    }
    ans=res[0];
    for (int k = 0; k < num; ++k) {
        if(ans>res[k])ans=res[k];
    }

    sort(num,1);
    for (int l = 0; l < num; ++l) {
        r1_2=0;
        r2_2=cor[l][1];
        for (int i = l+1; i < num; ++i) {
            if(cor[i][0]>r1_2)r1_2=cor[i][0];
        }
        res[l]=r1_2+r2_2;
    }
    for (int m = 0; m < num; ++m) {
        if(ans>res[m])ans=res[m];
    }
    cout<<ans<<endl;
    return 0;
}

void sort(int num,int index){
    long long temp1,temp2=0;
    for (int i = 0; i < num; ++i) {
        for (int j = 0; j < num - 1; ++j) {
            if(cor[j][index]>cor[j+1][index]){
                temp1=cor[j][index];
                cor[j][index]=cor[j+1][index];
                cor[j+1][index]=temp1;

                temp2=cor[j][1-index];
                cor[j][1-index]=cor[j+1][1-index];
                cor[j+1][1-index]=temp2;
            }
        }
    }
}


#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
long long int minn;
struct coordinate{
	long long int x,y,distance_1,distance_2;
}a[2010];
bool cmp1(coordinate a,coordinate b)
{
	return a.distance_1<b.distance_1;
}
bool cmp2(coordinate a,coordinate b)
{
	return a.distance_2<b.distance_2;
}
int main()
{
	int n,x1,y1,x2,y2;
	cin>>n>>x1>>y1>>x2>>y2;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i].x>>a[i].y;
		a[i].distance_1=pow(x1-a[i].x,2)+pow(y1-a[i].y,2);
		a[i].distance_2=pow(x2-a[i].x,2)+pow(y2-a[i].y,2);
	}
	if(n>1){
	long long int sum1=0,min1=100000000000000000000;
	sort(a+1,a+n+1,cmp1);
	long long int max=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			if(a[j].distance_2>=max)	max=a[j].distance_2;
		}
		sum1=a[i].distance_1+max;
		if(sum1<=min1)	min1=sum1;
	}
	long long int sum2=0,min2=100000000000000000000;
	sort(a+1,a+n+1,cmp2);
	max=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			if(a[j].distance_1>=max)	max=a[j].distance_1;
		}
		sum2=a[i].distance_2+max;
		if(sum2<=min2)	min2=sum2;
	}
	if(min1<=min2)	minn=min1;
	else minn=min2;
}
	else if(a[1].distance_1<=a[1].distance_2)	minn=a[1].distance_1;
	else minn=a[1].distance_2;
	cout<<minn;
	return 0;
}


#include<iostream>

using namespace std;

struct cor
{
	int x;
	int y;
};
struct dis
{
	long long d1;
	long long d2;
};
long long distanceOfAB(cor A, cor B);
void sort();
cor foutain1, foutain2,currentFlower;
int n;
long long r1 = 0, r2 = 0;
dis dist[2000];
long long currentMax = 0;
int main()
{
	cin >> n >> foutain1.x >> foutain1.y >> foutain2.x >> foutain2.y;
	for (int i = 0; i < n; ++i)
	{
		cin >> currentFlower.x >> currentFlower.y;
		dist[i].d1 = distanceOfAB(foutain1, currentFlower);
		dist[i].d2 = distanceOfAB(foutain2, currentFlower);
	}
	sort();
	for (int i = 0; i <= n; ++i)
	{
		if (i < n)
		{
			r1 = dist[i].d1;
		}
		else
		{
			r1 = 0;
		}
		for (int j = 0; j < i; ++j)
		{
			if (dist[j].d2>r2)
			{
				r2 = dist[j].d2;
			}
		}
		if (i == 0)
		{
			currentMax = r1 + r2;
		}
		if (r1 + r2 < currentMax)
		{
			currentMax = r1 + r2;
		}
	}
	cout << currentMax;
}

long long distanceOfAB(cor A, cor B)
{
	long long dis;
	dis = (A.x - B.x)*(A.x - B.x) + (A.y - B.y)*(A.y - B.y);
	return dis;
}

void sort()
{
	dis temp;
	for (int i = 1; i <n ; ++i)
	{
		for (int j = i; j > 0; --j)
		{
			if (dist[j].d1 > dist[j - 1].d1)
			{
				temp = dist[j];
				dist[j] = dist[j - 1];
				dist[j - 1] = temp;
			}
		}
	}
}


#include <iostream>
#include <cmath>

int main() {
    long long n, x1, y1, x2, y2, x, y, d1, d2;
    long long r1 = 0, r2 = 0;
    std::cin >> n >> x1 >> y1 >> x2 >> y2;
    for (int i = 0; i < n; ++i) {
        std::cin >> x >> y;
        d1 = pow(std::abs(x - x1), 2) + pow(std::abs(y - y1), 2);
        d2 = pow(std::abs(x - x2), 2) + pow(std::abs(y - y2), 2);
        if (d1 > r1 && d2 > r2){
            if ((d1 + r2) > (d2 + r1)) r2 = d2;
            else if ((d1 + r2) <= (d2 + r1)) r1 = d1;
        }
    }
    std::cout << r1 + r2;
    return 0;
}


#include<iostream>

using namespace std;

struct cor
{
	int x;
	int y;
};
struct dis
{
	int d1;
	int d2;
};
int distanceOfAB(cor A, cor B);
void sort();
cor foutain1, foutain2,currentFlower;
int n,r1=0,r2=0;
dis dist[2000];
int currentMax = 0;
int main()
{
	cin >> n >> foutain1.x >> foutain1.y >> foutain2.x >> foutain2.y;
	for (int i = 0; i < n; ++i)
	{
		cin >> currentFlower.x >> currentFlower.y;
		dist[i].d1 = distanceOfAB(foutain1, currentFlower);
		dist[i].d2 = distanceOfAB(foutain2, currentFlower);
	}
	sort();
	for (int i = 0; i <= n; ++i)
	{
		if (i < n)
		{
			r1 = dist[i].d1;
		}
		else
		{
			r1 = 0;
		}
		for (int j = 0; j < i; ++j)
		{
			if (dist[j].d2>r2)
			{
				r2 = dist[j].d2;
			}
		}
		if (i == 0)
		{
			currentMax = r1 + r2;
		}
		if (r1 + r2 < currentMax)
		{
			currentMax = r1 + r2;
		}
	}
	cout << currentMax;
}

int distanceOfAB(cor A, cor B)
{
	int dis;
	dis = (A.x - B.x)*(A.x - B.x) + (A.y - B.y)*(A.y - B.y);
	return dis;
}

void sort()
{
	dis temp;
	for (int i = 1; i <n ; ++i)
	{
		for (int j = i; j > 0; --j)
		{
			if (dist[j].d1 > dist[j - 1].d1)
			{
				temp = dist[j];
				dist[j] = dist[j - 1];
				dist[j - 1] = temp;
			}
		}
	}
}


#include<iostream>
#include<math.h>
using namespace std;
double dis(int x1, int y1, int x2, int y2);
int main()
{
	int a = 1999;
	int b = 1999;
	double c, d;
	c = d = 0;
	int n;
	long long int t1[2000] = { 0 };
	long long int t2[2000] = { 0 };
	double z1, z2;
	int x1, y1, x2, y2;
	cin >> n >> x1 >> y1 >> x2 >> y2;
	int i;
	for (i = 0; i < n; i++)
	{
		cin >> t1[i] >> t2[i];
		z1 = dis(x1, y1, t1[i], t2[i]);
		z2 = dis(x2, y2, t1[i], t2[i]);
		if (z1 < z2)
		{
			if (c < z1)
			{
				a = i;
				c = z1;
			}
		}
		else
		{
			if (d < z2)
			{
				d = z2;
				b = i;
			}
		}
	}
	cout << (t1[a] - x1)*(t1[a] - x1) + (t2[a] - y1)*(t2[a] - y1) + (t1[b] - x2)*(t1[b] - x2) + (t2[b] - y2)*(t2[b] - y2);
	/*
	int c, d, e, f;
	cin >> c >> d >> e >> f;
	cout << dis(c, d, e, f);
	*/
	return 0;
}
double dis(int x1, int y1, int x2, int y2)
{
	int t;
	if (x1 > x2)
		swap(x1, x2);
	if (y1 > y2)
		swap(y1, y2);
	double h = y2 - y1;
	double w = x2 - x1;
	if (w < 0.000001)
		return h;
	else
	{
		double tan = h / w;
		double cosdao = pow(1 + tan*tan, 0.5);
		return w*cosdao;
	}
}


#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
struct coordinate{
	long long int x,y,distance_1,distance_2;
}a[2010];
bool cmp1(coordinate a,coordinate b)
{
	return a.distance_1<b.distance_1;
}
bool cmp2(coordinate a,coordinate b)
{
	return a.distance_2<b.distance_2;
}
int main()
{
	int n,x1,y1,x2,y2;
	cin>>n>>x1>>y1>>x2>>y2;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i].x>>a[i].y;
		a[i].distance_1=pow(x1-a[i].x,2)+pow(y1-a[i].y,2);
		a[i].distance_2=pow(x2-a[i].x,2)+pow(y2-a[i].y,2);
	}
	long long int sum1=0,min1=100000000000000000000;
	sort(a+1,a+n+1,cmp1);
	long long int max=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i].distance_2>=max)	max=a[i].distance_2;
	}
	min1=max;
	max=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			if(a[j].distance_2>=max)	max=a[j].distance_2;
		}
		sum1=a[i].distance_1+max;
		if(sum1<=min1)	min1=sum1;
	}
	long long int sum2=0,min2=100000000000000000000;
	sort(a+1,a+n+1,cmp2);
	max=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i].distance_1>=max)	max=a[i].distance_1;
	}
	min2=max;
	max=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			if(a[j].distance_1>=max)	max=a[j].distance_1;
		}
		sum2=a[i].distance_2+max;
		if(sum2<=min2)	min2=sum2;
	}
	long long int min;
	if(min1<=min2)	min=min1;
	else min=min2;
	cout<<min;
	return 0;
}


#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
struct coordinate{
	int x,y,distance_1,distance_2;
}a[2010];
bool cmp1(coordinate a,coordinate b)
{
	return a.distance_1<b.distance_1;
}
bool cmp2(coordinate a,coordinate b)
{
	return a.distance_2<b.distance_2;
}
int main()
{
	int n,x1,y1,x2,y2;
	cin>>n>>x1>>y1>>x2>>y2;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i].x>>a[i].y;
		a[i].distance_1=pow(x1-a[i].x,2)+pow(y1-a[i].y,2);
		a[i].distance_2=pow(x2-a[i].x,2)+pow(y2-a[i].y,2);
	}
	long long int sum1=0,min1=100000000000000000000;
	sort(a+1,a+n+1,cmp1);
	for(int i=1;i<=n;i++)
	{
		long long int max=0;
		for(int j=i+1;j<=n;j++)
		{
			if(a[j].distance_2>=max)	max=a[j].distance_2;
		}
		sum1=a[i].distance_1+max;
		if(sum1<=min1)	min1=sum1;
	}
	long long int sum2=0,min2=100000000000000000000;
	sort(a+1,a+n+1,cmp2);
	for(int i=1;i<=n;i++)
	{
		long long int max=0;
		for(int j=i+1;j<=n;j++)
		{
			if(a[j].distance_1>=max)	max=a[j].distance_1;
		}
		sum2=a[i].distance_2+max;
		if(sum2<=min2)	min2=sum2;
	}
	long long int min;
	if(min1<=min2)	min=min1;
	else min=min2;
	cout<<min;
	return 0;
}


#include <iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;

int main(){
    int n;
    long long x,y,p,q,max_1,max_2,result,tmp_1,tmp_2;
    long long A[2000];
    long long B[2000];
    long long C[2000];
    scanf("%d%lld%lld%lld%lld",&n,&x,&y,&p,&q);
    for(int i=0;i<n;i++){
        scanf("%lld%lld",&tmp_1,&tmp_2);
        A[i]=(tmp_1-x)*(tmp_1-x)+(tmp_2-y)*(tmp_2-y);
        B[i]=(tmp_1-p)*(tmp_1-p)+(tmp_2-q)*(tmp_2-q);
        C[i]=A[i];
    }
    sort(A,A+n);
    result=1e15;
    for(int j=0;j<n+1;j++){
        if(j==0){
            max_1=0;
        }
        else{
            max_1=A[j-1];
        }
        max_2=0;
        for(int k=0;k<n;k++) {
            if (C[k] > max_1 && B[k] > max_2) {
                max_2 = B[k];

            }
        }
        if(max_1+max_2<result){
            result=max_1+max_2;
        }

    }
    printf("%lld\n",result);

}


#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

struct flower{
	long long d1,d2;
}a[2001]={};

long long distance(long long x,long long y,long long a,long long b){
	return (x-a)*(x-a)+(y-b)*(y-b);
}

int main(){
  int n;
  long long r1,r2,mini=1e16,x1,x2,y1,y2,i,x,y;
  cin>>n>>x1>>y1>>x2>>y2;
  for(i=1;i<=n;i++) {
  	cin>>x>>y;
  	a[i].d1=distance(x,y,x1,y1);
  	a[i].d2=distance(x,y,x2,y2);
  }

  if(n==1) mini=min(a[1].d1,a[1].d2);
  else for(i=1;i<=n;i++){
  	     r1=a[i].d1;
  	     r2=0;
  	     for(int j=1;j<=n;j++)
  		    if(a[j].d1>r1&&a[j].d2>r2) r2=a[j].d2;
       	if(r1+r2<mini) mini=r1+r2;

  }
  cout<<mini<<endl;

return 0;
}


#include <iostream>
using namespace std;

int cor[2000][2]={0};
void sort(int num,int index);
int main(){
    int num=0;
    int x,y,x1,y1,x2,y2=0;
    int r1_2=0;
    int r2_2=0;
    int res1,res2=0;
    cin>>num>>x1>>y1>>x2>>y2;
    for (int i = 0; i < num; ++i) {
        cin>>x>>y;
        cor[i][0]=(x-x1)*(x-x1)+(y-y1)*(y-y1);
        cor[i][1]=(x-x2)*(x-x2)+(y-y2)*(y-y2);
    }
    sort(num,0);
    for (int j = 0; j < num; ++j) {
        if(cor[j][0]-r1_2<cor[j][1]-r2_2&&cor[j][1]>r2_2)r1_2=cor[j][0];
        else if(cor[j][1]>r2_2)r2_2=cor[j][1];
    }
    res1=r1_2+r2_2;

    r1_2=0;
    r2_2=0;
    sort(num,1);
    for (int k = 0; k < num; ++k) {
        if(cor[k][1]-r2_2<cor[k][0]-r1_2&&cor[k][0]>r1_2)r2_2=cor[k][1];
        else if(cor[k][0]>r1_2)r1_2=cor[k][0];
    }
    res2=r1_2+r2_2;
    if(res1<res2)cout<<res1<<endl;
    else cout<<res2<<endl;

    return 0;
}

void sort(int num,int index){
    int temp1,temp2=0;
    for (int i = 0; i < num; ++i) {
        for (int j = 0; j < num - 1; ++j) {
            if(cor[j][index]>cor[j+1][index]){
                temp1=cor[j][index];
                cor[j][index]=cor[j+1][index];
                cor[j+1][index]=temp1;

                temp2=cor[j][1-index];
                cor[j][1-index]=cor[j+1][1-index];
                cor[j+1][1-index]=temp2;
            }
        }
    }
}


#include<stdio.h>
#include<iostream>
#include<set>
using namespace std;
const int maxn=2077;

double dis(double x1,double y1,double x2,double y2){
        return (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2);
}

int N,X1,Y1,X2,Y2;

struct NODE{
        int x,y;
        double d;
        bool operator <(const NODE &o)const{
                return d<o.d;
        }
};
set<NODE> S1,S2;

double ans=1.0/0.0;

int main(){
        scanf("%d%d%d%d%d",&N,&X1,&Y1,&X2,&Y2);
        for(int i=0;i<N;++i){
                int x,y;scanf("%d%d",&x,&y);
                S1.insert((NODE){x,y,dis(x,y,X1,Y1)});
        }

        ans=S1.rbegin()->d;
        set<NODE>::reverse_iterator it=S1.rbegin();
        S2.insert((NODE){it->x,it->y,dis(it->x,it->y,X2,Y2)});
        S1.erase(*it);

        while(!S1.empty()){
                ans=min(ans, S1.rbegin()->d + S2.rbegin()->d);
                set<NODE>::reverse_iterator it=S1.rbegin();
                S2.insert((NODE){it->x,it->y,dis(it->x,it->y,X2,Y2)});
                S1.erase(*it);
        }

        ans=min(ans, S2.rbegin()->d);

        printf("%lld\n",(long long)(ans+0.1));
}