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

#define ll long long

vector<int> adj[200001];
int vis[200001];
ll cntx,cnty;

void dfs(int v){
	vis[v]=1;
	if(v>100000) cnty++;
	else cntx++;
	for(int u:adj[v]){
		if(vis[u]) continue;
		dfs(u);
	}
	return;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);

	int n,x,y;
	ll ans=0;
	cin>>n;
	memset(vis,0,sizeof(vis));
	for(int i=0;i<n;i++){
		cin>>x>>y;
		adj[x].push_back(100000+y);
		adj[100000+y].push_back(x);
	}
	for(int i=1;i<=100000;i++){
		if(adj[i].size()){
			if(vis[i]==0){
				cntx=cnty=0;
				dfs(i);
				ans+=(cntx*cnty);
			}
		}
	}
	cout<<ans-n<<"\n";
	return 0;
}