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

let () =
    let main () =
        let n = Scanf.sscanf (read_line ()) "%d" (fun n -> n) in
        let xy = Array.init n (fun _ -> Scanf.sscanf (read_line ()) "%d %d" (fun x y -> x, y)) in
        let xmap = Array.fold_left (fun map (x, y) ->
            M.add x (y :: (try M.find x map with _ -> [])) map) M.empty xy in
        let ymap = Array.fold_left (fun map (x, y) ->
            M.add y (x :: (try M.find y map with _ -> [])) map) M.empty xy in
        let cx = Array.make 100001 true in
        let cy = Array.make 100001 true in
        let rec dfs_x px list ax ay depth =
            cx.(px) <- false;
            List.fold_left (fun ((ax, ay) as acc) py ->
                if cy.(py) then dfs_y py (M.find py ymap) ax ay (depth + 1) else acc) (ax + 1, ay) list
        and dfs_y py list ax ay depth =
            cy.(py) <- false;
            List.fold_left (fun ((ax, ay) as acc) px ->
                if cx.(px) then dfs_x px (M.find px xmap) ax ay (depth + 1) else acc) (ax, ay + 1) list
        in
        let acc = M.fold (fun x list acc ->
            if cx.(x) then let sx, sy = dfs_x x list 0 0 0 in acc + sx * sy else acc) xmap 0 in
        let acc = M.fold (fun y list acc ->
            if cy.(y) then let sx, sy = dfs_y y list 0 0 0 in acc + sx * sy else acc) ymap acc in
        Printf.printf "%d\n" (acc - n)
    in
    main ()