// author: Saman Mahdanian
#include <bits/stdc++.h>

using namespace std;
const int N = 1e5 + 10;

int n, x[N], y[N], par[N];
vector <int> xs[N], ys[N];
set <int> st[N];

int root (int);
void merge (int, int);

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
		xs[x[i]].push_back(i);
		ys[y[i]].push_back(i);
	}

	iota (par, par + n, 0);
	for (int i = 1; i < N; i++) {
		for (int j: xs[i])
			merge(xs[i][0], j);
		for (int j: ys[i])
			merge(ys[i][0], j);
	}

	for (int i = 0; i < n; i++)
		st[root(i)].insert(i);

	long long ans = 0;
	for (int i = 0; i < n; i++) 
		if (st[i].size()) {
			set <int> cx, cy;
			for (int j: st[i]) {
				cx.insert(x[j]);
				cy.insert(y[j]);
			}
			ans += 1LL * cx.size() * cy.size();
		}
	cout << ans - n << endl;
}

int root (int v) {
	return par[v] == v? v : (par[v] = root(par[v]));
}

void merge (int v, int u) {
	par[root(v)] = root(u);
}

// SamMHD :: Jun27-2019 :: Another Day with Shayan...