#include<bits/stdc++.h>
using namespace std;
const int maxn = 100005;
typedef long long ll;
vector<int> v[maxn*2];
vector<int> cnt;
bool visited[maxn*2];

void dfs(int x)
{
     if (visited[x]) return;
    visited[x] = true;
    cnt[x/maxn]++;
    for(auto u: v[x]) dfs(u);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        int x,y;
        cin >> x >> y;
        y += maxn;
        v[x].push_back(y);
        v[y].push_back(x);
    }

    ll ans = 0;
    for(int i = 0; i < 2*maxn; i++){
        if(visited[i]) continue;
        cnt = vector<int> (2);
        dfs(i);
        ans += (ll) cnt[0] * cnt[1];
    }
    ans -= n;
    cout << ans << endl;
    return 0;
}
