#include <iostream>
#include <stdio.h>
#include <vector>
#include <cmath>

using namespace std;

void ispis(vector <int> &a)
{
    for(int i=0;i<a.size();i++)
        cout<<a[i]<<" ";
    cout<<endl;
}

long long glavna(vector <int> &a)
{
    int c=0;
    long long u=0;
    for(int i=0;i<a.size();i++)
    {
        u+=abs(c);
        c+=a[i]-1;
        //printf("%d ",c);
    }
    return u;
}

int main()
{
    int n,k,l;
    scanf("%d",&n);
    vector <int> a(n,0),b(n,0);
    for(int i=0;i<n;i++)
    {
        scanf("%d %d",&k,&l);
        a[k-1]++;
        b[l-1]++;
    }
    //ispis(a);
    //ispis(b);
    //printf("%lld\n",glavna(a));
    //printf("%lld\n",glavna(b));
    printf("%lld\n",glavna(a)+glavna(b));

    return 0;
}