import Control.Monad
import Data.Graph
import Data.List (unfoldr, partition)
import Data.Foldable (toList)
import qualified Data.ByteString.Char8 as B

main = do
  n <- readLn
  p <- replicateM n $ (\[a,b]->(a,b)) <$> readIntsLn
  print $ solve n p

solve n p = sum (map cnt cmp) - n where
  cmp = components grp
  grp = buildG (1, 2*10^5) $ map (\(x,y)->(x,y+10^5)) p
  cnt a = x * y where
    (x,y) = (length xs, length ys)
    (xs,ys) = partition (<=10^5) $ toList a

readIntsLn :: IO [Int]
readIntsLn
  = unfoldr (B.readInt.B.dropWhile(==' '))<$>B.getLine