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

class unionfind {
  vector<int> parent;
  public:  
  void init(int n) {
    for (int i = 0; i < n; i++) {
      parent.push_back(i);
    }
  }
  
  void merge(int m, int n) {
    if (find(m) == find(n)) return;
    parent.at(find(m)) = find(n);
  }
  
  int find(int n) {
    if (parent.at(n) == n) return n;
    return parent.at(n) = find(parent.at(n));
  }
};

int main()
{
  int n;
  cin >> n;
  unionfind t;
  t.init(200000);
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    t.merge(x - 1, y + 99999);
  }
  vector<int> sx(200000), sy(200000);
  for (int i = 0; i < 100000; i++) {
    sx.at(t.find(i))++;
    sy.at(t.find(i + 100000))++;
  }
  long s = 0;
  for (int i = 0; i < 200000; i++) {
    s += (long)sx.at(i) * sy.at(i);
  }
  cout << s - n << endl;
}
