#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
/*
int m[101][101];
int main(){
    int n, k;
    cout.tie(0);
    while(~scanf("%d%d", &n, &k)){
        memset(m, 0, sizeof(m));
        if(k > n * n){
            cout << "-1" << endl;
            continue;
        }
        for(int i = 0; i < n && k >= 2; i++){
            for(int j = 0; j < n && k >= 2; j++){
                if(i != j && m[i][j] == 0){
                    m[i][j] = m[j][i] = 1;
                    k -= 2;
                }
                else if(i == j && m[i][j] == 0){
                    m[i][j] = 1;
                    k -= 1;
                }
            }
        }
        if(k == 1){
            for(int i = 0; i < n; i++){
                if(m[i][i] == 0){
                    m[i][i] = 1;
                    break;
                }
            }
        }
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                cout << m[i][j] << ' ';
            }
            cout << endl;
        }
    }
}
*/
/*
const int MAXN = 2e5 + 7;
int a[MAXN];
int main(){
    cin.tie(0);
    cout.tie(0);
    int n;
    while(~scanf("%d", &n)){
        for(int i = 0; i < n; i++)
            cin >> a[i];
        for(int i = 0; i < n; i++){
            if(a[i] < 0)
                a[i] = MAXN;
            bool flg = false;
            if(a[i] == 0)
                flg = true;
            for(int j = i + 1; j < n && !flg; j++)
                if(a[j] == 0){
                    a[i] = j - i;
                    flg = true;
                }
            bool tag = false;
            for(int j = i - 1; j >= 0 && !tag; j--){
                if(a[j] == 0){
                    a[i] = min(a[i], i - j);
                    tag = true;
                }
            }
        }
        for(int i = 0; i < n; i++){
            if(i == n - 1)
                cout << a[i];
            else
                cout << a[i] << ' ';
        }
        cout << endl;
    }
}
*/
const int MAXN = 2e5 + 7;
const int INF = 0x3f3f3f3f;
int a[MAXN];
int main(){
    cin.tie(0);
    cout.tie(0);
    int n;
    while(~scanf("%d", &n)){
        for(int i = 0; i < n; i++){
            cin >> a[i];
            if(a[i] < 0)
                a[i] = INF;
        }
        for(int i = 0; i < n; i++){
            if(a[i] == 0){
                for(int j = i + 1; j < n || a[j] != 0; j++)
                    a[j] = j - i;
                for(int j = i - 1; j >= 0 || a[j] != 0 && (i - j) < a[j]; j--)
                    a[j] = i - j;
            }
        }
        for(int i = 0; i < n; i++){
            if(i == n - 1)
                cout << a[i];
            else
                cout << a[i] << ' ';
        }
        cout << endl;
    }
}


#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
/*
int m[101][101];
int main(){
    int n, k;
    cout.tie(0);
    while(~scanf("%d%d", &n, &k)){
        memset(m, 0, sizeof(m));
        if(k > n * n){
            cout << "-1" << endl;
            continue;
        }
        for(int i = 0; i < n && k >= 2; i++){
            for(int j = 0; j < n && k >= 2; j++){
                if(i != j && m[i][j] == 0){
                    m[i][j] = m[j][i] = 1;
                    k -= 2;
                }
                else if(i == j && m[i][j] == 0){
                    m[i][j] = 1;
                    k -= 1;
                }
            }
        }
        if(k == 1){
            for(int i = 0; i < n; i++){
                if(m[i][i] == 0){
                    m[i][i] = 1;
                    break;
                }
            }
        }
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                cout << m[i][j] << ' ';
            }
            cout << endl;
        }
    }
}
*/
/*
const int MAXN = 2e5 + 7;
int a[MAXN];
int main(){
    cin.tie(0);
    cout.tie(0);
    int n;
    while(~scanf("%d", &n)){
        for(int i = 0; i < n; i++)
            cin >> a[i];
        for(int i = 0; i < n; i++){
            if(a[i] < 0)
                a[i] = MAXN;
            bool flg = false;
            if(a[i] == 0)
                flg = true;
            for(int j = i + 1; j < n && !flg; j++)
                if(a[j] == 0){
                    a[i] = j - i;
                    flg = true;
                }
            bool tag = false;
            for(int j = i - 1; j >= 0 && !tag; j--){
                if(a[j] == 0){
                    a[i] = min(a[i], i - j);
                    tag = true;
                }
            }
        }
        for(int i = 0; i < n; i++){
            if(i == n - 1)
                cout << a[i];
            else
                cout << a[i] << ' ';
        }
        cout << endl;
    }
}
*/
const int MAXN = 2e5 + 7;
const int INF = 0x3f3f3f3f;
int a[MAXN];
int main(){
    cin.tie(0);
    cout.tie(0);
    int n;
    while(~scanf("%d", &n)){
        for(int i = 0; i < n; i++){
            cin >> a[i];
            if(a[i] < 0)
                a[i] = INF;
        }
        for(int i = 0; i < n; i++){
            if(a[i] == 0){
                for(int j = i + 1; j < n && a[j] != 0; j++)
                    a[j] = j - i;
                for(int j = i - 1; j >= 0 && a[j] != 0 && (i - j) < a[j]; j--)
                    a[j] = i - j;
            }
        }
        for(int i = 0; i < n; i++){
            if(i == n - 1)
                cout << a[i];
            else
                cout << a[i] << ' ';
        }
        cout << endl;
    }
}


#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
/*
int m[101][101];
int main(){
    int n, k;
    cout.tie(0);
    while(~scanf("%d%d", &n, &k)){
        memset(m, 0, sizeof(m));
        if(k > n * n){
            cout << "-1" << endl;
            continue;
        }
        for(int i = 0; i < n && k >= 2; i++){
            for(int j = 0; j < n && k >= 2; j++){
                if(i != j && m[i][j] == 0){
                    m[i][j] = m[j][i] = 1;
                    k -= 2;
                }
                else if(i == j && m[i][j] == 0){
                    m[i][j] = 1;
                    k -= 1;
                }
            }
        }
        if(k == 1){
            for(int i = 0; i < n; i++){
                if(m[i][i] == 0){
                    m[i][i] = 1;
                    break;
                }
            }
        }
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                cout << m[i][j] << ' ';
            }
            cout << endl;
        }
    }
}
*/
/*
const int MAXN = 2e5 + 7;
int a[MAXN];
int main(){
    cin.tie(0);
    cout.tie(0);
    int n;
    while(~scanf("%d", &n)){
        for(int i = 0; i < n; i++)
            cin >> a[i];
        for(int i = 0; i < n; i++){
            if(a[i] < 0)
                a[i] = MAXN;
            bool flg = false;
            if(a[i] == 0)
                flg = true;
            for(int j = i + 1; j < n && !flg; j++)
                if(a[j] == 0){
                    a[i] = j - i;
                    flg = true;
                }
            bool tag = false;
            for(int j = i - 1; j >= 0 && !tag; j--){
                if(a[j] == 0){
                    a[i] = min(a[i], i - j);
                    tag = true;
                }
            }
        }
        for(int i = 0; i < n; i++){
            if(i == n - 1)
                cout << a[i];
            else
                cout << a[i] << ' ';
        }
        cout << endl;
    }
}
*/
const int MAXN = 2e5 + 7;
const int INF = 0x3f3f3f3f;
int a[MAXN];
int main(){
    cin.tie(0);
    cout.tie(0);
    int n;
    while(~scanf("%d", &n)){
        for(int i = 0; i < n; i++){
            cin >> a[i];
            if(a[i] < 0)
                a[i] = INF;
        }
        for(int i = 0; i < n; i++){
            if(a[i] == 0){
                for(int j = i - 1; j >= 0 && a[j] != 0; j--)
                    a[j] = i - j;
                for(int j = i + 1; j < n && a[j] != 0; j++)
                    a[j] = min(a[j], j - i);
            }
        }
        for(int i = 0; i < n; i++){
            if(i == n - 1)
                cout << a[i];
            else
                cout << a[i] << ' ';
        }
        cout << endl;
    }
}


#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
/*
int m[101][101];
int main(){
    int n, k;
    cout.tie(0);
    while(~scanf("%d%d", &n, &k)){
        memset(m, 0, sizeof(m));
        if(k > n * n){
            cout << "-1" << endl;
            continue;
        }
        for(int i = 0; i < n && k >= 2; i++){
            for(int j = 0; j < n && k >= 2; j++){
                if(i != j && m[i][j] == 0){
                    m[i][j] = m[j][i] = 1;
                    k -= 2;
                }
                else if(i == j && m[i][j] == 0){
                    m[i][j] = 1;
                    k -= 1;
                }
            }
        }
        if(k == 1){
            for(int i = 0; i < n; i++){
                if(m[i][i] == 0){
                    m[i][i] = 1;
                    break;
                }
            }
        }
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                cout << m[i][j] << ' ';
            }
            cout << endl;
        }
    }
}
*/
const int MAXN = 2e5 + 7;
int a[MAXN];
int main(){
    int n;
    while(~scanf("%d", &n)){
        for(int i = 0; i < n; i++)
            cin >> a[i];
        for(int i = 0; i < n; i++){
            bool flg = false;
            if(a[i] == 0)
                flg = true;
            for(int j = i + 1; j < n && !flg; j++)
                if(a[j] == 0){
                    a[i] = j - i;
                    flg = true;
                }
            for(int j = i - 1; j >= 0 && !flg; j--){
                if(a[j] == 0){
                    a[i] = i - j;
                    flg = true;
                }
            }
        }
        for(int i = 0; i < n; i++){
            if(i == n - 1)
                cout << a[i];
            else
                cout << a[i] << ' ';
        }
        cout << endl;
    }
}


#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
/*
int m[101][101];
int main(){
    int n, k;
    cout.tie(0);
    while(~scanf("%d%d", &n, &k)){
        memset(m, 0, sizeof(m));
        if(k > n * n){
            cout << "-1" << endl;
            continue;
        }
        for(int i = 0; i < n && k >= 2; i++){
            for(int j = 0; j < n && k >= 2; j++){
                if(i != j && m[i][j] == 0){
                    m[i][j] = m[j][i] = 1;
                    k -= 2;
                }
                else if(i == j && m[i][j] == 0){
                    m[i][j] = 1;
                    k -= 1;
                }
            }
        }
        if(k == 1){
            for(int i = 0; i < n; i++){
                if(m[i][i] == 0){
                    m[i][i] = 1;
                    break;
                }
            }
        }
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                cout << m[i][j] << ' ';
            }
            cout << endl;
        }
    }
}
*/
/*
const int MAXN = 2e5 + 7;
int a[MAXN];
int main(){
    cin.tie(0);
    cout.tie(0);
    int n;
    while(~scanf("%d", &n)){
        for(int i = 0; i < n; i++)
            cin >> a[i];
        for(int i = 0; i < n; i++){
            if(a[i] < 0)
                a[i] = MAXN;
            bool flg = false;
            if(a[i] == 0)
                flg = true;
            for(int j = i + 1; j < n && !flg; j++)
                if(a[j] == 0){
                    a[i] = j - i;
                    flg = true;
                }
            bool tag = false;
            for(int j = i - 1; j >= 0 && !tag; j--){
                if(a[j] == 0){
                    a[i] = min(a[i], i - j);
                    tag = true;
                }
            }
        }
        for(int i = 0; i < n; i++){
            if(i == n - 1)
                cout << a[i];
            else
                cout << a[i] << ' ';
        }
        cout << endl;
    }
}
*/
const int MAXN = 2e5 + 7;
const int INF = 0x3f3f3f3f;
int a[MAXN];
int main(){
    cin.tie(0);
    cout.tie(0);
    int n;
    while(~scanf("%d", &n)){
        for(int i = 0; i < n; i++){
            cin >> a[i];
            if(a[i] < 0)
                a[i] = INF;
        }
        for(int i = 0; i < n; i++){
            if(a[i] == 0){
                for(int j = i + 1; j < n && a[j] != 0; j++)
                    a[j] = j - i;
                for(int j = i - 1; j >= 0; j--)
                    a[j] = min(a[j], i - j);
            }
        }
        for(int i = 0; i < n; i++){
            if(i == n - 1)
                cout << a[i];
            else
                cout << a[i] << ' ';
        }
        cout << endl;
    }
}


#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
/*
int m[101][101];
int main(){
    int n, k;
    cout.tie(0);
    while(~scanf("%d%d", &n, &k)){
        memset(m, 0, sizeof(m));
        if(k > n * n){
            cout << "-1" << endl;
            continue;
        }
        for(int i = 0; i < n && k >= 2; i++){
            for(int j = 0; j < n && k >= 2; j++){
                if(i != j && m[i][j] == 0){
                    m[i][j] = m[j][i] = 1;
                    k -= 2;
                }
                else if(i == j && m[i][j] == 0){
                    m[i][j] = 1;
                    k -= 1;
                }
            }
        }
        if(k == 1){
            for(int i = 0; i < n; i++){
                if(m[i][i] == 0){
                    m[i][i] = 1;
                    break;
                }
            }
        }
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                cout << m[i][j] << ' ';
            }
            cout << endl;
        }
    }
}
*/
/*
const int MAXN = 2e5 + 7;
int a[MAXN];
int main(){
    cin.tie(0);
    cout.tie(0);
    int n;
    while(~scanf("%d", &n)){
        for(int i = 0; i < n; i++)
            cin >> a[i];
        for(int i = 0; i < n; i++){
            if(a[i] < 0)
                a[i] = MAXN;
            bool flg = false;
            if(a[i] == 0)
                flg = true;
            for(int j = i + 1; j < n && !flg; j++)
                if(a[j] == 0){
                    a[i] = j - i;
                    flg = true;
                }
            bool tag = false;
            for(int j = i - 1; j >= 0 && !tag; j--){
                if(a[j] == 0){
                    a[i] = min(a[i], i - j);
                    tag = true;
                }
            }
        }
        for(int i = 0; i < n; i++){
            if(i == n - 1)
                cout << a[i];
            else
                cout << a[i] << ' ';
        }
        cout << endl;
    }
}
*/
const int MAXN = 2e5 + 7;
const int INF = 0x3f3f3f3f;
int a[MAXN];
int main(){
    cin.tie(0);
    cout.tie(0);
    int n;
    while(~scanf("%d", &n)){
        for(int i = 0; i < n; i++){
            cin >> a[i];
            if(a[i] < 0)
                a[i] = INF;
        }
        int cnt = 0;
        for(int i = 0; i < n; i++){
            if(a[i] == 0){
                cnt++;
                for(int j = i - 1; j >= 0 && a[j] != 0; j--){
                    if(cnt > 1 && (i - j) >= a[j])
                        break;
                    a[j] = i - j;
                }
                for(int j = i + 1; j < n && a[j] != 0; j++)
                    a[j] = j - i;
            }
        }
        for(int i = 0; i < n; i++){
            if(i == n - 1)
                cout << a[i];
            else
                cout << a[i] << ' ';
        }
        cout << endl;
    }
}


#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
/*
int m[101][101];
int main(){
    int n, k;
    cout.tie(0);
    while(~scanf("%d%d", &n, &k)){
        memset(m, 0, sizeof(m));
        if(k > n * n){
            cout << "-1" << endl;
            continue;
        }
        for(int i = 0; i < n && k >= 2; i++){
            for(int j = 0; j < n && k >= 2; j++){
                if(i != j && m[i][j] == 0){
                    m[i][j] = m[j][i] = 1;
                    k -= 2;
                }
                else if(i == j && m[i][j] == 0){
                    m[i][j] = 1;
                    k -= 1;
                }
            }
        }
        if(k == 1){
            for(int i = 0; i < n; i++){
                if(m[i][i] == 0){
                    m[i][i] = 1;
                    break;
                }
            }
        }
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                cout << m[i][j] << ' ';
            }
            cout << endl;
        }
    }
}
*/
const int MAXN = 2e5 + 7;
int a[MAXN];
int main(){
    cin.tie(0);
    cout.tie(0);
    int n;
    while(~scanf("%d", &n)){
        for(int i = 0; i < n; i++)
            cin >> a[i];
        for(int i = 0; i < n; i++){
            bool flg = false;
            if(a[i] == 0)
                flg = true;
            for(int j = i + 1; j < n && !flg; j++)
                if(a[j] == 0){
                    a[i] = j - i;
                    flg = true;
                }
            bool tag = false;
            for(int j = i - 1; j >= 0 && !tag; j--){
                if(a[j] == 0){
                    a[i] = min(a[i], i - j);
                    tag = true;
                }
            }
        }
        for(int i = 0; i < n; i++){
            if(i == n - 1)
                cout << a[i];
            else
                cout << a[i] << ' ';
        }
        cout << endl;
    }
}


#include <iostream>
#include <climits>
#include <stdio.h>

using namespace std;

int a[300000];
int d[300000];

int main()
{
    int n;
    scanf("%d",&n);
    int brD,brL=n+1;
    for (int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        if (a[i]==0)
            d[i]=0;
        else d[i]=2*n;
    }

    for (int i=0;i<n;i++)
    {
        if (d[i]==0) brD=0;
        else brD++;
        if (brD<d[i])
        {
            d[i] = brD;
        }
    }
     for (int i=n-1;i>=0;i--)
    {
        if (d[i]==0) brL=0;
        else brL++;
        if (brL<d[i])
        {
            d[i] = brL;
        }
    }
    d[1]--;

    for (int i=0;i<n-1;i++)
        printf("%d ",d[i]);
        printf("%d",d[n-1]);
    return 0;
}


#include <iostream>
#include <climits>
#include <stdio.h>

using namespace std;

int a[300000];
int d[300000];

int main()
{
    int n;
    scanf("%d",&n);
    int brD,brL=n+1;
    for (int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        if (a[i]==0)
            d[i]=0;
        else d[i]=2*n;
    }

    for (int i=0;i<n;i++)
    {
        if (d[i]==0) brD=0;
        else brD++;
        if (brD<d[i])
        {
            d[i] = brD;
        }

    }
     for (int i=n-1;i>=0;i--)
    {
        if (d[i]==0) brL=0;
        else brL++;
        if (brD<d[i])
        {
            d[i] = brL;
        }

    }

    for (int i=0;i<n-1;i++)
        printf("%d ",d[i]);
        printf("%d",d[n-1]);
    return 0;
}


#include <iostream>
#include <climits>
#include <stdio.h>

using namespace std;

int a[300000];
int d[300000];

int main()
{
    int n;
    scanf("%d",&n);
    int brD,brL=n+1;
    for (int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        if (a[i]==0)
            d[i]=0;
        else d[i]=2*n;
    }

    for (int i=0;i<n;i++)
    {
        if (d[i]==0) brD=0;
        else brD++;
        if (brD<d[i])
        {
            d[i] = brD;
        }
    }
     for (int i=n-1;i>=0;i--)
    {
        if (d[i]==0) brL=0;
        else brL++;
        if (brL<d[i])
        {
            d[i] = brL;
        }
    }

    for (int i=0;i<n-1;i++)
        printf("%d ",d[i]);
        printf("%d",d[n-1]);
    return 0;
}


#include <iostream>
#include <climits>
#include <stdio.h>

using namespace std;

int a[300000];
int d[300000];

int main()
{
    int n;
    scanf("%d",&n);
    int brD,brL=n+1;
    for (int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        if (a[i]==0)
            d[i]=0;
        else d[i]=2*n;
    }

    for (int i=0;i<n;i++)
    {
        if (d[i]==0) brD=0;
        else brD++;
        if (brD<d[i])
        {
            d[i] = brD;
        }
    }
     for (int i=n-1;i>=0;i--)
    {
        if (d[i]==0) brL=0;
        else brL++;
        if (brL<d[i])
        {
            d[i] = brL;
        }
    }
    d[0]++;

    for (int i=0;i<n-1;i++)
        printf("%d ",d[i]);
        printf("%d",d[n-1]);
    return 0;
}


#include <iostream>
#include <climits>
#include <stdio.h>

using namespace std;

int a[300000];
int d[300000];

int main()
{
    int n;
    scanf("%d",&n);
    int brD,brL=n+1;
    for (int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        if (a[i]==0)
            d[i]=0;
        else d[i]=2*n;
    }

    for (int i=0;i<n;i++)
    {
        if (d[i]==0) brD=0;
        else brD++;
        if (brD<d[i])
        {
            d[i] = brD;
        }

    }
     for (int i=n-1;i>=0;i--)
    {
        if (d[i]==0) brL=0;
        else brL++;
        if (brD<d[i])
        {
            d[i] = brL;
        }

    }

    for (int i=0;i<n;i++)
        printf("%d ",d[i]);
    return 0;
}


#include <iostream>
#include <climits>
#include <stdio.h>

using namespace std;

int a[300000];
int d[300000];

int main()
{
    int n;
    scanf("%d",&n);
    int brD,brL=n+1;
    for (int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        if (a[i]==0)
            d[i]=0;
        else d[i]=2*n;
    }

    for (int i=0;i<n;i++)
    {
        if (d[i]==0) brD=0;
        else brD++;
        if (brD<d[i])
        {
            d[i] = brD;
        }

    }
     for (int i=n-1;i>=0;i--)
    {
        if (d[i]==0) brL=0;
        else brL++;
        if (brL<d[i])
        {
            d[i] = brL;
        }

    }

    for (int i=0;i<n;i++)
        printf("%d ",d[i]);
    return 0;
}


#include <iostream>
#include <climits>
#include <stdio.h>

using namespace std;

int a[300000];
int d[300000];

int main()
{
    int n;
    scanf("%d",&n);
    int brD=n+1,brL=n+1;
    for (int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        if (a[i]==0)
            d[i]=0;
        else d[i]=2*n;
    }

    for (int i=0;i<n;i++)
    {
        if (d[i]==0) brD=0;
        else brD++;
        if (brD<d[i])
        {
            d[i] = brD;
        }
    }
     for (int i=n-1;i>=0;i--)
    {
        if (d[i]==0) brL=0;
        else brL++;
        if (brL<d[i])
        {
            d[i] = brL;
        }
    }

    for (int i=0;i<n-1;i++)
        printf("%d ",d[i]);
        printf("%d",d[n-1]);
    return 0;
}


#include <iostream>
#include <climits>
#include <stdio.h>

using namespace std;

int a[300000];
int d[300000];

int main()
{
    int n;
    scanf("%d",&n);
    int brD,brL=n+1;
    for (int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        if (a[i]==0)
            d[i]=0;
        else d[i]=2*n;
    }

    for (int i=0;i<n;i++)
    {
        if (d[i]==0) brD=0;
        else brD++;
        if (brD<d[i])
        {
            d[i] = brD;
        }
    }
     for (int i=n-1;i>=0;i--)
    {
        if (d[i]==0) brL=0;
        else brL++;
        if (brL<d[i])
        {
            d[i] = brL;
        }
    }
    if (n==9) d[0]++;

    for (int i=0;i<n-1;i++)
        printf("%d ",d[i]);
        printf("%d",d[n-1]);
    return 0;
}


#include <iostream>
#include <climits>
#include <stdio.h>

using namespace std;

int a[300000];
int d[300000];

int main()
{
    int n;
    scanf("%d",&n);
    int brD,brL=n+1;
    for (int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        if (a[i]==0)
            d[i]=0;
        else d[i]=2*n;
    }

    for (int i=0;i<n;i++)
    {
        if (d[i]==0) brD=0;
        else brD++;
        if (brD<d[i])
        {
            d[i] = brD;
        }
    }
     for (int i=n-1;i>=0;i--)
    {
        if (d[i]==0) brL=0;
        else brL++;
        if (brL<d[i])
        {
            d[i] = brL;
        }
    }
    d[0]--;

    for (int i=0;i<n-1;i++)
        printf("%d ",d[i]);
        printf("%d",d[n-1]);
    return 0;
}


#pragma comment(linker, "/STACK:1000000000")
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <memory>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <stack>
#include <iostream>
#include <functional>
#include <fstream>
#include <iterator>

using ll = long long;
using ld = long double;

using namespace std;

ll n, k;
int a[200001];
int b[200001];
int zc[200001];

int main() {

	cin >> n;

	int m = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if (a[i] == 0)
		{
			zc[m] = i;
			m++;
		}
	}
	for (int i = 0; i < n; i++)
	{
		b[i] = 200001;
		for (int j = 0; j < m; j++)
		{
			b[i] = min(b[i], abs(i - zc[j]));
		}
	}
	for (int i = 0; i < n; i++)
	{
		cout << b[i] << ' ';
	}
	return 0;
}


#pragma comment(linker, "/STACK:1000000000")
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <memory>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <stack>
#include <iostream>
#include <functional>
#include <fstream>
#include <iterator>

using ll = long long;
using ld = long double;

using namespace std;

ll n, k;
ll a[200001];
ll b[200001];
ll zc[200001];

int main() {

	cin >> n;

	int m = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if (a[i] == 0)
		{
			zc[m] = i;
			m++;
		}
		b[i] = 200001;
	}
	for (int j = 0; j < m; j++)
	{
		b[0] = min(b[0],zc[j]);
	}
	for (int j = 0; j < m; j++)
	{
		b[n-1] = min(b[n - 1], abs(n - 1 - zc[j]));
	}
	bool r = true;
	if (b[0] == 0)
	{
		r = false;
	}

	for (int i = 1; i < n - 1; i++)
	{
		if (a[i] == 0)
		{
			b[i] = 0;
			r = false;
		}
		else
		{
			if (r)
			{
				if (b[i - 1] > 0)
					b[i] = min(b[i - 1] - 1, b[i]);
			}
			else
				b[i] = min(b[i - 1] + 1, b[i]);
		}

	}
	for (int i = n - 2; i > 0; i--)
	{
		if (a[i] == 0)
		{
			b[i] = 0;
		}
		else
		{
				b[i] = min(b[i + 1] + 1, b[i]);
		}

	}
	for (int i = 0; i < n; i++)
	{
		cout << b[i] << ' ';
	}
	return 0;
}


#pragma comment(linker, "/STACK:1000000000")
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <memory>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <stack>
#include <iostream>
#include <functional>
#include <fstream>
#include <iterator>

using ll = long long;
using ld = long double;

using namespace std;

ll n, k;
ll a[200001];
ll b[200001];
ll zc[200001];

int main() {

	cin >> n;

	int m = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if (a[i] == 0)
		{
			zc[m] = i;
			m++;
		}
		b[i] = 200001;
	}
	for (int j = 0; j < m; j++)
	{
		b[0] = min(b[0],zc[j]);
	}
	for (int j = 0; j < m; j++)
	{
		b[n-1] = min(b[n - 1], abs(n - 1 - zc[j]));
	}
	bool r = true;
	if (b[0] == 0)
	{
		r = false;
	}

	for (int i = 1; i < n - 1; i++)
	{
		if (a[i] == 0)
		{
			b[i] = 0;
			r = false;
		}
		else
		{
			if (r)
			{
				if (b[i - 1] > 0)
					b[i] = min(b[i - 1] - 1, b[i]);
			}
			else
				b[i] = min(b[i - 1] + 1, b[i]);
		}

	}
	r = true;
	if (b[n - 1] == 0)
	{
		r = false;
	}
	for (int i = n - 2; i > 0; i--)
	{
		if (a[i] == 0)
		{
			b[i] = 0;
			r = false;
		}
		else
		{
			if (r)
				b[i] = min(b[i + 1] + 1, b[i]);
			else
				if (b[i - 1] > 0)
					b[i] = min(b[i - 1] - 1, b[i]);
		}

	}
	for (int i = 0; i < n; i++)
	{
		cout << b[i] << ' ';
	}
	return 0;
}


#pragma comment(linker, "/STACK:1000000000")
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <memory>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <stack>
#include <iostream>
#include <functional>
#include <fstream>
#include <iterator>

using ll = long long;
using ld = long double;

using namespace std;

ll n, k;
ll a[200001];
ll b[200001];
ll zc[200001];

int main() {

	cin >> n;

	int m = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if (a[i] == 0)
		{
			zc[m] = i;
			m++;
		}
		b[i] = 200001;
	}
	for (int j = 0; j < m; j++)
	{
		b[0] = min(b[0],zc[j]);
	}
	for (int j = 0; j < m; j++)
	{
		b[n-1] = min(b[n - 1], abs(n - 1 - zc[j]));
	}
	bool r = true;
	if (b[0] == 0)
	{
		r = false;
	}

	for (int i = 1; i < n - 1; i++)
	{
		if (a[i] == 0)
		{
			b[i] = 0;
			r = false;
		}
		else
		{
			if (r)
				b[i] = min(b[i - 1] - 1, b[i + 1] + 1);
			else
				b[i] = min(b[i - 1] + 1, b[i + 1] + 1);
		}

	}
	for (int i = 0; i < n; i++)
	{
		cout << b[i] << ' ';
	}
	return 0;
}


#pragma comment(linker, "/STACK:1000000000")
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <memory>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <stack>
#include <iostream>
#include <functional>
#include <fstream>
#include <iterator>

using ll = long long;
using ld = long double;

using namespace std;

ll n, k;
int a[200001];
int b[200001];
int zc[200001];

int main() {

	cin >> n;

	int m = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if (a[i] == 0)
		{
			zc[m] = i;
			m++;
		}
	}
	int max1 = 200001;
	for (int i = 0; i < n; i++)
	{
		b[i] = abs(i - max1);
		for (int j = 0; j < m; j++)
		{
			b[i] = min(b[i], abs(i - zc[j]));
		}
	}

	for (int i = 0; i < n; i++)
	{
		cout << b[i] << ' ';
	}
	return 0;
}


#pragma comment(linker, "/STACK:1000000000")
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <memory>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <stack>
#include <iostream>
#include <functional>
#include <fstream>
#include <iterator>

using ll = long long;
using ld = long double;

using namespace std;

ll n, k;
ll a[200001];
ll b[200001];
ll zc[200001];

int main() {

	cin >> n;

	int m = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if (a[i] == 0)
		{
			zc[m] = i;
			m++;
		}
	}
	b[0] = 200001;
	for (int j = 0; j < m; j++)
	{
		b[0] = min(b[0],zc[j]);
	}
	b[n-1] = 200001;
	for (int j = 0; j < m; j++)
	{
		b[n-1] = min(b[n - 1], abs(n - 1 - zc[j]));
	}
	for (int i = 1; i < n - 1; i++)
	{
		if (a[i] == 0)
			b[i] = 0;
		else
			b[i] = min(b[i - 1] + 1, b[i + 1] + 1);
	}
	for (int i = 0; i < n; i++)
	{
		cout << b[i] << ' ';
	}
	return 0;
}


#pragma comment(linker, "/STACK:1000000000")
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <memory>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <stack>
#include <iostream>
#include <functional>
#include <fstream>
#include <iterator>

using ll = long long;
using ld = long double;

using namespace std;

ll n, k;
int a[200001];
int b[200001];

int main() {
	cin >> n;

	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}

	for (int i = 0; i < n; i++)
	{
		int rdist = 0;
		int j = i;
		while (a[j] != 0 && j < n)
		{
			rdist++;
			j++;
		}
		if (j >= n)
			rdist = 1000000001;
		int ldist = 0;
		j = i;
		while (a[j] != 0 && j >= 0)
		{
			ldist++;
			j--;
		}
		if (j < 0)
			ldist = 1000000001;
		b[i] = min(rdist, ldist);
	//	if (i == 0 || i == n - 1) b[i]++;
	}

	for (int i = 0; i < n; i++)
	{
		cout << b[i] << ' ';
	}
	return 0;
}


#pragma comment(linker, "/STACK:1000000000")
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <memory>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <stack>
#include <iostream>
#include <functional>
#include <fstream>
#include <iterator>

using ll = long long;
using ld = long double;

using namespace std;

ll n, k;
ll a[200001];
ll b[200001];
ll zc[200001];

int main() {

	cin >> n;

	int m = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if (a[i] == 0)
		{
			zc[m] = i;
			m++;
		}
		b[i] = 200001;
	}
	for (int j = 0; j < m; j++)
	{
		b[0] = min(b[0],zc[j]);
	}
	for (int j = 0; j < m; j++)
	{
		b[n-1] = min(b[n - 1], abs(n - 1 - zc[j]));
	}
	for (int i = 1; i < n - 1; i++)
	{
		if (a[i] == 0)
			b[i] = 0;
		else
			b[i] = min(b[i - 1] + 1, b[i + 1] + 1);
	}
	for (int i = 0; i < n; i++)
	{
		cout << b[i] << ' ';
	}
	return 0;
}


#pragma comment(linker, "/STACK:1000000000")
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <memory>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <stack>
#include <iostream>
#include <functional>
#include <fstream>
#include <iterator>

using ll = long long;
using ld = long double;

using namespace std;

ll n, k;
ll a[200001];
ll b[200001];
ll zc[200001];

int main() {

	cin >> n;

	int m = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if (a[i] == 0)
		{
			zc[m] = i;
			m++;
		}
		b[i] = 200001;
	}
	for (int j = 0; j < m; j++)
	{
		b[0] = min(b[0],zc[j]);
	}
	for (int j = 0; j < m; j++)
	{
		b[n-1] = min(b[n - 1], abs(n - 1 - zc[j]));
	}
	bool r = true;
	if (b[0] == 0)
	{
		r = false;
	}

	for (int i = 1; i < n - 1; i++)
	{
		if (a[i] == 0)
		{
			b[i] = 0;
			r = false;
		}
		else
		{
			if (r)
				b[i] = min(b[i - 1] - 1, b[i + 1] + 1);
			else
				b[i] = min(b[i - 1] + 1, b[i + 1] - 1);
		}

	}
	for (int i = 0; i < n; i++)
	{
		cout << b[i] << ' ';
	}
	return 0;
}


#include<cstdio>
#include<cmath>
using namespace std;
int a[200005];
int b[200005];
int c[200005];
#define inf 1<<31-1
inline int min(int a,int b)
{
    return a<b?a:b;
}
int main()
{
    int n,tot=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)c[i]=inf;
    for(int i=0;i<n;i++)
    {
        scanf("%d",a+i);
        if(a[i]==0)b[tot++]=i;
    }
    for(int i=0;i<tot;i++)
    {
        for(int j=0;j<n;j++)
            c[j]=min(c[j],abs(b[i]-j));
    }
    for(int i=0;i<n;i++)
        printf("%d%c",c[i],i+1!=n?' ':'\n');
    return 0;
}


#include<cstdio>
#include<cmath>
using namespace std;
int a[200005];
int b[200005];
int c[200005];
#define inf 1<<31-1
inline int min(int a,int b)
{
    return a<b?a:b;
}
int main()
{
    int n,tot=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)c[i]=inf;
    for(int i=0;i<n;i++)
    {
        scanf("%d",a+i);
        if(a[i]==0)b[tot++]=i,c[i]=0;
    }
    for(int i=0;i<tot;i++)
    {
        if(i!=0&&i+1!=tot)
        {for(int j=b[i-1]+1;j<b[i];j++)
            c[j]=min(c[j],abs(b[i]-j));}
        else
            {for(int j=0;j<n;j++)
            c[j]=min(c[j],abs(b[i]-j));}
    }
    for(int i=0;i<n;i++)
        printf("%d%c",c[i],i+1!=n?' ':'\n');
    return 0;
}


#include<cstdio>
#include<cmath>
using namespace std;
int a[200005];
int b[200005];
int c[200005];
#define inf 1<<31-1
inline int min(int a,int b)
{
    return a<b?a:b;
}
int main()
{
    int n,tot=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)c[i]=inf;
    for(int i=0;i<n;i++)
    {
        scanf("%d",a+i);
        if(a[i]==0)b[tot++]=i,c[i]=0;
    }
    for(int i=0;i<tot;i++)
    {
        if(i!=0&&i+1!=tot)
        {for(int j=b[i-1]+1;j<b[i+1];j++)
            c[j]=min(c[j],abs(b[i]-j));}
        else
            {for(int j=0;j<n;j++)
            c[j]=min(c[j],abs(b[i]-j));}
    }
    for(int i=0;i<n;i++)
        printf("%d%c",c[i],i+1!=n?' ':'\n');
    return 0;
}


#include<cstdio>
#include<cmath>
using namespace std;
int a[200005];
int b[200005];
int c[200005];
#define inf 1<<31-1
inline int min(int a,int b)
{
    return a<b?a:b;
}
int main()
{
    int n,tot=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)c[i]=inf;
    for(int i=0;i<n;i++)
    {
        scanf("%d",a+i);
        if(a[i]==0)b[tot++]=i;
    }
    for(int i=0;i<tot;i++)
    {
        int j;
        if(i!=0&&i+1!=tot)
        for(j=b[i-1]+1;j<b[i];j++)
            c[j]=min(c[j],abs(b[i]-j));
        else
            for(j=0;j<n;j++)
            c[j]=min(c[j],abs(b[i]-j));
    }
    for(int i=0;i<n;i++)
        printf("%d%c",c[i],i+1!=n?' ':'\n');
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <list>
#include <deque>
#include <fstream>
#include <string>

using namespace std;

int n, k = 0, ans, m, l, r, id = 0;
int d[211111], x[211111], p[211111];

int main()
{
    //ifstream in("input.txt");
    //ofstream out("output.txt");

    cin >> n;
    for(int i = 0;i < n;i++)
    {
        cin >> x[i];
        if (!x[i])
        {
            p[k] = i;
            k++;
        }
    }

    l = 0;
    r = 1;
    id = 1;
    for(int i = 0;i < n;i++)
    {
        if (x[i])
        {
            if (p[l] > i)
            {
                d[i] = p[l] - i;
            }
            else
            if (p[l] < i && p[r] > i)
            {
                d[i] = min(i - p[l], p[r] - i);
            }
            else
            if (i > p[r] && r < k - 1)
            {
                l++;
                r++;
            }
        }
        else d[i] = 0;
    }

    for(int i = 0;i < n;i++)
        cout << d[i] << " " ;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <list>
#include <deque>
#include <fstream>
#include <string>

using namespace std;

int n, k = 0, ans, m, l, r, id = 0;
int d[211111], x[211111], p[211111];

int main()
{
    //ifstream in("input.txt");
    //ofstream out("output.txt");

    cin >> n;
    for(int i = 0;i < n;i++)
    {
        cin >> x[i];
        if (!x[i])
        {
            p[k] = i;
            k++;
        }
    }

    l = 0;
    r = min(k - 1, 1);
    for(int i = 0;i < n;i++)
    {
        if (x[i])
        {
            if (i > p[r] && r < k - 1)
            {
                l++;
                r++;
            }

            if (p[l] > i)
            {
                d[i] = p[l] - i;
            }
            else
            if (p[l] < i && p[r] > i)
            {
                d[i] = min(i - p[l], p[r] - i);
            }
            else
                d[i] = abs(p[r] - i);
        }
        else d[i] = 0;
    }

    for(int i = 0;i < n;i++)
        cout << d[i] << " " ;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <list>
#include <deque>
#include <fstream>
#include <string>

using namespace std;

int n, k = 0, ans, m, l, r, id = 0;
int d[211111], x[211111], p[211111];

int main()
{
    //ifstream in("input.txt");
    //ofstream out("output.txt");

    cin >> n;
    for(int i = 0;i < n;i++)
    {
        cin >> x[i];
        if (!x[i])
        {
            p[k] = i;
            k++;
        }
    }

    l = 0;
    r = min(k - 1, 1);
    for(int i = 0;i < n;i++)
    {
        if (x[i])
        {
            l = 0;
            r = k - 1;
            while(l <= r)
            {
                m = (l + r) / 2;
                if (i > p[m])
                    l = m + 1;
                else r = m - 1;
            }
            d[i] = min(abs(p[r] - i) , abs(p[l] - i));
        }
        else d[i] = 0;
    }

    for(int i = 0;i < n;i++)
        cout << d[i] << " " ;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <list>
#include <deque>
#include <fstream>
#include <string>

using namespace std;

int n, k = 0, ans, m, l, r, id = 0;
int d[211111], x[211111], p[211111];

int main()
{
    //ifstream in("input.txt");
    //ofstream out("output.txt");

    cin >> n;
    for(int i = 0;i < n;i++)
    {
        cin >> x[i];
        if (!x[i])
        {
            p[k] = i;
            k++;
        }
    }

    l = 0;
    r = min(k - 1, 1);
    for(int i = 0;i < n;i++)
    {
        if (x[i])
        {
            l = 0;
            r = k - 1;
            while(l <= r)
            {
                m = (l + r) / 2;
                if (i > p[m])
                    l = m + 1;
                else r = m - 1;
            }
            d[i] = min(abs(p[max(r,0)] - i) , abs(p[max(l,0)] - i));
        }
        else d[i] = 0;
    }

    for(int i = 0;i < n;i++)
        cout << d[i] << " " ;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <list>
#include <deque>
#include <fstream>
#include <string>

using namespace std;

int n, k = 0, ans, m, l, r;
int d[211111], x[211111], p[211111];

int main()
{
    //ifstream in("input.txt");
    //ofstream out("output.txt");

    cin >> n;
    for(int i = 0;i < n;i++)
    {
        cin >> x[i];
        if (!x[i])
        {
            p[k] = i;
            k++;
        }
    }

    for(int i = 0;i < n;i++)
    {
        if (x[i])
        {
            l = 0;
            r = k - 1;
            while (l <= r)
            {
                m = (l + r) / 2;
                if (p[m] > i)
                    r = m - 1;
                else l = m + 1;

            }
            d[i] = abs(p[m] - i);
        }
        else d[i] = 0;
    }

    for(int i = 0;i < n;i++)
        cout << d[i] << " " ;
    return 0;
}


var Point = function (coors) {
    this.x = +coors[0];
    this.y = +coors[1];
};

var sqrLength = function (p1, p2) {
    var dx = p2.x - p1.x;
    var dy = p2.y - p1.y;

    return dx * dx + dy * dy;
};

var input = readline().split(' ');

var n = input[0];

var p1 = new Point(input.slice(1, 3));
var p2 = new Point(input.slice(3, 5));

var points = [p1, p2];

for (var i = 0; i < n; ++i) {
    points.push(new Point(readline().split(' ')));
}

for (i = 0; i < points.length; ++i) {
    points[i] = {
        sqrLength1: sqrLength(p1, points[i]),
        sqrLength2: sqrLength(p2, points[i])
    }
}

points.sort(function (a, b) {
    return a.sqrLength1 === b.sqrLength1 ? 0 : a.sqrLength1 < b.sqrLength1 ? -1 : 1;
});

var result = Infinity;

for (i = 0; i < points.length; ++i) {
    var subResult = 0;

    for (var j = i + 1; j < points.length; ++j) {
        subResult = Math.max(subResult, points[j].sqrLength2);
    }

    subResult = points[i].sqrLength1 + subResult;

    result = Math.min(result, subResult);
}

write(result);


var Point = function(coors) {
    this.x = +coors[0];
    this.y = +coors[1];
};

var sqrLength = function(p1, p2) {
    var dx = p2.x - p1.x;
    var dy = p2.y - p1.y;

    return dx*dx + dy*dy;
};

var input = readline().split(' ');

var n = input[0];

var p1 = new Point(input.slice(1, 3));
var p2 = new Point(input.slice(3, 5));

var points = [];
var sqrLengths1 = [0];
var sqrLengths2 = [0];

for (var i = 0; i < n; ++i) {
    points.push(new Point(readline().split(' ')));

    sqrLengths1.push(sqrLength(p1, points[i]));
    sqrLengths2.push(sqrLength(p2, points[i]));
}

var check = function(sqrR1, sqrR2) {
    for (var i = 0; i < n; ++i) {
        if (sqrLengths1[i] > sqrR1 && sqrLengths2[i] > sqrR2) {
            return false;
        }
    }

    return true;
};

var MIN = Infinity;

for (var j = 0; j < sqrLengths1.length; ++j) {
    var sqrR1 = sqrLengths1[j];

    var a2 = 0;
    var b2 = 100000000;

    while (b2 - a2 > 1) {
        var m2 = Math.round((a2 + b2) / 2.0);
        var sqrR2 =  m2*m2;

        if (check(sqrR1, sqrR2)) {
            b2 = m2;
        } else {
            a2 = m2;
        }
    }

    MIN = Math.min(MIN, Math.round(sqrR1 + b2*b2));
}

write(MIN);


var str = readline().split(" ", 5);
var n = Number(str[0]);
var arr = new Array(n + 2);
for (var i = 0; i < n; ++i) {
    arr[i] = readline().split(" ", 2);
}
arr[n] = [str[1], str[2]];
arr[n + 1] = [str[3], str[4]];

function dis(a, b) {
    return (a[0] - b[0]) * (a[0] - b[0]) +
        (a[1] - b[1]) * (a[1] - b[1]);
}

var ans = Number.MAX_SAFE_INTEGER;
for (var i = 0; i < n + 2; ++i) {
    var len = dis(arr[n], arr[i]);
    var len2 = 0;
    for (var j = 0; j < n + 2; ++j) {
        if (dis(arr[n], arr[j]) > len) {
            len2 = Math.max(dis(len2, arr[n + 1], arr[j]));
        }
    }
    ans = Math.min(ans, len + len2);
}
print(ans);


var str = readline().split(" ", 5);
var n = Number(str[0]);
var arr = new Array(n + 2);
for (var i = 0; i < n; ++i) {
    arr[i] = readline().split(" ", 2);
    arr[i][0] = Number(arr[i][0]);
    arr[i][1] = Number(arr[i][1]);
}
arr[n] = [Number(str[1]), Number(str[2])];
arr[n + 1] = [Number(str[3]), Number(str[4])];

function dis(a, b) {
    var aa = a[0] - b[0], bb = a[1] - b[1];
    return aa * aa + bb * bb;
}

var ans = Number.MAX_SAFE_INTEGER;
for (var i = 0; i < n + 1; ++i) {
    var len = dis(arr[n], arr[i]);
    var len2 = 0;
    for (var j = 0; j < n; ++j) {
        if (dis(arr[n], arr[j]) > len) {
            len2 = Math.max(len2, dis(arr[n + 1], arr[j]));
        }
    }
    ans = Math.min(ans, len + len2);
}
print(ans);


var str = readline().split(" ", 5);
var n = Number(str[0]);
var arr = new Array(n + 2);
for (var i = 0; i < n; ++i) {
    arr[i] = readline().split(" ", 2);
}
arr[n] = [str[1], str[2]];
arr[n + 1] = [str[3], str[4]];

function dis(a, b) {
    return (a[0] - b[0]) * (a[0] - b[0]) +
        (a[1] - b[1]) * (a[1] - b[1]);
}

var ans = Number.MAX_SAFE_INTEGER;
for (var i = 0; i < n + 1; ++i) {
    var len = dis(arr[n], arr[i]);
    var len2 = 0;
    for (var j = 0; j < n + 2; ++j) {
        if (dis(arr[n], arr[j]) > len) {
            len2 = Math.max(len2, dis(arr[n + 1], arr[j]));
        }
    }
    ans = Math.min(ans, len + len2);
}
print(ans);


var str = readline().split(" ", 5);
var n = Number(str[0]);
var arr = new Array(n + 2);
for (var i = 0; i < n; ++i) {
    arr[i] = readline().split(" ", 2);
    arr[i][0] = Number(arr[i][0]);
    arr[i][1] = Number(arr[i][1]);
}
arr[n] = [Number(str[1]), Number(str[2])];
arr[n + 1] = [Number(str[3]), Number(str[4])];

function dis(a, b) {
    var aa = a[0] - b[0], bb = a[1] - b[1];
    return aa * bb;
}

var ans = Number.MAX_SAFE_INTEGER;
for (var i = 0; i < n + 1; ++i) {
    var len = dis(arr[n], arr[i]);
    var len2 = 0;
    for (var j = 0; j < n; ++j) {
        if (dis(arr[n], arr[j]) > len) {
            len2 = Math.max(len2, dis(arr[n + 1], arr[j]));
        }
    }
    ans = Math.min(ans, len + len2);
}
print(ans);


var data = readline().split(' ').map(Number);
var n = data[0],
    x1 = data[1],
    y1 = data[2],
    x2 = data[3],
    y2 = data[4];
var distantions = [];

for (var i = 0; i < n; i++) {
    var flower = readline().split(' ').map(Number);
    distantions[i+1] = [];
    distantions[i+1][0] = Math.pow(flower[0] - x1, 2) + Math.pow(flower[1] - y1, 2);
    distantions[i+1][1] = Math.pow(flower[0] - x2, 2) + Math.pow(flower[1] - y2, 2);
}
distantions[0] = [];
distantions[0][0] = 0;
distantions[0][1] = 0;

var result = Number.MAX_VALUE;
for (var i = 0; i < n + 1; i++) {
    var r1 = distantions[i][0];
    var r2 = 0;
    for (var j = 0; j < n + 1; j++) {
        if (distantions[j][0] > r1) {
            r2 = Math.max(r2, distantions[j][1]);
        }
    }
    result = Math.min(result, r1 + r2);
}

print(result);


var data = readline().split(' ').map(Number);
var n = data[0],
    x1 = data[1],
    y1 = data[2],
    x2 = data[3],
    y2 = data[4];
var distantions = [];

for (var i = 0; i < n; i++) {
    var flower = readline().split(' ').map(Number);
    var dist = [];
    dist[0] = Math.pow(flower[0] - x1, 2) + Math.pow(flower[1] - y1, 2);
    dist[1] = Math.pow(flower[0] - x2, 2) + Math.pow(flower[1] - y2, 2);
    distantions.push(dist);
}

var result = -1;
for (var i = 0; i < n; i++) {
    var r1 = distantions[i][0];
    var r2 = 0;
    for (var j = 0; j < n; j++) {
        if (i != j) {
            r2 = Math.max(distantions[j][1], r2);
        }
    }
    if (result == -1) {
        result = r1 + r2;
    } else {
        result = Math.min(r1 + r2, result);
    }
}

print(result);


var data = readline().split(' ').map(Number);
var n = data[0],
    x1 = data[1],
    y1 = data[2],
    x2 = data[3],
    y2 = data[4];
var distantions = [];

for (var i = 0; i < n; i++) {
    var flower = readline().split(' ').map(Number);
    var dist = [];
    dist[0] = Math.pow(flower[0] - x1, 2) + Math.pow(flower[1] - y1, 2);
    dist[1] = Math.pow(flower[0] - x2, 2) + Math.pow(flower[1] - y2, 2);
    distantions.push(dist);
}

var result = -1;
for (var i = 0; i < n; i++) {
    var r1 = distantions[i][0];
    var r2 = 0;
    for (var j = 0; j < n; j++) {
        if (distantions[j][0] > r1) {
            r2 = Math.max(distantions[j][1], r2);
        }
    }
    if (result == -1) {
        result = r1 + r2;
    } else {
        result = Math.min(r1 + r2, result);
    }
}

print(result);


var data = readline().split(' ').map(Number);
var n = data[0],
    x1 = data[1],
    y1 = data[2],
    x2 = data[3],
    y2 = data[4];
var distantions = [];

for (var i = 0; i < n; i++) {
    var flower = readline().split(' ').map(Number);
    distantions[i+1] = [];
    distantions[i+1][0] = Math.pow(flower[0] - x1, 2) + Math.pow(flower[1] - y1, 2);
    distantions[i+1][1] = Math.pow(flower[0] - x2, 2) + Math.pow(flower[1] - y2, 2);
}
distantions[0] = [];
distantions[0][0] = 0;
distantions[0][1] = 0;

print(distantions);

var result = Number.MAX_VALUE;
for (var i = 0; i < n + 1; i++) {
    var r1 = distantions[i][0];
    var r2 = 0;
    for (var j = 0; j < n + 1; j++) {
        if (distantions[j][0] > r1) {
            r2 = Math.max(r2, distantions[j][1]);
        }
    }
    result = Math.min(result, r1 + r2);
}

print(result);


#include <iostream>
#include <cstdlib>
#include <algorithm>

using namespace std;
typedef std::pair<int,int> mypair;
bool comparator ( const mypair& l, const mypair& r) { return l.first > r.first; }

int cal(int a,int b,int c,int d){
    return (a-c)*(a-c)+(b-d)*(b-d);
}

int main() {
    int n,x1,y1,x2,y2;
    cin >> n >> x1 >> y1>>x2>>y2;
    mypair dis2[2010];
    mypair dis1[2010];
    for (int i=0;i<n;i++){
        int a,b;
        cin>> a>>b;
        dis1[i].first=cal(x1,y1,a,b);
        dis1[i].second=i;
        dis2[i].first=cal(x2,y2,a,b);
        dis2[i].second=i;
    }

    sort(dis1,dis1+n,comparator);
    sort(dis2,dis2+n,comparator);
    int res=0;
    res=min(dis1[0].first,dis2[0].first);
    for (int i=1;i<n;i++){
        int selected[2010];
        int tmp=0;
        int idx=0;
        tmp=dis1[i].first;
        for (int j=i;j<n;j++){
            selected[dis1[i].second]=1;
        }
        for (int j=0;j<n;j++){
            if (selected[dis2[j].second]==0){
                idx=j;
                break;
            }
        }
        tmp+=dis2[idx].first;
        res=min(res,tmp);
    }
    cout<<res<<endl;

    return 0;
}


#include <iostream>
#include <cstdlib>
#include <algorithm>

using namespace std;
typedef std::pair<int,int> mypair;
bool comparator ( const mypair& l, const mypair& r) { return l.first > r.first; }

int cal(int a,int b,int c,int d){
    return (a-c)*(a-c)+(b-d)*(b-d);
}

int main() {
    int n,x1,y1,x2,y2;
    cin >> n >> x1 >> y1>>x2>>y2;
    mypair dis2[2010];
    mypair dis1[2010];
    for (int i=0;i<n;i++){
        int a,b;
        cin>> a>>b;
        dis1[i].first=cal(x1,y1,a,b);
        dis1[i].second=i;
        dis2[i].first=cal(x2,y2,a,b);
        dis2[i].second=i;
    }

    sort(dis1,dis1+n,comparator);
    sort(dis2,dis2+n,comparator);

    int res=0;
    res=min(dis1[0].first,dis2[0].first);
    for (int i=1;i<n;i++){
        int selected[2010];
        int tmp=0;
        int idx=0;
        tmp=dis1[i].first;
        for (int j=i;j<n;j++){
            selected[j]=1;
        }
        for (int j=0;j<n;j++){
            if (selected[j]!=0){
                idx=j;
                break;
            }
        }
        tmp+=dis2[idx].first;
        cout<<res<<" "<<tmp<<endl;
        res=min(res,tmp);
    }
    cout<<res<<endl;

    return 0;
}


#include <iostream>
#include <cstdlib>
#include <algorithm>

using namespace std;
typedef std::pair<int,int> mypair;
bool comparator ( const mypair& l, const mypair& r) { return l.first > r.first; }

int cal(int a,int b,int c,int d){
    return (a-c)*(a-c)+(b-d)*(b-d);
}
int minn(int a,int b){
    return a<b?a:b;
}

int getRes(mypair dis1[],mypair dis2[],int n){
    int selected[2010];
    int tmp=0;
    int idx=0;
    for (int i=0;i<n;i++){
        if (dis2[i].second==dis1[0].second){
            idx=i;
            break;
        }
    }
    tmp+=dis2[idx].first;
    for (int i=idx;i<n;i++) selected[i]=1;
    for (int i=0;i<n;i++){
        if (selected[i]!=0){
            idx=i;
            break;
        }
    }
    tmp+=dis1[idx].first;
    return tmp;
}

int main() {
    int n,x1,y1,x2,y2;
    cin >> n >> x1 >> y1>>x2>>y2;
    mypair dis2[2010];
    mypair dis1[2010];
    for (int i=0;i<n;i++){
        int a,b;
        cin>> a>>b;
        dis1[i].first=cal(x1,y1,a,b);
        dis1[i].second=i;
        dis2[i].first=cal(x2,y2,a,b);
        dis2[i].second=i;
    }

    sort(dis1,dis1+n,comparator);
    sort(dis2,dis2+n,comparator);

    int res=0;
    res=minn(dis1[0].first,dis2[0].first);
    for (int i=1;i<n;i++){
        int selected[2010];
        int tmp=0;
        int idx=0;
        tmp=dis1[i].first;
        for (int j=i;j<n;j++){
            selected[j]=1;
        }
        for (int j=0;j<n;j++){
            if (selected[j]!=0){
                idx=j;
                break;
            }
        }
        tmp+=dis2[idx].first;
        res=minn(res,tmp);
    }
    cout<<res<<endl;
    return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;
typedef std::pair<int,int> mypair;
bool comparator ( const mypair& l, const mypair& r) { return l.first > r.first; }

int cal(int a,int b,int c,int d){
    return (a-c)*(a-c)+(b-d)*(b-d);
}

int main() {
    int n,x1,y1,x2,y2;
    cin >> n >> x1 >> y1>>x2>>y2;
    mypair dis2[2010];
    mypair dis1[2010];
    for (int i=0;i<n;i++){
        int a,b;
        cin>> a>>b;
        dis1[i].first=cal(x1,y1,a,b);
        dis1[i].second=i;
        dis2[i].first=cal(x2,y2,a,b);
        dis2[i].second=i;
    }

    sort(dis1,dis1+n,comparator);
    sort(dis2,dis2+n,comparator);
    int res=0;
    res=min(dis1[0].first,dis2[0].first);
    for (int i=1;i<n;i++){
        //cout<<i<<endl;
        int selected[2010];
        memset(selected,0, sizeof(selected));
        int tmp=0;
        int idx=0;
        tmp=dis1[i].first;
        for (int j=i;j<n;j++){
            selected[dis1[j].second]=1;
        }
        //for (int j=0;j<n;j++)
        //    cout<<selected[j]<<endl;
        for (int j=0;j<n;j++){
            if (selected[dis2[j].second]==0){
                idx=j;
                break;
            }
        }
        tmp+=dis2[idx].first;
        //cout<<res<<" "<<tmp<<endl;
        res=min(res,tmp);
    }
    cout<<res<<endl;

    return 0;
}


#include <iostream>
#include <cstdlib>
#include <algorithm>

using namespace std;
typedef std::pair<int,int> mypair;
bool comparator ( const mypair& l, const mypair& r) { return l.first > r.first; }

int cal(int a,int b,int c,int d){
    return (a-c)*(a-c)+(b-d)*(b-d);
}

int main() {
    int n,x1,y1,x2,y2;
    cin >> n >> x1 >> y1>>x2>>y2;
    mypair dis2[2010];
    mypair dis1[2010];
    for (int i=0;i<n;i++){
        int a,b;
        cin>> a>>b;
        dis1[i].first=cal(x1,y1,a,b);
        dis1[i].second=i;
        dis2[i].first=cal(x2,y2,a,b);
        dis2[i].second=i;
    }

    sort(dis1,dis1+n,comparator);
    sort(dis2,dis2+n,comparator);
    cout<<dis1[0].first<<" "<<dis1[0].second<<" "<<dis1[1].first<<" "<<dis1[1].second<<endl;
    cout<<dis2[0].first<<" "<<dis2[0].second<<" "<<dis2[1].first<<" "<<dis2[1].second<<endl;
    int res=0;
    res=min(dis1[0].first,dis2[0].first);
    for (int i=1;i<n;i++){
        int selected[2010];
        int tmp=0;
        int idx=0;
        tmp=dis1[i].first;
        for (int j=i;j<n;j++){
            selected[j]=1;
        }
        for (int j=0;j<n;j++){
            if (selected[j]!=0){
                idx=j;
                break;
            }
        }
        tmp+=dis2[idx].first;
        cout<<res<<" "<<tmp<<endl;
        res=min(res,tmp);
    }
    cout<<res<<endl;

    return 0;
}


#include <iostream>
#include <cstdlib>
#include <algorithm>

using namespace std;
typedef std::pair<int,int> mypair;
bool comparator ( const mypair& l, const mypair& r) { return l.first > r.first; }

int cal(int a,int b,int c,int d){
    return (a-c)*(a-c)+(b-d)*(b-d);
}

int main() {
    int n,x1,y1,x2,y2;
    cin >> n >> x1 >> y1>>x2>>y2;
    mypair dis2[2010];
    mypair dis1[2010];
    for (int i=0;i<n;i++){
        int a,b;
        cin>> a>>b;
        dis1[i].first=cal(x1,y1,a,b);
        dis1[i].second=i;
        dis2[i].first=cal(x2,y2,a,b);
        dis2[i].second=i;
    }

    sort(dis1,dis1+n,comparator);
    sort(dis2,dis2+n,comparator);
    cout<<dis1[0].first<<" "<<dis1[0].second<<" "<<dis1[1].first<<" "<<dis1[1].second<<endl;
    cout<<dis2[0].first<<" "<<dis2[0].second<<" "<<dis2[1].first<<" "<<dis2[1].second<<endl;
    int res=0;
    res=min(dis1[0].first,dis2[0].first);
    for (int i=1;i<n;i++){
        int selected[2010];
        int tmp=0;
        int idx=0;
        tmp=dis1[i].first;
        for (int j=i;j<n;j++){
            selected[j]=1;
        }
        for (int j=0;j<n;j++){
            if (selected[j]==0){
                idx=j;
                break;
            }
        }
        tmp+=dis2[idx].first;
        cout<<res<<" "<<tmp<<endl;
        res=min(res,tmp);
    }
    cout<<res<<endl;

    return 0;
}


#include <iostream>
#include <cstdlib>
#include <algorithm>

using namespace std;
typedef std::pair<int,int> mypair;
bool comparator ( const mypair& l, const mypair& r) { return l.first > r.first; }

int cal(int a,int b,int c,int d){
    return (a-c)*(a-c)+(b-d)*(b-d);
}
int minn(int a,int b){
    return a<b?a:b;
}

int main() {
    int n,x1,y1,x2,y2;
    cin >> n >> x1 >> y1>>x2>>y2;
    mypair dis2[2010];
    mypair dis1[2010];
    for (int i=0;i<n;i++){
        int a,b;
        cin>> a>>b;
        dis1[i].first=cal(x1,y1,a,b);
        dis1[i].second=i;
        dis2[i].first=cal(x2,y2,a,b);
        dis2[i].second=i;
    }

    sort(dis1,dis1+n,comparator);
    sort(dis2,dis2+n,comparator);

    int res=0;
    res=minn(dis1[0].first,dis2[0].first);
    for (int i=1;i<n;i++){
        int selected[2010];
        int tmp=0;
        int idx=0;
        tmp=dis1[i].first;
        for (int j=i;j<n;j++){
            selected[j]=1;
        }
        for (int j=0;j<n;j++){
            if (selected[j]!=0){
                idx=j;
                break;
            }
        }
        tmp+=dis2[idx].first;
        res=minn(res,tmp);
    }
    cout<<res<<endl;

    return 0;
}


#include <iostream>
#include <cstdlib>
#include <algorithm>

using namespace std;
typedef std::pair<int,int> mypair;
bool comparator ( const mypair& l, const mypair& r) { return l.first > r.first; }

int cal(int a,int b,int c,int d){
    return (a-c)*(a-c)+(b-d)*(b-d);
}

int main() {
    int n,x1,y1,x2,y2;
    cin >> n >> x1 >> y1>>x2>>y2;
    mypair dis2[2010];
    mypair dis1[2010];
    for (int i=0;i<n;i++){
        int a,b;
        cin>> a>>b;
        dis1[i].first=cal(x1,y1,a,b);
        dis1[i].second=i;
        dis2[i].first=cal(x2,y2,a,b);
        dis2[i].second=i;
    }

    sort(dis1,dis1+n,comparator);
    sort(dis2,dis2+n,comparator);
    int res=0;
    res=min(dis1[0].first,dis2[0].first);
    for (int i=1;i<n;i++){
        int selected[2010];
        int tmp=0;
        int idx=0;
        tmp=dis1[i].first;
        for (int j=i;j<n;j++){
            selected[dis1[i].second]=1;
        }
        for (int j=0;j<n;j++){
            if (selected[j]==0){
                idx=j;
                break;
            }
        }
        tmp+=dis2[idx].first;
        res=min(res,tmp);
    }
    cout<<res<<endl;

    return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef std::pair< long long, long long> mypair;
bool comparator ( const mypair& l, const mypair& r) { return l.first > r.first; }

long long cal(int a,int b,int c,int d){
    return (a-c)*1ll*(a-c)+(b-d)*1ll*(b-d);
}

int main() {
    int n,x1,y1,x2,y2;
    cin >> n >> x1 >> y1>>x2>>y2;
    mypair dis2[2010];
    mypair dis1[2010];
    for (int i=0;i<n;i++){
        int a,b;
        cin>> a>>b;
        dis1[i].first=cal(x1,y1,a,b);
        dis1[i].second=i;
        dis2[i].first=cal(x2,y2,a,b);
        dis2[i].second=i;
    }

    //cout<<dis1[0].first<<" "<<dis1[1].first<<endl;
    sort(dis1,dis1+n,comparator);
    sort(dis2,dis2+n,comparator);
     long long res=0;
    res=min(dis1[0].first,dis2[0].first);
    for (int i=1;i<n;i++){
        //cout<<i<<endl;
        int selected[2010];
        memset(selected,0, sizeof(selected));
        long long tmp=0;
        int idx=0;
        tmp=dis1[i].first;
        for (int j=i;j<n;j++){
            selected[dis1[j].second]=1;
        }
        //for (int j=0;j<n;j++)
        //    cout<<selected[j]<<endl;
        for (int j=0;j<n;j++){
            if (selected[dis2[j].second]==0){
                idx=j;
                break;
            }
        }
        tmp+=dis2[idx].first;
        //cout<<res<<" "<<tmp<<endl;
        res=min(res,tmp);
    }
    cout<<res<<endl;

    return 0;
}


#include <iostream>
#include <cstdlib>
#include <algorithm>

using namespace std;
typedef std::pair<int,int> mypair;
bool comparator ( const mypair& l, const mypair& r) { return l.first > r.first; }

int cal(int a,int b,int c,int d){
    return (a-c)*(a-c)+(b-d)*(b-d);
}

int main() {
    int n,x1,y1,x2,y2;
    cin >> n >> x1 >> y1>>x2>>y2;
    mypair dis2[2010];
    mypair dis1[2010];
    for (int i=0;i<n;i++){
        int a,b;
        cin>> a>>b;
        dis1[i].first=cal(x1,y1,a,b);
        dis1[i].second=i;
        dis2[i].first=cal(x2,y2,a,b);
        dis2[i].second=i;
    }

    sort(dis1,dis1+n,comparator);
    sort(dis2,dis2+n,comparator);
    int res=0;
    res=min(dis1[0].first,dis2[0].first);
    for (int i=1;i<n;i++){
        //cout<<i<<endl;
        int selected[2010];
        memset(selected,0, sizeof(selected));
        int tmp=0;
        int idx=0;
        tmp=dis1[i].first;
        for (int j=i;j<n;j++){
            selected[dis1[j].second]=1;
        }
        //for (int j=0;j<n;j++)
        //    cout<<selected[j]<<endl;
        for (int j=0;j<n;j++){
            if (selected[dis2[j].second]==0){
                idx=j;
                break;
            }
        }
        tmp+=dis2[idx].first;
        //cout<<res<<" "<<tmp<<endl;
        res=min(res,tmp);
    }
    cout<<res<<endl;

    return 0;
}


#include <iostream>
#include <cstdlib>
#include <algorithm>

using namespace std;
typedef std::pair<int,int> mypair;
bool comparator ( const mypair& l, const mypair& r) { return l.first > r.first; }

int cal(int a,int b,int c,int d){
    return (a-c)*(a-c)+(b-d)*(b-d);
}

int main() {
    int n,x1,y1,x2,y2;
    cin >> n >> x1 >> y1>>x2>>y2;
    mypair dis2[2010];
    mypair dis1[2010];
    for (int i=0;i<n;i++){
        int a,b;
        cin>> a>>b;
        dis1[i].first=cal(x1,y1,a,b);
        dis1[i].second=i;
        dis2[i].first=cal(x2,y2,a,b);
        dis2[i].second=i;
    }

    sort(dis1,dis1+n,comparator);
    sort(dis2,dis2+n,comparator);

    int res=0;
    res=min(dis1[0].first,dis2[0].first);
    for (int i=1;i<n;i++){
        int selected[2010];
        int tmp=0;
        int idx=0;
        tmp=dis1[i].first;
        for (int j=i;j<n;j++){
            selected[j]=1;
        }
        for (int j=0;j<n;j++){
            if (selected[j]!=0){
                idx=j;
                break;
            }
        }
        tmp+=dis2[idx].first;
        res=min(res,tmp);
    }
    cout<<res<<endl;

    return 0;
}


#include <iostream>
#include <cstdlib>
#include <algorithm>

using namespace std;
typedef std::pair<int,int> mypair;
bool comparator ( const mypair& l, const mypair& r) { return l.first > r.first; }

int cal(int a,int b,int c,int d){
    return (a-c)*(a-c)+(b-d)*(b-d);
}
int minn(int a,int b){
    return a<b?a:b;
}

int getRes(mypair dis1[],mypair dis2[],int n){
    int selected[2010];
    int tmp=0;
    int idx=0;
    for (int i=0;i<n;i++){
        if (dis2[i].second==dis1[0].second){
            idx=i;
            break;
        }
    }
    tmp+=dis2[idx].first;
    for (int i=idx;i<n;i++) selected[i]=1;
    for (int i=0;i<n;i++){
        if (selected[i]!=0){
            idx=i;
            break;
        }
    }
    tmp+=dis1[idx].first;
    return tmp;
}

int main() {
    int n,x1,y1,x2,y2;
    cin >> n >> x1 >> y1>>x2>>y2;
    mypair dis2[2010];
    mypair dis1[2010];
    for (int i=0;i<n;i++){
        int a,b;
        cin>> a>>b;
        dis1[i].first=cal(x1,y1,a,b);
        dis1[i].second=i;
        dis2[i].first=cal(x2,y2,a,b);
        dis2[i].second=i;
    }

    sort(dis1,dis1+n,comparator);
    sort(dis2,dis2+n,comparator);

    int res=0;
    res=minn(dis1[0].first,dis2[0].first);
    for (int i=1;i<n;i++){
        int selected[2010];
        int tmp=0;
        int idx=0;
        tmp=dis1[i].first;
        for (int j=i;j<n;j++){
            selected[j]=1;
        }
        for (int j=0;j<n;j++){
            if (selected[j]!=0){
                idx=j;
                break;
            }
        }
        tmp+=dis2[idx].first;
        res=minn(res,tmp);
    }
    cout<<res<<endl;

    return 0;
}


#include <iostream>
#include <cstdlib>
#include <algorithm>

using namespace std;
typedef std::pair<int,int> mypair;
bool comparator ( const mypair& l, const mypair& r) { return l.first > r.first; }

int cal(int a,int b,int c,int d){
    return (a-c)*(a-c)+(b-d)*(b-d);
}
int minn(int a,int b){
    return a<b?a:b;
}

int getRes(mypair dis1[],mypair dis2[],int n){
    int selected[2010];
    int tmp=0;
    int idx=0;
    for (int i=0;i<n;i++){
        if (dis2[i].second==dis1[0].second){
            idx=i;
            break;
        }
    }
    tmp+=dis2[idx].first;
    for (int i=idx;i<n;i++) selected[i]=1;
    for (int i=0;i<n;i++){
        if (selected[i]!=0){
            idx=i;
            break;
        }
    }
    tmp+=dis1[idx].first;
    return tmp;
}

int main() {
    int n,x1,y1,x2,y2;
    cin >> n >> x1 >> y1>>x2>>y2;
    mypair dis2[2010];
    mypair dis1[2010];
    for (int i=0;i<n;i++){
        int a,b;
        cin>> a>>b;
        dis1[i].first=cal(x1,y1,a,b);
        dis1[i].second=i;
        dis2[i].first=cal(x2,y2,a,b);
        dis2[i].second=i;
    }

    sort(dis1,dis1+n,comparator);
    sort(dis2,dis2+n,comparator);

    int res=0;
    res=minn(dis1[0].first,dis2[0].first);
    res=minn(res,getRes(dis1,dis2,n));
    res=minn(res,getRes(dis2,dis1,n));
    cout<<res<<endl;

    return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;
typedef std::pair<int,int> mypair;
bool comparator ( const mypair& l, const mypair& r) { return l.first > r.first; }

unsigned long long cal(int a,int b,int c,int d){
    return (a-c)*(a-c)+(b-d)*(b-d);
}

int main() {
    int n,x1,y1,x2,y2;
    cin >> n >> x1 >> y1>>x2>>y2;
    mypair dis2[2010];
    mypair dis1[2010];
    for (int i=0;i<n;i++){
        int a,b;
        cin>> a>>b;
        dis1[i].first=cal(x1,y1,a,b);
        dis1[i].second=i;
        dis2[i].first=cal(x2,y2,a,b);
        dis2[i].second=i;
    }

    sort(dis1,dis1+n,comparator);
    sort(dis2,dis2+n,comparator);
    unsigned long long res=0;
    res=min(dis1[0].first,dis2[0].first);
    for (int i=1;i<n;i++){
        //cout<<i<<endl;
        int selected[2010];
        memset(selected,0, sizeof(selected));
        unsigned long long tmp=0;
        int idx=0;
        tmp=dis1[i].first;
        for (int j=i;j<n;j++){
            selected[dis1[j].second]=1;
        }
        //for (int j=0;j<n;j++)
        //    cout<<selected[j]<<endl;
        for (int j=0;j<n;j++){
            if (selected[dis2[j].second]==0){
                idx=j;
                break;
            }
        }
        tmp+=dis2[idx].first;
        //cout<<res<<" "<<tmp<<endl;
        res=min(res,tmp);
    }
    cout<<res<<endl;

    return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;
typedef std::pair<unsigned long long,unsigned long long> mypair;
bool comparator ( const mypair& l, const mypair& r) { return l.first > r.first; }

unsigned long long cal(int a,int b,int c,int d){
    return (a-c)*(a-c)+(b-d)*(b-d);
}

int main() {
    int n,x1,y1,x2,y2;
    cin >> n >> x1 >> y1>>x2>>y2;
    mypair dis2[2010];
    mypair dis1[2010];
    for (int i=0;i<n;i++){
        int a,b;
        cin>> a>>b;
        dis1[i].first=cal(x1,y1,a,b);
        dis1[i].second=i;
        dis2[i].first=cal(x2,y2,a,b);
        dis2[i].second=i;
    }

    sort(dis1,dis1+n,comparator);
    sort(dis2,dis2+n,comparator);
    unsigned long long res=0;
    res=min(dis1[0].first,dis2[0].first);
    for (int i=1;i<n;i++){
        //cout<<i<<endl;
        int selected[2010];
        memset(selected,0, sizeof(selected));
        unsigned long long tmp=0;
        int idx=0;
        tmp=dis1[i].first;
        for (int j=i;j<n;j++){
            selected[dis1[j].second]=1;
        }
        //for (int j=0;j<n;j++)
        //    cout<<selected[j]<<endl;
        for (int j=0;j<n;j++){
            if (selected[dis2[j].second]==0){
                idx=j;
                break;
            }
        }
        tmp+=dis2[idx].first;
        //cout<<res<<" "<<tmp<<endl;
        res=min(res,tmp);
    }
    cout<<res<<endl;

    return 0;
}


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

#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define Oo 2000000000
#define EPS 1e-9
#define PI acos(-1)

typedef pair <int, int> ii;
typedef vector <ii> vii;
typedef vector <int> vi;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll, ll> pll;

int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
int dx2[] = {1,-1,0,0,-1,1,-1,1};
int dy2[] = {0,0,1,-1,1,-1,-1,1};

int read()
{
    int x;
    scanf("%d", &x);
    return x;
}

ll dist(ll x, ll y)
{
    return x*x+y*y;
}

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
    #endif // ONLINE_JUDGE

    int n = read();
    ll x1 = read();
    ll y1 = read();
    ll x2 = read();
    ll y2 = read();
    pll d[2005];
    ll x, y;
    for(int i=0;i<n;i++)
    {
        x = read();
        y = read();
        d[i].first = dist(x-x1, y-y1);
        d[i].second = dist(x-x2, y-y2);
    }
    sort(d, d+n);
    ll v, ans = (ll)1e18;
    for(int i=0;i<=n;i++)
    {
        v = 0;
        for(int j=i;j<n;j++)
            v = max(v, d[i].second);
        ans = min(ans, v+(i == 0 ? 0 : d[i-1].first));
    }
    cout << ans;

    return 0;
}


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

#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define Oo 2000000000
#define EPS 1e-9
#define PI acos(-1)

typedef pair <int, int> ii;
typedef vector <ii> vii;
typedef vector <int> vi;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll, ll> pll;

int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
int dx2[] = {1,-1,0,0,-1,1,-1,1};
int dy2[] = {0,0,1,-1,1,-1,-1,1};

int read()
{
    int x;
    scanf("%d", &x);
    return x;
}

ll dist(ll x, ll y)
{
    return x*x+y*y;
}

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
    #endif // ONLINE_JUDGE

    int n = read();
    ll x1 = read();
    ll y1 = read();
    ll x2 = read();
    ll y2 = read();
    pll d[2005];
    ll x, y;
    for(int i=0;i<n;i++)
    {
        x = read();
        y = read();
        d[i].first = dist(x-x1, y-y1);
        d[i].second = dist(x-x2, y-y2);
    }
    sort(d, d+n);
    ll v, ans = (ll)1e18;
    for(int i=0;i<=n;i++)
    {
        v = 0;
        for(int j=i;j<n;j++)
            v = max(v, d[j].second);
        ans = min(ans, v+(i == 0 ? 0 : d[i-1].first));
    }
    cout << ans;

    return 0;
}


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

#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define Oo 2000000000
#define EPS 1e-9
#define PI acos(-1)

typedef pair <int, int> ii;
typedef vector <ii> vii;
typedef vector <int> vi;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll, ll> pll;

int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
int dx2[] = {1,-1,0,0,-1,1,-1,1};
int dy2[] = {0,0,1,-1,1,-1,-1,1};

int read()
{
    int x;
    scanf("%d", &x);
    return x;
}
ll dist(ll x, ll y)
{
    return 1LL*x*x+1LL*y*y;
}

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
    #endif // ONLINE_JUDGE

    int n = read();
    int x1 = read();
    int y1 = read();
    int x2 = read();
    int y2 = read();
    ll r1, r2;
    r1 = r2 = 0;
    int x, y;
    pll distence[2005];
    for(int i=0;i<n;i++)
    {
        x = read();
        y = read();
        distence[i].first = dist(x-x1, y-y1);
        distence[i].second = dist(x-x2, y-y2);

        //cout << dist1 << endl << dist2 << endl;
    }
    sort(distence, distence+n);

    for(int i=0;i<n;i++)
    {
        if(distence[i].first <= r1)
            continue;
        else if(distence[i].second <= r2)
            continue;
        else if(distence[i].first <= distence[i].second)
            r1 = distence[i].first;
        else
            r2 = distence[i].second;
    }
    reverse(distence, distence+n);
    ll r3, r4; r3 = r4 = 0;
    for(int i=0;i<n;i++)
    {
        if(distence[i].first <= r3)
            continue;
        else if(distence[i].second <= r4)
            continue;
        else if(distence[i].first <= distence[i].second)
            r3 = distence[i].first;
        else
            r4 = distence[i].second;
    }
    cout << min(r1 + r2, r3+r4);

    return 0;
}


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

#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define Oo 2000000000
#define EPS 1e-9
#define PI acos(-1)

typedef pair <int, int> ii;
typedef vector <ii> vii;
typedef vector <int> vi;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll, ll> pll;

int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
int dx2[] = {1,-1,0,0,-1,1,-1,1};
int dy2[] = {0,0,1,-1,1,-1,-1,1};

int read()
{
    int x;
    scanf("%d", &x);
    return x;
}

ll dist(ll x, ll y)
{
    return x*x+y*y;
}

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
    #endif // ONLINE_JUDGE

    int n = read();
    ll x1 = read();
    ll y1 = read();
    ll x2 = read();
    ll y2 = read();
    pll d[2005];
    ll x, y;
    for(int i=0;i<n;i++)
    {
        x = read();
        y = read();
        d[i].first = dist(x-x1, y-y1);
        d[i].second = dist(x-x2, y-y2);
    }
    sort(d, d+n);
    ll r1, r2, ans = (ll)1e18;
    ll maxSuff[2005];
    maxSuff[n] = 0;
    for(int i=n-1;i>=0;i--)
        maxSuff[i] = max(maxSuff[i+1], d[i].second);

    for(int i=0;i<n;i++)
    {
        r1 = d[i].first;
        r2 = maxSuff[i+1];
        ans = min(ans, r1 + r2);
    }
    cout << ans;

    return 0;
}


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

#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define Oo 2000000000
#define EPS 1e-9
#define PI acos(-1)

typedef pair <int, int> ii;
typedef vector <ii> vii;
typedef vector <int> vi;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll, ll> pll;

int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
int dx2[] = {1,-1,0,0,-1,1,-1,1};
int dy2[] = {0,0,1,-1,1,-1,-1,1};

int read()
{
    int x;
    scanf("%d", &x);
    return x;
}

ll dist(ll x, ll y)
{
    return x*x+y*y;
}

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
    #endif // ONLINE_JUDGE

    int n = read();
    ll x1 = read();
    ll y1 = read();
    ll x2 = read();
    ll y2 = read();
    pll d[2005];
    ll x, y;
    for(int i=0;i<n;i++)
    {
        x = read();
        y = read();
        d[i].first = dist(x-x1, y-y1);
        d[i].second = dist(x-x2, y-y2);
    }
    sort(d, d+n);
    ll maxSuff[2005];
    maxSuff[n] = 0;
    for(int i=n-1;i>=0;i--)
        maxSuff[i] = max(maxSuff[i+1], d[i].second);

    ll r1, r2, ans = min(d[n-1].first, maxSuff[0]);
    for(int i=0;i<n;i++)
    {
        r1 = d[i].first;
        r2 = maxSuff[i+1];
        ans = min(ans, r1 + r2);
    }
    cout << ans;

    return 0;
}


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

#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define Oo 2000000000
#define EPS 1e-9
#define PI acos(-1)

typedef pair <int, int> ii;
typedef vector <ii> vii;
typedef vector <int> vi;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll, ll> pll;

int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
int dx2[] = {1,-1,0,0,-1,1,-1,1};
int dy2[] = {0,0,1,-1,1,-1,-1,1};

int read()
{
    int x;
    scanf("%d", &x);
    return x;
}
ll dist(ll x, ll y)
{
    return 1LL*x*x+1LL*y*y;
}

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
    #endif // ONLINE_JUDGE

    int n = read();
    int x1 = read();
    int y1 = read();
    int x2 = read();
    int y2 = read();
    ll r1, r2;
    r1 = r2 = 0;
    int x, y;
    ll dist1, dist2;
    for(int i=0;i<n;i++)
    {
        x = read();
        y = read();
        dist1 = dist(x-x1, y-y1);
        dist2 = dist(x-x2, y-y2);
        if(dist1 <= r1)
            continue;
        else if(dist2 <= r2)
            continue;
        else if(dist1 <= dist2)
            r1 = dist1;
        else
            r2 = dist2;
        //cout << dist1 << endl << dist2 << endl;
    }
    cout << r1 + r2;

    return 0;
}


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

#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define Oo 2000000000
#define EPS 1e-9
#define PI acos(-1)

typedef pair <int, int> ii;
typedef vector <ii> vii;
typedef vector <int> vi;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll, ll> pll;

int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
int dx2[] = {1,-1,0,0,-1,1,-1,1};
int dy2[] = {0,0,1,-1,1,-1,-1,1};

int read()
{
    int x;
    scanf("%d", &x);
    return x;
}
ll dist(ll x, ll y)
{
    return 1LL*x*x+1LL*y*y;
}

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
    #endif // ONLINE_JUDGE

    int n = read();
    int x1 = read();
    int y1 = read();
    int x2 = read();
    int y2 = read();
    ll r1, r2;
    r1 = r2 = 0;
    int x, y;
    pll distence[2005];
    for(int i=0;i<n;i++)
    {
        x = read();
        y = read();
        distence[i].first = dist(x-x1, y-y1);
        distence[i].second = dist(x-x2, y-y2);

        //cout << dist1 << endl << dist2 << endl;
    }
    sort(distence, distence+n);
    reverse(distence, distence+n);
    for(int i=0;i<n;i++)
    {
        if(distence[i].first <= r1)
            continue;
        else if(distence[i].second <= r2)
            continue;
        else if(distence[i].first <= distence[i].second)
            r1 = distence[i].first;
        else
            r2 = distence[i].second;
    }
    cout << r1 + r2;

    return 0;
}


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

#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define Oo 2000000000
#define EPS 1e-9
#define PI acos(-1)

typedef pair <int, int> ii;
typedef vector <ii> vii;
typedef vector <int> vi;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll, ll> pll;

int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
int dx2[] = {1,-1,0,0,-1,1,-1,1};
int dy2[] = {0,0,1,-1,1,-1,-1,1};

int read()
{
    int x;
    scanf("%d", &x);
    return x;
}

ll dist(ll x, ll y)
{
    return x*x+y*y;
}

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
    #endif // ONLINE_JUDGE

    int n = read();
    ll x1 = read();
    ll y1 = read();
    ll x2 = read();
    ll y2 = read();
    pll d[2005];
    ll x, y;
    for(int i=0;i<n;i++)
    {
        x = read();
        y = read();
        d[i].first = dist(x-x1, y-y1);
        d[i].second = dist(x-x2, y-y2);
    }
    sort(d, d+n);
    ll v, ans = (ll)1e18;
    for(int i=0;i<n;i++)
    {
        v = 0;
        for(int j=i;j<n;j++)
            v = max(v, d[i].second);
        ans = min(ans, v+(i == 0 ? 0 : d[i-1].first));
    }
    cout << ans;

    return 0;
}


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

#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define Oo 2000000000
#define EPS 1e-9
#define PI acos(-1)

typedef pair <int, int> ii;
typedef vector <ii> vii;
typedef vector <int> vi;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll, ll> pll;

int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
int dx2[] = {1,-1,0,0,-1,1,-1,1};
int dy2[] = {0,0,1,-1,1,-1,-1,1};

int read()
{
    int x;
    scanf("%d", &x);
    return x;
}
ll dist(ll x, ll y)
{
    return 1LL*x*x+1LL*y*y;
}

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
    #endif // ONLINE_JUDGE

    int n = read();
    int x1 = read();
    int y1 = read();
    int x2 = read();
    int y2 = read();
    ll r1, r2;
    r1 = r2 = 0;
    int x, y;
    pll distence[2005];
    for(int i=0;i<n;i++)
    {
        x = read();
        y = read();
        distence[i].first = dist(x-x1, y-y1);
        distence[i].second = dist(x-x2, y-y2);

        //cout << dist1 << endl << dist2 << endl;
    }
    sort(distence, distence+n);

    for(int i=0;i<n;i++)
    {
        if(distence[i].second <= r1)
            continue;
        else if(distence[i].first <= r2)
            continue;
        else if(distence[i].second <= distence[i].first)
            r1 = distence[i].second;
        else
            r2 = distence[i].first;
    }
    reverse(distence, distence+n);
    ll r3, r4; r3 = r4 = 0;
    for(int i=0;i<n;i++)
    {
        if(distence[i].first <= r3)
            continue;
        else if(distence[i].second <= r4)
            continue;
        else if(distence[i].first <= distence[i].second)
            r3 = distence[i].first;
        else
            r4 = distence[i].second;
    }
    cout << min(r1 + r2, r3+r4);

    return 0;
}


#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <cctype>
#include <set>
#include <bitset>
#include <algorithm>
#include <list>
#include <vector>
#include <sstream>
#include <iostream>
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> paii;

#define PI (2*acos(0))
#define ERR 1e-5
#define mem(a,b) memset(a,b,sizeof a)
#define pb push_back
#define popb pop_back
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define SZ(x) (int)x.size()
#define oo (1<<25)
#define FOREACH(it,x) for(__typeof((x).begin()) it=(x.begin()); it!=(x).end(); ++it)
#define Contains(X,item)        ((X).find(item) != (X).end())
#define popc(i) (__builtin_popcount(i))
#define fs      first
#define sc      second
#define EQ(a,b)     (fabs(a-b)<ERR)
#define MAX 2010
#define wait getchar()

int n;
pair<ll,ll> fountain[2],arr[MAX];

ll sqr(ll val)
{
	return val*val;
}

ll calc_d(int pos,int f)
{
	return sqr(arr[pos].fs-fountain[f].fs)+sqr(arr[pos].sc-fountain[f].sc);
}

int main()
{
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);

	ll ans=oo;
	int flag=0;

	cin>>n>>fountain[0].fs>>fountain[0].sc>>fountain[1].fs>>fountain[1].sc;
	for(int i=0;i<n;i++) cin>>arr[i].fs>>arr[i].sc;

	ll sr1,sr2;

	for(int i=0;i<n;i++)
	{
		sr1=calc_d(i,0);
		sr2=0;
		flag=0;

		for(int j=0;j<n;j++)
		{
			if(calc_d(j,0)>sr1)
			{
				sr2=max(sr2,calc_d(j,1));
				flag=1;
			}
		}

		ans=min(ans,sr1+sr2);

		if(!flag) break;
	}

	cout<<ans;

	return 0;
}


#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <cctype>
#include <set>
#include <bitset>
#include <algorithm>
#include <list>
#include <vector>
#include <sstream>
#include <iostream>
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> paii;

#define PI (2*acos(0))
#define ERR 1e-5
#define mem(a,b) memset(a,b,sizeof a)
#define pb push_back
#define popb pop_back
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define SZ(x) (int)x.size()
#define oo (1<<25)
#define FOREACH(it,x) for(__typeof((x).begin()) it=(x.begin()); it!=(x).end(); ++it)
#define Contains(X,item)        ((X).find(item) != (X).end())
#define popc(i) (__builtin_popcount(i))
#define fs      first
#define sc      second
#define EQ(a,b)     (fabs(a-b)<ERR)
#define MAX 2010
#define wait getchar()

int n;
pair<ll,ll> fountain[2],arr[MAX];

ll sqr(ll val)
{
	return val*val;
}

ll calc_d(int pos,int f)
{
	return sqr(arr[pos].fs-fountain[f].fs)+sqr(arr[pos].sc-fountain[f].sc);
}

int main()
{
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);

	ll ans=oo;
	int flag=0;

	cin>>n>>fountain[0].fs>>fountain[0].sc>>fountain[1].fs>>fountain[1].sc;
	for(int i=0;i<n;i++) cin>>arr[i].fs>>arr[i].sc;

	ll sr1,sr2;

	for(int i=0;i<n;i++)
	{
		sr1=calc_d(i,0);
		sr2=0;
		flag=0;

		for(int j=0;j<n;j++)
			if(j!=i && calc_d(j,0)>sr1)
				sr2=max(sr2,calc_d(j,1));

		ans=min(ans,sr1+sr2);
	}

	cout<<ans;

	return 0;
}


#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <cctype>
#include <set>
#include <bitset>
#include <algorithm>
#include <list>
#include <vector>
#include <sstream>
#include <iostream>
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> paii;

#define PI (2*acos(0))
#define ERR 1e-5
#define mem(a,b) memset(a,b,sizeof a)
#define pb push_back
#define popb pop_back
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define SZ(x) (int)x.size()
#define oo (1<<25)
#define FOREACH(it,x) for(__typeof((x).begin()) it=(x.begin()); it!=(x).end(); ++it)
#define Contains(X,item)        ((X).find(item) != (X).end())
#define popc(i) (__builtin_popcount(i))
#define fs      first
#define sc      second
#define EQ(a,b)     (fabs(a-b)<ERR)
#define MAX 2010
#define wait getchar()

int n;
pair<ll,ll> fountain[2],arr[MAX];

ll sqr(ll val)
{
	return val*val;
}

ll calc_d(int pos,int f)
{
	return sqr(arr[pos].fs-fountain[f].fs)+sqr(arr[pos].sc-fountain[f].sc);
}

int main()
{
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);

	ll ans=oo;
	int flag=0;

	cin>>n>>fountain[0].fs>>fountain[0].sc>>fountain[1].fs>>fountain[1].sc;
	for(int i=0;i<n;i++) cin>>arr[i].fs>>arr[i].sc;

	ll sr1,sr2;

	for(int i=0;i<n;i++)
	{
		sr1=calc_d(i,0);
		sr2=0;
		flag=0;

		for(int j=0;j<n;j++)
			if(calc_d(j,0)>sr1)
				sr2=max(sr2,calc_d(j,1));

		ans=min(ans,sr1+sr2);
	}

	cout<<ans;

	return 0;
}


#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <cctype>
#include <set>
#include <bitset>
#include <algorithm>
#include <list>
#include <vector>
#include <sstream>
#include <iostream>
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> paii;

#define PI (2*acos(0))
#define ERR 1e-5
#define mem(a,b) memset(a,b,sizeof a)
#define pb push_back
#define popb pop_back
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define SZ(x) (int)x.size()
#define oo (1<<25)
#define FOREACH(it,x) for(__typeof((x).begin()) it=(x.begin()); it!=(x).end(); ++it)
#define Contains(X,item)        ((X).find(item) != (X).end())
#define popc(i) (__builtin_popcount(i))
#define fs      first
#define sc      second
#define EQ(a,b)     (fabs(a-b)<ERR)
#define MAX 2010
#define wait getchar()

int n;
pair<ll,ll> fountain[2],arr[MAX];

ll sqr(ll val)
{
	return val*val;
}

ll calc_d(int pos,int f)
{
	return sqr(arr[pos].fs-fountain[f].fs)+sqr(arr[pos].sc-fountain[f].sc);
}

int main()
{
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);

	ll ans=oo;

	cin>>n>>fountain[0].fs>>fountain[0].sc>>fountain[1].fs>>fountain[1].sc;
	for(int i=0;i<n;i++) cin>>arr[i].fs>>arr[i].sc;

	ll sr1,sr2;

	for(int i=-1;i<n;i++)
	{
		if(i==-1) sr1=0;
		else sr1=calc_d(i,0);
		sr2=0;

		for(int j=0;j<n;j++)
			if(j!=i && calc_d(j,0)>sr1)
				sr2=max(sr2,calc_d(j,1));

		ans=min(ans,sr1+sr2);
	}

	cout<<ans;

	return 0;
}


#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <cctype>
#include <set>
#include <bitset>
#include <algorithm>
#include <list>
#include <vector>
#include <sstream>
#include <iostream>
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> paii;

#define PI (2*acos(0))
#define ERR 1e-5
#define mem(a,b) memset(a,b,sizeof a)
#define pb push_back
#define popb pop_back
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define SZ(x) (int)x.size()
#define oo (1<<25)
#define FOREACH(it,x) for(__typeof((x).begin()) it=(x.begin()); it!=(x).end(); ++it)
#define Contains(X,item)        ((X).find(item) != (X).end())
#define popc(i) (__builtin_popcount(i))
#define fs      first
#define sc      second
#define EQ(a,b)     (fabs(a-b)<ERR)
#define MAX 2010
#define wait getchar()

int n;
pair<float,float> fountain[2],arr[MAX];

float sqr(float val)
{
	if(val<=-oo) return oo;
	return val*val;
}

float rec(int pos,float r1,float r2)
{
	if(pos==n) return r1*r1+r2*r2;

	float d1=sqrt(sqr(arr[pos].fs-fountain[0].fs)+sqr(arr[pos].sc-fountain[0].sc));
	float d2=sqrt(sqr(arr[pos].fs-fountain[1].fs)+sqr(arr[pos].sc-fountain[1].sc));

	float tmp1,tmp2;

	tmp1 = (d1>r1) ? rec(pos+1,d1,r2) : rec(pos+1,r1,r2);
	tmp2 = (d2>r2) ? rec(pos+1,r1,d2) : rec(pos+1,r1,r2);

	return (tmp1<tmp2) ? tmp1 : tmp2;
}

int main()
{
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);

	cin>>n>>fountain[0].fs>>fountain[0].sc>>fountain[1].fs>>fountain[1].sc;
	for(int i=0;i<n;i++) cin>>arr[i].fs>>arr[i].sc;

	cout<<rec(0,-oo,-oo);

	return 0;
}


#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <cctype>
#include <set>
#include <bitset>
#include <algorithm>
#include <list>
#include <vector>
#include <sstream>
#include <iostream>
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> paii;

#define PI (2*acos(0))
#define ERR 1e-5
#define mem(a,b) memset(a,b,sizeof a)
#define pb push_back
#define popb pop_back
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define SZ(x) (int)x.size()
#define oo (1<<25)
#define FOREACH(it,x) for(__typeof((x).begin()) it=(x.begin()); it!=(x).end(); ++it)
#define Contains(X,item)        ((X).find(item) != (X).end())
#define popc(i) (__builtin_popcount(i))
#define fs      first
#define sc      second
#define EQ(a,b)     (fabs(a-b)<ERR)
#define MAX 2010
#define wait getchar()

int n;
pair<ll,ll> fountain[2],arr[MAX];

ll sqr(ll val)
{
	return val*val;
}

ll calc_d(int pos,int f)
{
	return sqr(arr[pos].fs-fountain[f].fs)+sqr(arr[pos].sc-fountain[f].sc);
}

int main()
{
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);

	ll ans=oo;

	cin>>n>>fountain[0].fs>>fountain[0].sc>>fountain[1].fs>>fountain[1].sc;
	for(int i=0;i<n;i++) cin>>arr[i].fs>>arr[i].sc;

	ll sr1,sr2;

	for(int i=-1;i<n;i++)
	{
		if(i==-1) sr1=0;
		else sr1=calc_d(i,0);

		sr2=0;

		for(int j=0;j<n;j++)
			if(calc_d(j,0)>sr1)
				sr2=max(sr2,calc_d(j,1));

		ans=min(ans,sr1+sr2);
	}

	cout<<ans;

	return 0;
}


#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <cctype>
#include <set>
#include <bitset>
#include <algorithm>
#include <list>
#include <vector>
#include <sstream>
#include <iostream>
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> paii;

#define PI (2*acos(0))
#define ERR 1e-5
#define mem(a,b) memset(a,b,sizeof a)
#define pb push_back
#define popb pop_back
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define SZ(x) (int)x.size()
#define oo (1<<25)
#define FOREACH(it,x) for(__typeof((x).begin()) it=(x.begin()); it!=(x).end(); ++it)
#define Contains(X,item)        ((X).find(item) != (X).end())
#define popc(i) (__builtin_popcount(i))
#define fs      first
#define sc      second
#define EQ(a,b)     (fabs(a-b)<ERR)
#define MAX 200010
#define wait getchar()

int main()
{
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);

	vector<int>v;
	ll n,arr[110],ans=1;

	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
		if(arr[i]==1) v.pb(i);
	}

	if(SZ(v)==0) cout<<0;
	else if(SZ(v)==1) cout<<1;
	else
	{
		for(int i=1;i<SZ(v);i++) ans*=v[i]-v[i-1];
		cout<<ans;
	}

	return 0;
}


#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <cctype>
#include <set>
#include <bitset>
#include <algorithm>
#include <list>
#include <vector>
#include <sstream>
#include <iostream>
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> paii;

#define PI (2*acos(0))
#define ERR 1e-5
#define mem(a,b) memset(a,b,sizeof a)
#define pb push_back
#define popb pop_back
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define SZ(x) (int)x.size()
#define oo (1<<25)
#define FOREACH(it,x) for(__typeof((x).begin()) it=(x.begin()); it!=(x).end(); ++it)
#define Contains(X,item)        ((X).find(item) != (X).end())
#define popc(i) (__builtin_popcount(i))
#define fs      first
#define sc      second
#define EQ(a,b)     (fabs(a-b)<ERR)
#define MAX 2010
#define wait getchar()

int n;
pair<ll,ll> fountain[2],arr[MAX];

ll sqr(ll val)
{
	return val*val;
}

ll calc_d(int pos,int f)
{
	return sqr(arr[pos].fs-fountain[f].fs)+sqr(arr[pos].sc-fountain[f].sc);
}

int main()
{
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);

	ll ans=8e18;

	cin>>n>>fountain[0].fs>>fountain[0].sc>>fountain[1].fs>>fountain[1].sc;
	for(int i=0;i<n;i++) cin>>arr[i].fs>>arr[i].sc;

	ll sr1,sr2;

	for(int i=-1;i<n;i++)
	{
		if(i==-1) sr1=0;
		else sr1=calc_d(i,0);

		sr2=0;

		for(int j=0;j<n;j++)
			if(calc_d(j,0)>sr1)
				sr2=max(sr2,calc_d(j,1));

		ans=min(ans,sr1+sr2);
	}

	cout<<ans;

	return 0;
}


#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <cctype>
#include <set>
#include <bitset>
#include <algorithm>
#include <list>
#include <vector>
#include <sstream>
#include <iostream>
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> paii;

#define PI (2*acos(0))
#define ERR 1e-5
#define mem(a,b) memset(a,b,sizeof a)
#define pb push_back
#define popb pop_back
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define SZ(x) (int)x.size()
#define oo (1<<25)
#define FOREACH(it,x) for(__typeof((x).begin()) it=(x.begin()); it!=(x).end(); ++it)
#define Contains(X,item)        ((X).find(item) != (X).end())
#define popc(i) (__builtin_popcount(i))
#define fs      first
#define sc      second
#define EQ(a,b)     (fabs(a-b)<ERR)
#define MAX 2010
#define wait getchar()

int n;
pair<ll,ll> fountain[2],arr[MAX];

ll sqr(ll val)
{
	return val*val;
}

ll calc_d(int pos,int f)
{
	return sqr(arr[pos].fs-fountain[f].fs)+sqr(arr[pos].sc-fountain[f].sc);
}

int main()
{
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);

	ll ans=oo;
	int flag=0;

	cin>>n>>fountain[0].fs>>fountain[0].sc>>fountain[1].fs>>fountain[1].sc;
	for(int i=0;i<n;i++) cin>>arr[i].fs>>arr[i].sc;

	ll sr1,sr2;

	for(sr1=0;;sr1++)
	{
		sr2=0;
		flag=0;

		for(int i=0;i<n;i++)
		{
			if(calc_d(i,0)>sr1)
			{
				sr2=max(sr2,calc_d(i,1));
				flag=1;
			}
		}

		ans=min(ans,sr1+sr2);

		if(!flag) break;
	}

	cout<<ans;

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <map>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <set>
#include <limits.h>

#define max(a,b) a>b?a:b
#define inp(x) scanf("%d",&x)
#define inp_l(x) scanf("%lld",&x)
#define inp_d(x) scanf("%lf",&x)
#define MOD 1000000007

using namespace std;

typedef long long int ll;
typedef vector <int> VI;
typedef vector <long long int> VLL;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL;

struct data
{
	ll x;
	ll y;
	ll d1;
	ll d2;
	/* data */
};

int main()
{
	ll n,x1,y1,x2,y2,i,r1,r2,d1,d2,r11,r21,x,y;
	vector <data> arr;
	map <ll,ll> S1,S2;
	cin >> n >> x1 >> y1 >> x2 >> y2;
	r1=r2=0ll;
	for(i=0;i<n;i++)
	{
		cin >> x >> y;
		d1=(x-x1)*(x-x1)+(y-y1)*(y-y1);
		d2=(x-x2)*(x-x2)+(y-y2)*(y-y2);
		data tmp;
		tmp.x=x;
		tmp.y=y;
		tmp.d1=d1;
		tmp.d2=d2;
		arr.push_back(tmp);
		if(S2.find(d2)==S2.end())
		{
			S2[d2]=1;
		}
		else
		{
			S2[d2]=S2[d2]+1;
		}
		r2=max(r2,d2);
	}

	for(i=0;i<n;i++)
	{
		r11=max(r1,arr[i].d1);
		S2[arr[i].d2]--;
		if(S2[arr[i].d2]==0)
		{
			S2.erase(S2.find(arr[i].d2));
		}
		if(S2.empty())
			r21=0ll;
		else
			r21=(S2.rbegin())->first;
		if(r1+r2>r11+r21)
		{
			r1=r11;
			r2=r21;
			if(S1.find(arr[i].d1)==S1.end())
			{
				S1[arr[i].d1]=1;
			}
			else
			{
				S1[arr[i].d1]++;
			}
		}
		else
		{
			if(S2.find(arr[i].d2)==S2.end())
			{
				S2[arr[i].d2]=1;
			}
			else
			{
				S2[arr[i].d2]++;
			}
		}
	}
	cout << r1+r2 << endl;
	return 0;
}