#include <iostream>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;

ll N;
vector<vector<int>> v(200010);
int vis[200010] = {};

ll dfs(int n,set<int>& sx,set<int>& sy){
    ll cnt = 0;
    vis[n] = 1;
    if(n<=100000) sx.insert(n);
    else sy.insert(n);
    for(auto x:v[n]){
        cnt++;
        if(vis[x]==0) cnt += dfs(x,sx,sy);
    }
    return cnt;
}

int main(){
    cin >> N;
    int x,y;
    for(int i=0;i<N;i++){
        cin >> x >> y;
        v[x].push_back(y+100000);
        v[y+100000].push_back(x);
    }
    ll ans = 0;
    for(int i=1;i<=100000;i++){
        if((int) v[i].size()!=0 && vis[i]==0){
            set<int> sx,sy;
            ll n = dfs(i,sx,sy)/2;
            ll cx = sx.size(),cy = sy.size();
            ans += cx*cy-n;
        }
    }
    cout << ans << endl;
}