#include <iostream>
#include <set>
#include <vector>

using namespace std;

int n;
vector<int> v[110000];
vector<int> w[110000];
bool visited[110000];

set<int> stx;
set<int> sty;

long long ans;

void dfs(int i)
{
  if (visited[i]) return;
  visited[i] = true;
  int cnt = 0;
  for (int y: v[i]) {
    sty.insert(y);
    for (int x: w[y]) {
      stx.insert(x);
      dfs(x);
    }
  }
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
    w[y].push_back(x);
  }
  
  for (int i = 1; i <= 100000; i++) {
    dfs(i);
    ans += stx.size() * sty.size();
    stx.clear();
    sty.clear();
  }
  ans -= n;
  
  cout << ans << endl;
  return 0;
}