#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#define endl "\n"
#define ll long long
using namespace std;

ll n,x[2048],y[2048],i,j,ans=-1;
bool used[2048];
vector<pair<ll,ll> > sysedi[2048];
priority_queue<pair<ll, ll> > q;

void dijkstra(ll curr, ll dul){
    if(!q.empty()){
       q.pop();
    }
    cout << curr << " " << dul << endl;
    used[curr]=true;
    if(dul>ans){
        ans=dul;
    }
    for(int j=0;j<sysedi[curr].size();j++){
        if(used[sysedi[curr][j].first]){
            continue;
        }
        q.push({-(dul+sysedi[curr][j].second),sysedi[curr][j].first});
        used[sysedi[curr][j].first]=true;
        //cout << "da";
    }
    while(!q.empty()){
        dijkstra(q.top().second,-q.top().first);
    }
}

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
    cin >> n;
    for(i=0;i<n;i++){
        cin >> x[i] >> y[i];
    }
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            if(x[i]==x[j]){
                sysedi[i].push_back({j,abs(y[i]-y[j])});
            }
            if(y[i]==y[j]){
                sysedi[i].push_back({j,abs(x[i]-x[j])});
            }
        }
    }
    for(i=0;i<n;i++){
        if(!used[i]){
            dijkstra(i,0);
        }
    }
    cout << ans << endl;
}
