#include <iostream>
#include <cmath>

using namespace std;
int main() {
    int n,r,c,i,p,s;
    cin >> n;
    int R[n+1];
    int C[n+1];
    for (i = 1; i <= n; i++) {
        R[i] = 0;
        C[i] = 0;
    }
    for (i = 1; i <= n; i++) {
        cin >> r;
        cin >> c;
        R[r]++;
        C[c]++;
    }
    s = 0;
    p = 0;
    for (i = 1; i <= n - 1; i++) {
        p = p + R[i] - 1;
        s = s + fabs(p);
    }
    p = 0;
    for (i = 1; i <= n - 1; i++) {
        p = p + C[i] - 1;
        s = s + fabs(p);
    }
    cout << s << endl;
    return 0;
}