module Union_find : sig
  type t
  val make : int -> t
  val find : int -> t -> int
  val size : int -> t -> int
  val same : int -> int -> t -> bool
  val unite : int -> int -> t -> unit
end = struct
  type t = int array
  let make n = Array.make n (-1)
  let rec find x uf =
    if uf.(x) < 0 then x
    else (( let x' = find uf.(x) uf in uf.(x) <- x'; x' ))
  let same x y uf = find x uf = find y uf
  let size x uf = - uf.(find x uf)
  let unite x y uf =
    let x = find x uf and y = find y uf in
    if x <> y then
      if uf.(x) < uf.(y) then ((
        uf.(x) <- uf.(x) + uf.(y);
        uf.(y) <- x
      )) else ((
        uf.(y) <- uf.(x) + uf.(y);
        uf.(x) <- y
      ))
end
module UF = Union_find

module M = Map.Make(struct type t = int let compare = (-) end)
module S = Set.Make(struct type t = int let compare = (-) end)

let () =
  Scanf.scanf "%d" @@ fun n ->
  let uf = UF.make 10000 in
  let xy = Array.init n (fun _ -> Scanf.scanf " %d %d" (fun x y -> x-1, y-1)) in
  Array.sort (fun (a,_) (c,_) -> a-c) xy;
  let _ = Array.fold_left (fun (u, v) (w, x) ->
    if u = w then UF.unite v x uf; (w, x)
  ) (-1, -1) xy in
  let ss = Array.fold_left (fun ss (x, y) ->
    let k = UF.find x uf in
    try M.add k (S.add y (M.find k ss)) ss
    with Not_found -> M.add k (S.singleton y) ss
  ) M.empty xy in
  let t = M.fold (fun k v s -> UF.size k uf * S.cardinal v + s) ss 0 in
  Printf.printf "%d\n" (t - n)
