#include<bits/stdc++.h>
#define Rint register int
using namespace std;
typedef long long LL;
const int N = 200003;
template<typename T>
inline void read(T &x){
	int ch = getchar(); x = 0;
	bool flag = false;
	while((ch < '0' || ch > '9') && ch != '-') ch = getchar();
	if(ch == '-'){
		flag = true;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9'){
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	if(flag) x = -x;
}
int n, fa[N], siz[N][2];
LL ans;
inline int getfa(int x){
	return x == fa[x] ? x : fa[x] = getfa(fa[x]);
}
int main(){
	read(n);
	for(Rint i = 1;i <= 200000;i ++) fa[i] = i, siz[i][0] = (i <= 100000), siz[i][1] = (i > 100000);
	for(Rint i = 1;i <= n;i ++){
		int x, y;
		read(x); read(y); y += 100000;
		x = getfa(x); y = getfa(y);
		if(x != y){
			ans += (LL) siz[x][0] * siz[y][1] + (LL) siz[x][1] * siz[y][0];
			siz[x][0] += siz[y][0];
			siz[x][1] += siz[y][1];
			fa[y] = x;
		}
	}
	printf("%lld\n", ans - n);
}