// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
#include "../debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

struct UnionFind {
    V<ll> rank;
    V<ll> parent;

    UnionFind(ll N) : rank(N, 0), parent(N) {
        iota(parent.begin(), parent.end(), 0ll);
    }

    ll find(ll child) {
        return (child == parent[child] ? child : parent[child] = find(parent[child]));
    }

    void unit(ll x, ll y) {
        ll px = find(x);
        ll py = find(y);
        if(px == py) {
            return;
        }
        if(rank[px] < rank[py]) {
            swap(px, py);
        }
        parent[py] = px;
        rank[px] += (rank[px] == rank[py]);
    }

    bool same(ll x, ll y) {
        return (find(x) == find(y));
    }
};

int main() {
    ll N;
    cin >> N;
    V<PLL> lis;
    map<ll, V<PLL>> x_mp;
    map<ll, V<PLL>> y_mp;
    for(ll i = 0; i < N; i++) {
        ll x, y;
        cin >> x >> y;
        x_mp[x].emplace_back(y, i);
        y_mp[y].emplace_back(x, i);
        lis.emplace_back(x, y);
    }

    UnionFind uf(N);
    for(ll l = 0; l <= 1; l++) {
        const auto &mp = (l ? x_mp : y_mp);
        for(const auto &ele : mp) {
            const auto &v = ele.second;
            for(ll i = 0; i < v.size() - 1; i++) {
                ll idx0 = v[i].second;
                ll idx1 = v[i + 1].second;
                uf.unit(idx0, idx1);
            }
        }
    }

    ll ans = 0;

    map<ll, V<ll>> connect;
    for(ll i = 0; i < N; i++) connect[uf.find(i)].push_back(i);
    for(const auto &ele : connect) {
        set<ll> xst, yst;
        for(ll idx : ele.second) {
            ll x, y;
            tie(x, y) = lis[idx];
            xst.insert(x);
            yst.insert(y);
        }
        ans += xst.size() * yst.size() - ele.second.size();
    }

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


Measured memory_bytes: 22896