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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	long long n, x, y, sum = 0, offset;
	bool flag;
	cin >> n;
	int xcount[n] = {}, ycount[n] = {};

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

	if(n == 1){
		cout << 0;
		return 0;
	}else{
		for(int i = 0; i < n; i++){
			for(int c = xcount[i]; c > 1; c--){
				offset = 1;
				flag = true;
				while(flag){
					if(offset <= i && xcount[i-offset] == 0){
						xcount[i-offset]++;
						xcount[i]--;
						flag = false;
						sum += offset;
					}else if(i+offset < n && xcount[i+offset] == 0){
						xcount[i+offset]++;
						xcount[i]--;
						flag = false;
						sum += offset;
					}
					offset++;
				}
			}
			for(int c = ycount[i]; c > 1; c--){
				offset = 1;
				flag = true;
				while(flag){
					if(offset <= i && ycount[i-offset] == 0){
						ycount[i-offset]++;
						ycount[i]--;
						flag = false;
						sum += offset;
					}else if(i+offset < n && ycount[i+offset] == 0){
						ycount[i+offset]++;
						ycount[i]--;
						flag = false;
						sum += offset;
					}
					offset++;
				}
			}
		}
	}
	cout << sum;

	return 0;
}