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

int n, x[2004], y[2004], answer;
int path[2004][2004];
vector <int> nbs[2004];
const int inf = 1000000000;

int func (int curr, int fin, bool used[]) {
    if (curr == fin) {path[curr][fin] = 0; return 0;}
    if (path[curr][fin] != inf) {path[fin][curr] = path[curr][fin]; return path[curr][fin];}
    if (path[fin][curr] != inf) {path[curr][fin] = path[fin][curr]; return path[fin][curr];}

    int ans=inf;
    for (int i=0; i < nbs[curr].size(); i++) {
        int currn = nbs[curr][i];
        if (currn == curr) {continue;}
        if (used[currn] == false) {
            int curr_path = abs(x[curr] - x[currn]) + abs(y[curr] - y[currn]);
            used[currn] = true;
            ans = min (ans, curr_path + func (currn, fin, used));
            used[currn] = false;
        }
    }
    path[curr][fin] = ans;
    path[fin][curr] = ans;
    return ans;
}

int main () {
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);

cin >> n;

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

for (int i=0; i < n; i++) {
    for (int j=0; j < n; j++) {
        path[i][j] = inf;
        if (i == j) {continue;}
        if (x[i] == x[j] or y[i] == y[j]) {
            nbs[i].push_back(j);
        }
    }
}

for (int i=0; i < n; i++) {
    for (int j=0; j < n; j++) {
        if (path[i][j] == inf) {
            bool used[2004];
            for (int i=0; i < 2004; i++) {used[i] = false;}
            used[i] = true;
            path[i][i] = 0;
            path[i][j] = func (i, j, used);
        }
    }
}

answer = (-1)*inf;

for (int i=0; i < n; i++) {
    for (int j=0; j < n; j++) {
        if (path[i][j] == inf) {continue;}
        cout << i << " " << j << " " << path[i][j] << endl;
        answer = max (answer, path[i][j]);
    }
}

cout << answer << endl;

return 0;
}