#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
double const EPS = 1e-10, PI = acos(-1);
const int N = 2e5 + 9, M = 1e5 + 9, OO = 1e9 + 7, MOD = 1e9 + 7;
const ll inf = 1e18;

vector<int> adj[N];
bool vis[N];
ll Xs, Ys;

void dfs(int node) {
  if(node > 1e5)
    ++Ys;
  else
    ++Xs;
  vis[node] = 1;
  for(int it: adj[node]) {
    if(vis[it]) continue;
    dfs(it);
  }
}

int main() {
  fastIO;
#ifdef LOCAL
  freopen("input.in", "rt", stdin);
#endif
  int n, x, y;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> x >> y;
    y += 1e5;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  ll total = 0;
  for (int i = 0; i < N; ++i) {
    if(!vis[i]) {
      Xs = Ys = 0;
      dfs(i);
      total += (Xs * Ys);
    }
  }
  cout << total - n;
  return 0;
}
