#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>

#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <random>
#include <complex>
#include <utility>
#include <tuple>
#include <memory>

#include <array>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <csignal>
#include <cstdint>
#include <cstddef>

#ifdef ONLINE_JUDGE
#define NDEBUG
#endif
#include <cassert>
#include <stdexcept>
#include <exception>

// << pair
template <typename T1, typename T2>
std::ostream&operator<<(std::ostream&os,const std::pair<T1,T2>&p){return os<<"("<<p.first<<", "<<p.second<<")";}
// << container
template <typename C>
std::ostream&_debug_go(std::ostream&os,const C&v) {bool first=true;os<<"[";for(auto i:v){if(!first)os<<", ";os<<i;first=false;}return os<<"]";}
// << {vector, set, map} delegating to _debug_go
template<typename T> std::ostream&operator<<(std::ostream&os,const std::vector<T>&v){return _debug_go(os, v);}
template<typename T> std::ostream&operator<<(std::ostream&os,const std::set<T>&v){return _debug_go(os, v);}
template<typename T1, typename T2> std::ostream&operator<<(std::ostream&os,const std::map<T1,T2>&v){return _debug_go(os, v);}
struct Debugger{template<typename T>Debugger&operator,(const T&v){std::cerr<<v<<" "; return *this;}} dbg;
#ifndef NDEBUG
#define debug(args...) do {dbg,args; cerr << "\n";} while(0)
#else
#define debug(args...)
#endif

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ITER(i, s, e) for (auto i((s)); i != (e); ++i)
#define IT(i, c) ITER(i, (c).begin(), (c).end())

using namespace std;

using ui = uint32_t;
using ll = int64_t;
using ull = uint64_t;
template <typename T = int> using Pt = complex<T>;

template <typename T>
T cross(const Pt<T>& a, const Pt<T>& b) { return a.real() * b.imag() - a.imag() * b.real(); }
// END TEMPLATE


struct UnionFind {
    const int N;
    std::vector<int> p, sz;

    explicit UnionFind(int N) : N(N), p(N), sz(N, 1) {
        std::iota(p.begin(), p.end(), 0);
    }

    int find(int u) {
        if (p[u] == u) return u;
        return p[u] = find(p[u]);
    }

    std::pair<int, bool> unite(int u, int v) {
        u = find(u), v = find(v);
        if (u == v) return {u, false};
        if (sz[u] < sz[v]) std::swap(u, v);
        p[v] = u;
        sz[u] += sz[v];
        return {u, true};
    }

    int size(int u) {
        return sz[find(u)];
    }
};

ll solve(const ll N, const vector<Pt<>>& xs) {
    map<int, int> x2i, y2i;
    for (const auto& p : xs) {
        x2i[p.real()] = 0, y2i[p.imag()] = 0;
    }
    int nx = 0;
    for (auto& xi : x2i) xi.second = nx++;
    int ny = 0;
    for (auto& yi : y2i) yi.second = ny++;
    static UnionFind uf(nx + ny);
    for (const auto& p : xs) {
        int i = x2i[p.real()], j = y2i[p.imag()];
        uf.unite(i, nx + j);
    }
    vector<ll> ct(nx + ny);
    for (const auto& p : xs) {
        int i = x2i[p.real()];
        ++ct[uf.find(i)];
    }
    vector<pair<ll, ll>> ct2(nx + ny);
    REP(i, nx) ++ct2[uf.find(i)].first;
    FOR(j, nx, nx + ny) ++ct2[uf.find(j)].second;
    ll ans = 0;
    REP(i, nx + ny) {
        ans += ct2[i].first * ct2[i].second - ct[i];
    }
    //assert(ans < nx*ny);
    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    ll N; cin >> N;
    vector<Pt<>> xs(N);
    REP(i, N) {
        int x, y; cin >> x >> y;
        xs[i] = {x, y};
    }
    cout << solve(N, xs) << '\n';

    return 0;
}


Measured memory_bytes: 8960