#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5;
void dfs(ll node,vector<vector<ll>>& adj,vector<bool>& vu,set<ll>& s){
  if(vu[node]) return;
  s.insert(node);
  vu[node] = true;
  for(ll i : adj[node]) dfs(i,adj,vu,s);
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n,x,y;
  cin >> n;
  vector<vector<ll>> adj(2*N);
  for(int i = 0; i < n; ++i){
    cin >> x >> y;
    adj[x-1].push_back(N+y-1);
    adj[N+y-1].push_back(x-1);
  }
  ll ret = -n;
  vector<bool> vu(2*N);
  for(ll i = 0; i < 2*N; ++i){
    set<ll> s;
    dfs(i,adj,vu,s);
    ll nbx = 0,nby = 0;
    for(ll j : s){
      if(j < N) ++nbx;
      else ++nby;
    }
    ret += nbx*nby;
  }
  cout << ret;
  return 0;
}
