#include <iostream>
#include <utility>
#include <tuple>
#include <string>
#include <cstdint>
#include <vector>
#include <array>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <cassert>
using namespace std;
using i64 = int64_t;
const int OFS = 100000;
i64 n;
vector<int> g[200001];
bool vis[200001];
i64 r, c, p;
void dfs(int u) {
    if (vis[u]) return;
    vis[u] = true;
    if (u <= OFS) ++r;
    else ++c;
    for (int v : g[u]) {
        ++p;
        dfs(v);
    }
}
int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        g[x].push_back(y + OFS);
        g[y + OFS].push_back(x);
    }
    i64 ans = 0;
    for (int u = 1; u <= 200000; ++u) {
        r = c = p = 0;
        dfs(u);
        ans += r * c - p / 2;
    }
    cout << ans << endl;
    return 0;
}