#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
using namespace std;

typedef long long ll;
typedef vector <ll> v_ll;
typedef vector <vector <ll> > vv_ll;
typedef vector < pair <ll,ll> > vp_ll;
typedef pair <ll,ll> p_ll;

bool TEST=false;
ll MOD = 1000000007;

void show(){if (TEST){cout << endl;}}
void show(string x){if (TEST){cout << x;}}
void show(string x,bool enter){
  if (TEST){if (enter) cout << "<#> " << x << endl;else cout << x;}
}
void show(ll x){if (TEST){cout << x;}}
void show(ll x,bool enter){
  if (TEST){if (enter) cout << "<#> " << x << endl;else cout << x;}
}
void show(p_ll p){
  if (TEST){cout << "{ ";show(p.first);cout << " ";show(p.second);cout << " }";}
}
void show(v_ll v){
  if (TEST){
    cout << "<begin> ";
    for (ll i=0;i<v.size();i++){show(v[i]); cout << " ";}cout <<"<end>"<< endl;
}}
void show(vv_ll v){
  if (TEST){
    cout << "//////////" << endl;
    for (ll i=0;i<v.size();i++){
      show(v[i]); cout << endl;
}}}
void show(vp_ll v){
  if (TEST){
    cout << "//////////" << endl;
    for (ll i=0;i<v.size();i++){
      show(v[i]); cout << endl;
}}}

ll mod(ll x){
  ll n=MOD;
  ll ret=x%n;
  if (ret<0)ret+=n;
  return ret;
}
void mod_self(ll &x){
  x=mod(x);
}
ll mod_inv(ll x){
  ll n=MOD;
  ll y = x,z = n-2, ret=1;
  y=mod(y);
  while (z>0){
    if(z%2==1) ret=mod(ret*y);
    y=mod(y*y);
    z/=2;
  }
  return ret;
}
ll mod_pow(ll x,ll a){
  ll y = x,z = a,ret=1;
  y=mod(y);
  if (z<0)z=-z;
  while (z>0){
    if(z%2==1) ret=mod(ret*y);
    y=mod(y*y);
    z/=2;
  }
  if (a<0) ret=mod_inv(ret);
  return ret;
}
v_ll mod_nck(ll n){
  v_ll nck(n+1,0);
  nck[0]=1;
  for (ll i=1;i<=n;i++){
    nck[i]=mod(nck[i-1]*(n+1-i));
    nck[i]=mod(nck[i]*mod_inv(i));
  }
  return nck;
}
v_ll mod_factorial(ll n){
  v_ll fct(n+1,0);
  fct[0]=1;
  for (ll i=1;i<=n;i++){
    fct[i]=mod(fct[i-1]*i);
  }
  return fct;
}


//comparison for pair
bool comp_f_ls(const p_ll &x,const p_ll &y){
  if (x.first<y.first)return true;
  if (x.first>y.first)return false;
  if (x.second<y.second)return true;
  if (x.second>y.second)return false;
  return false;
}

//comparison for pair
bool comp_s_ls(const p_ll &x,const p_ll &y){
  if (x.second<y.second)return true;
  if (x.second>y.second)return false;
  if (x.first<y.first)return true;
  if (x.first>y.first)return false;
  return false;
}

//comparison for pair
bool comp_f_gr(const p_ll &x,const p_ll &y){
  return comp_f_ls(y,x);
}

//comparison for pair
bool comp_s_gr(const p_ll &x,const p_ll &y){
  return comp_s_ls(y,x);
}



ll N;
vp_ll A;
vv_ll G;
v_ll Q;
int main(){
  ll L=100000;
  cin >> N;
  A.assign(N+10,make_pair(0,0));
  G.assign(L*2+10,v_ll());
  Q.assign(L*2+10,0);
  for (ll i=1;i<=N;i++){
    cin >> A[i].first >> A[i].second;
    Q[A[i].first]++;
    Q[A[i].second+L]++;
  }
  sort(A.begin()+1,A.begin()+N+1,comp_f_ls);
  for (ll i=2;i<=N;i++){
    if(A[i].first==A[i-1].first){
      G[A[i].second+L].push_back(A[i-1].second+L);
      G[A[i-1].second+L].push_back(A[i].second+L);
    }
  }
  sort(A.begin()+1,A.begin()+N+1,comp_s_ls);
  for (ll i=2;i<=N;i++){
    if(A[i].second==A[i-1].second){
      G[A[i].first].push_back(A[i-1].first);
      G[A[i-1].first].push_back(A[i].first);
    }
  }
  /*
  for (ll i=1;i<=100;i++){
    cout << Q[i] << endl;
  }
  for (ll i=1+L;i<=100+L;i++){
    cout << Q[i] << endl;
  }*/
  for (ll i=1;i<=N;i++){
    G[A[i].first].push_back(A[i].second+L);
    G[A[i].second+L].push_back(A[i].first);
  }
  /*
  TEST=true;
  show(G[1]);
show(G[2]);
show(G[3]);
show(G[4]);
show(G[5]);
show(G[L+1]);
show(G[L+2]);
show(G[L+3]);
show(G[L+4]);
show(G[L+5]);
*/
  queue <ll> que;
  ll ans=-N;
  v_ll S(2*L+10,0);
  for (ll i=1;i<=2*L;i++){
    if (Q[i]==0)continue;
    if (S[i]==1)continue;
    //cout << "hoge" << i << endl;
    que.push(i);
    S[i]=1;
    ll x=0,y=0;
    while (!que.empty()){
      ll f=que.front();
      //cout << "HUGA" << f << endl;

      if (f<=L)x++;
      else y++;
      que.pop();
      for (ll j=0;j<G[f].size();j++){
        if (S[G[f][j]]==0){
          que.push(G[f][j]);
          S[G[f][j]]=1;
        }
      }
    }
    ans+=x*y;
    //cout  << x*y << endl;
    //cout  << x*y << endl;
  }
  cout << ans << endl;
}


Measured memory_bytes: 16768