let n = read_int ();;
let g = Array.init 200000 (fun _ -> []);;
let visited = Array.make 200000 false;;

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

let rec dfs u cl cr = 
  if not visited.(u) then (
    if u < 100000 then
      cl := !cl + 1
    else
      cr := !cr + 1;
    visited.(u) <- true;
    List.iter (fun v -> dfs v cl cr) g.(u);
  );;


let ans = ref (-n);;
for i = 0 to 199999 do
  let cl = ref 0 and cr = ref 0 in
  dfs i cl cr;
  ans := !ans + !cl * !cr;
done;;

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