#include<iostream>
#include<map>
#include<algorithm>
#include<functional>
#include<bitset>
#include<vector>
#include<set>
using  namespace std;
#define ll long long
#define pb push_back
#define sc second
#define fr first
#define mp make_pair
const int  MOD = 1e9 + 7, OO = 1e9;
const int  N = 1e5 + 10;
int vis[N][3];
vector<int> g[3][N];
set<int> st[2];
void dfs(int u, int t) {
	if (vis[u][t])return;
	vis[u][t] = 1;
	st[t].insert(u);
	for (int i = 0; i < g[t][u].size(); ++i) {
		dfs(g[t][u][i], !t);
	}
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		int a, b;
		cin >> a >> b;
		g[0][a].pb(b);
		g[1][b].pb(a);
	}
	ll ans = 0;
	for (int it = 0; it < 2; ++it) {
		for (int i = 1; i < N; ++i) {
			dfs(i, it);
			ans += st[0].size()*1ll*st[1].size();
			st[1].clear();
			st[0].clear();
		}
	}
	cout << ans - n << endl;

}