#include <iostream>
#include <cstdio>
#include <vector>
#define N 100001
using namespace std;
typedef long long ll;

ll n, x, y, ans, cx, cy, v[200005];
vector<ll> gr[200005];

void dfs(int p) {
	v[p] = 1;
	p>=N ? cy++ : cx++;
	for(int i=0; i<gr[p].size(); i++) {
		if(!v[gr[p][i]]) dfs(gr[p][i]);
	}
}

int main() {
	ll i, x, y;
	cin >> n;
	for(i=0; i<n; i++) {
		scanf("%lld%lld", &x, &y);
		gr[x].push_back(y+N);
		gr[y+N].push_back(x);
	}
	for(i=0; i<=2*N; i++) {
		if(!v[i]) {
			cx = cy = 0;
			dfs(i);
			ans += cx * cy;
		}
	}
	cout << ans - n;
	return 0;
}