#include <bits/stdc++.h>
using namespace std;

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

const int N = 100000;
int n;
vector<int> graph[N*2+1];
int seen[N*2+1];

void dfs(int cur, int& l, int& r) {
    seen[cur] = true;
    if(cur <= N) l++;
    else r++;
    for(auto child : graph[cur]) {
        if(!seen[child]) {
            dfs(child, l, r);
        }
    }
}

int32_t main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    for(int i = 0; i < n; ++i) {
        int x, y; cin >> x >> y;
        graph[x].push_back(y+N);
        graph[y+N].push_back(x);
    }

    int ans = 0;
    for(int i = 1; i <= N; ++i) {
        if(!seen[i]) {
            int l = 0, r = 0;
            dfs(i, l, r);
            ans += l*r;
        }
    }
    ans -= n;

    cout << ans << endl;
    
    return 0;
}
