fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val p = (1..n).map { val a = (readLine()!!.split(" ").map { it.toInt() }); Point(it-1, a[0], a[1]) }

    val xy = mutableMapOf<Int, MutableList<Int>>()
    val yx = mutableMapOf<Int, MutableList<Int>>()
    val uf = UnionFind(n)
    p.forEach {
        xy[it.x]?: run { xy[it.x] = mutableListOf() }
        yx[it.y]?: run { yx[it.y] = mutableListOf() }
        xy[it.x]!!.add(it.id)
        yx[it.y]!!.add(it.id)
    }

    xy.map { it.value }.forEach { it.reduce{ a,b -> uf.unite(a,b); b } }
    yx.map { it.value }.forEach { it.reduce{ a,b -> uf.unite(a,b); b } }

    val sum = p.groupBy { uf.find(it.id) }.map { it.value }.map {
        val x = it.distinctBy { it.x }.size
        val y = it.distinctBy { it.y }.size
        1L *x * y
    }.sum()

    println(sum-n)

}

data class Point(val id: Int, val x: Int, val y: Int)

class UnionFind(private val N: Int) {
    private val nodes = (0 until N).toList()
    private val parent = IntArray(N) { it }
    private val roots = parent.toMutableSet()
    private val rank = IntArray(N) { 0 }
    private val size = IntArray(N) { 1 }

    fun group() = nodes.groupBy { find(it) }
    fun groupCount() = roots.size
    fun sameGroupSize(x: Int) = size[find(x)]

    fun find(x: Int): Int = if (parent[x] == x) x else { parent[x] = find(parent[x]); parent[x] }
    fun unite(x: Int, y: Int) {
        val a = find(x)
        val b = find(y)
        if (a == b) return

        if (rank[a] < rank[b]) {
            roots.remove(a)
            parent[a] = b
            size[b] += size[a]
        } else {
            roots.remove(b)
            parent[b] = a
            size[a] += size[b]
            if (rank[a] == rank[b]) rank[a]++
        }
    }
}