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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

const int N = 1e5;
vi adj[2*N+1];
bool visited[2*N+1];
int u, v;

void dfs(int x) {
	visited[x] = true;
	if (x <= N) ++u;
	else ++v;
	for (int y : adj[x])
		if (!visited[y]) dfs(y);
}

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		y += N;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}

	ll answer = 0;
	for (int x = 1; x <= N; x++) {
		if (visited[x]) continue;
		u = 0, v = 0;
		dfs(x);
		answer += (ll)u * v;
	}
	printf("%lld\n", answer - n);
}
