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

int n, x[2004], y[2004], answer;
int path[2004][2004];
const int inf = 1000000000;

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

    int ans=inf;
    for (int i=0; i < n; i++) {
        if (i == curr) {continue;}
        if (used[i] == false) {
            if (x[curr] == x[i] or y[curr] == y[i]) {
                int curr_path = abs(x[curr] - x[i]) + abs(y[curr] - y[i]);
                used[i] = true;
                ans = min (ans, curr_path + func (i, fin, used));
                used[i] = 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;
    }
}

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;}
            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;}
        answer = max (answer, path[i][j]);
    }
}

cout << answer << endl;

return 0;
}