#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
using namespace std;

typedef unsigned long long ULL;
typedef long long ll;
const ULL base = 233;
const int N = 100005;

int n;
int f[201000];
ll val1[200100],val2[201000];
int find(int x){return f[x]==x?x:(f[x]=find(f[x]));}

int main(){
    cin>>n;
    FOR(i,1,2*N)f[i]=i;
    FOR(i,1,n){
        int x,y;
        scanf("%d%d",&x,&y);
        f[find(x)]= find(y+N);
    }
    FOR(i,1,N)val1[find(i)]++;
    FOR(i,N+1,2*N)val2[find(i)]++;
    ll ans=0;
    FOR(i,1,2*N){
        ans+=val1[i]*val2[i];
        //if(val1[i]*val2[i])cout<<ans<<" "<<i<<" "<<i-N<<endl;
    }
    printf("%lld\n",ans-n);
}
