import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

void main() {
    int N;
    scan(N);
    auto x = new int[](N);
    auto y = new int[](N);
    iota(N).each!(i => scan(x[i], y[i]));
    x[] -= 1;
    y[] -= 1;

    int L = 10^^5;
    auto adj = new int[][](2 * L, 0);
    foreach (i ; 0 .. N) {
        adj[x[i]] ~= y[i] + L;
        adj[y[i] + L] ~= x[i];
    }

    auto visited = new bool[](2 * L);

    long ans;
    long cx, cy;

    void dfs(int v) {
        visited[v] = true;
        (v >= L ? cy : cx)++;

        foreach (u ; adj[v]) {
            if (!visited[u]) dfs(u);
        }
    }

    foreach (i ; 0 .. 2 * L) {
        cx = cy = 0;
        if (!visited[i]) {
            dfs(i);
        }
        ans += cx * cy;
    }

    ans -= N;
    writeln(ans);
}








void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}
