#include <bits/stdc++.h>

using namespace std;
const int V=100003;
int n;
bool vis[V*2];
vector<int> r[2*V],cnt;
void dfs(int u)
{
    vis[u]=1;
    cnt[u/V]++;
    for (int v:r[u])
    {
        if (!vis[v]) dfs(v);
    }
}
long long ans=0;
int main()
{
    //freopen("F.in","r",stdin);
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    cin >> n;
    fill(vis+1,vis+2*V,1);
    for (int i=1;i<=n;i++)
    {
        int x,y;
        cin >> x >> y;
        y+=V;
        r[x].push_back(y);
        r[y].push_back(x);
        vis[x]=vis[y]=0;
    }

    for (int i=1;i<V*2;i++)
    {

        if (!vis[i])
        {
            cnt=vector<int> (2,0);
            dfs(i);
            ans+=(long long) cnt[0]*cnt[1];
        }
    }
    cout << ans-n;
}
