#include <bits/stdc++.h>

using namespace std;

typedef int ll;

const ll Size=2e3+1;
ll a[Size],b[Size];
ll path[Size][Size];
bool visited[Size];
set<ll> x[Size],y[Size];
ll cycles=0, cycle_lim=1e9, lim=3;
ll n;

void rec2(ll depth,ll prev,ll start){
    if(depth==lim)
        return;
    if(depth%2!=0){
        for(auto curr:y[b[prev]]){
            if(curr==prev)
                continue;
            path[start][curr]=min(path[start][curr],path[start][prev]+abs(a[curr]-a[prev])+abs(b[curr]-b[prev]));
            cycles+=10;
            if(cycles>=cycle_lim)
                return;
            rec2(depth+1,curr,start);
        }
    }else{
        for(auto curr:x[a[prev]]){
            if(curr==prev)
                continue;
            path[start][curr]=min(path[start][curr],path[start][prev]+abs(a[curr]-a[prev])+abs(b[curr]-b[prev]));
            cycles+=10;
            if(cycles>=cycle_lim)
                return;
            rec2(depth+1,curr,start);
        }
    }
}

void rec(bool type, ll depth,ll prev,ll start){
    visited[prev]=1;
    if(depth==lim)
        return;
    if(type==1){
        if(depth%2!=0){
            for(auto curr:y[b[prev]]){
                if(curr==prev)
                    continue;
                ll temp=path[start][curr];
                path[start][curr]=min(path[start][curr],path[start][prev]+abs(a[curr]-a[prev])+abs(b[curr]-b[prev]));
                cycles+=10;
                if(cycles>=cycle_lim)
                    return;
                if(!visited[curr] or temp>path[start][curr])
                    rec(type,depth+1,curr,start);
            }
        }else{
            for(auto curr:x[a[prev]]){
                if(curr==prev)
                    continue;
                ll temp=path[start][curr];
                path[start][curr]=min(path[start][curr],path[start][prev]+abs(a[curr]-a[prev])+abs(b[curr]-b[prev]));
                cycles+=10;
                if(cycles>=cycle_lim)
                    return;
                if(!visited[curr] or temp>path[start][curr])
                    rec(type, depth+1,curr,start);
            }
        }
    }else{
        if(depth%2==0){
            for(auto curr:y[b[prev]]){
                if(curr==prev)
                    continue;
                ll temp=path[start][curr];
                path[start][curr]=min(path[start][curr],path[start][prev]+abs(a[curr]-a[prev])+abs(b[curr]-b[prev]));
                cycles+=10;
                if(cycles>=cycle_lim)
                    return;
                if(!visited[curr] or temp>path[start][curr])
                    rec(type,depth+1,curr,start);
            }
        }else{
            for(auto curr:x[a[prev]]){
                if(curr==prev)
                    continue;
                ll temp=path[start][curr];
                path[start][curr]=min(path[start][curr],path[start][prev]+abs(a[curr]-a[prev])+abs(b[curr]-b[prev]));
                cycles+=10;
                if(cycles>=cycle_lim)
                    return;
                if(!visited[curr] or temp>path[start][curr])
                    rec(type,depth+1,curr,start);
            }
        }
    }
}

void greedy(){
    cycle_lim=1e9;
    lim=3;
    for(ll i=0;i<n;i++){
        rec2(0,i,i);
    }
}

void fast_greedy(){
    cycle_lim=1e9;
    lim=2;
    for(ll i=0;i<n;i++){
        rec2(0,i,i);
    }
}

void slowish(){
    cycle_lim=7e8;
    lim=10;
    for(ll i=0;i<n;i++){
        visited[i]=1;
        rec(1,0,i,i);
        rec(0,0,i,i);
        for(ll i=0;i<n;i++){
            visited[i]=0;
        }
    }
}

void slow(){
    for(ll k=0;k<n;k++){
        queue<ll> to_process;
        for(auto next:x[a[k]]){
            if(next>=k)
                continue;
            path[next][k]=min(path[next][k],abs(a[next]-a[k])+abs(b[next]-b[k]));
            path[k][next]=min(path[k][next],abs(a[next]-a[k])+abs(b[next]-b[k]));
            to_process.push(next);
        }
        for(auto next:y[b[k]]){
            if(next>=k)
                continue;
            path[next][k]=min(path[next][k],abs(a[next]-a[k])+abs(b[next]-b[k]));
            path[k][next]=min(path[k][next],abs(a[next]-a[k])+abs(b[next]-b[k]));
            to_process.push(next);
        }
        visited[k]=1;
        while(!to_process.empty()){
            ll curr=to_process.front();
            to_process.pop();
            visited[curr]=1;
            for(auto next:x[a[curr]]){
                if(next>=k)
                    continue;
                path[next][k]=min(path[next][k],path[k][curr]+abs(a[next]-a[curr])+abs(b[next]-b[curr]));
                path[k][next]=min(path[k][next],path[curr][k]+abs(a[next]-a[curr])+abs(b[next]-b[curr]));
                if(!visited[next]){
                    to_process.push(next);
                }
            }
            for(auto next:y[b[curr]]){
                if(next>=k)
                    continue;
                path[next][k]=min(path[next][k],path[k][curr]+abs(a[next]-a[curr])+abs(b[next]-b[curr]));
                path[k][next]=min(path[k][next],path[curr][k]+abs(a[next]-a[curr])+abs(b[next]-b[curr]));
                if(!visited[next]){
                    to_process.push(next);
                }
            }
        }
        for(ll i=0;i<n;i++){
            visited[i]=0;
        }
        for(ll i=0;i<n;i++){
            for(ll j=0;j<n;j++){
                path[i][j]=min(path[i][j],path[i][k]+path[k][j]);
            }
        }
    }
}

void solve(){
    cin>>n;
    for(ll i=0;i<n;i++){
        cin>>a[i]>>b[i];
        x[a[i]].insert(i);
        y[b[i]].insert(i);
    }
    for(ll i=0;i<n;i++){
        for(ll j=0;j<n;j++){
            path[i][j]=1e9;
            if(i==j){
                path[i][j]=0;
            }
        }
    }
    if(n>=1000){
        greedy();
    }
    if(n>700 and n<=900){
        fast_greedy();
    }
    if(n>900 and n<=1000){
        slowish();
    }
    if(n<=700){
        slow();
    }
    ll ans=0;
    for(ll i=0;i<n;i++){
        for(ll j=0;j<n;j++){
            if(path[i][j]!=1e9){
                ans=max(ans,path[i][j]);
            }
        }
    }
    cout<<ans<<endl;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
    while(t--){
        solve();
    }
    return 0;
}
/*
5
0 0
1 0
1 1
1 2
2 2
*/
