let n = read_int ();;

module UnionFind =
  struct
    type unionfind = { size : int array; parent : int array };;
    let make n = {size = Array.make n 1; parent = Array.init n (fun i -> i)};;
    let rec find uf x = (
        if uf.parent.(x) = x then
          x
        else (
          let y = find uf (uf.parent.(x)) in
          uf.parent.(x) <- y;
          y
        )
      );;
    let unite uf x y = (
        let x = find uf x in
        let y = find uf y in
        if x <> y then (
          let x, y = if uf.size.(x) > uf.size.(y) then x, y else y, x in
          uf.size.(x) <- uf.size.(x) + uf.size.(y);
          uf.parent.(y) <- x;
        );
      )
  end;;

let uf = UnionFind.make 200000;;

for i = 0 to n - 1 do
  let x, y = Scanf.scanf " %d %d" (fun x y -> x - 1, y - 1 + 100000) in
  UnionFind.unite uf x y
done;;

let row = Array.make 200000 0;;
let col = Array.make 200000 0;;

for i = 0 to 99999 do
  let j = UnionFind.find uf i in
  row.(j) <- row.(j) + 1;
done;;

for i = 100000 to 199999 do
  let j = UnionFind.find uf i in
  col.(j) <- col.(j) + 1;
done;;

let ans = ref (-n);;
for i = 0 to 199999 do
  ans := !ans + row.(i) * col.(i);
done;;

Printf.printf "%d\n" !ans;;
