

#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll INF=1e18;
vector<ll> x[210005];
vector<ll> used(210005,0);
vector<ll> c(2);
ll cx,cy;

void dfs(ll t){
  //used[n][t]=1;
  if (t>=100005)cy++;
  if (t<100005)cx++;
  used[t]=1;
  for(ll to:x[t]){
    if (used[to])continue;
    dfs(to);
  }
}


int main() {
  ll N;
  cin >> N;
  vector<P> v(N);


  rep(i,N){
    ll a1,b1;
    cin>>a1>>b1;
    a1--;b1+=100005;
    v[i]=make_pair(a1,b1);
    x[a1].push_back(b1);
    x[b1].push_back(a1);
  }
ll ans=0;
  rep(i,N){
    c[0]=0;c[1]=0;
cx=0;cy=0;
    dfs(v[i].first);
  //  cout<<"i"<<i<<cx<<" "<<cy<<endl;
    ans+=cx*cy;

  }

  ans-=N;
  cout<<ans;

}
