#![allow(non_snake_case)]

fn main() {
    use std::collections::{VecDeque, HashSet};

    let stdin = std::io::stdin();
    let mut stdin = my::io::InputReader::new(stdin.lock());
    
    let N: usize = stdin.read();
    let (x, y): (Vec<i32>, Vec<i32>) = (0..N).map(|_| (stdin.read::<i32>(), stdin.read::<i32>())).unzip();

    // neighbors[i][0]: left (-y) neighbor of i,
    // neighbors[i][1]: right (+y) neighbor of i,
    // neighbors[i][2]: up (-x) neighbor of i,
    // neighbors[i][3]: down (+x) neighbor of i,
    let mut neighbors: Vec<Vec<Option<usize>>> = vec![vec![None; 4]; N];
    let mut xyi: Vec<_> = (0..N).map(|i| (x[i], y[i], i)).collect();
    let mut yxi: Vec<_> = (0..N).map(|i| (y[i], x[i], i)).collect();
    xyi.sort();
    yxi.sort();
    for j in 0..N - 1 {
        let (x1, _y1, i1) = xyi[j];
        let (x2, _y2, i2) = xyi[j + 1];
        if x1 == x2 {
            neighbors[i1][1] = Some(i2);
            neighbors[i2][0] = Some(i1);
        }

        let (y1, _x1, i1) = yxi[j];
        let (y2, _x2, i2) = yxi[j + 1];
        if y1 == y2 {
            neighbors[i1][3] = Some(i2);
            neighbors[i2][2] = Some(i1);
        }
    }

    let mut result: u64 = 0;
    let mut used = vec![false; N];
    for i in 0..N {
        if !used[i] {
            used[i] = true;
            let mut q = VecDeque::<usize>::new();
            let mut xs = HashSet::<i32>::new();
            let mut ys = HashSet::<i32>::new();
            let mut count_points = 1;
            q.push_back(i);
            xs.insert(x[i]);
            ys.insert(y[i]);
            while !q.is_empty() {
                let j: usize = *q.front().unwrap();
                q.pop_front();
                for dir in 0..4 {
                    if let Some(k) = neighbors[j][dir] {
                        if !used[k] {
                            used[k] = true;
                            q.push_back(k);
                            xs.insert(x[k]);
                            ys.insert(y[k]);
                            count_points += 1;
                        }
                    }
                }
            }
            result += xs.len() as u64 * ys.len() as u64 - count_points;
        }
    }
    println!("{}", result);
}

#[allow(dead_code, unused_must_use)]
mod my {
    pub mod io {
        use std::io::{BufRead, ErrorKind, Result};
        use std::str::{FromStr, from_utf8};
        use std::fmt::Debug;

        pub fn read_word<R: BufRead>(r: &mut R, buf: &mut Vec<u8>)
                                              -> Result<usize> {
            let mut read = 0;
            loop {
                let (done, used) = {
                    let available = match r.fill_buf() {
                        Ok(n) => n,
                        Err(ref e) if e.kind() == ErrorKind::Interrupted => continue,
                        Err(e) => return Err(e)
                    };
                    match available.iter().position(|&x| x == b'\n' || x == b' ') {
                        Some(i) => {
                            buf.extend_from_slice(&available[..i]);
                            (true, i + 1)
                        }
                        None => {
                            buf.extend_from_slice(available);
                            (false, available.len())
                        }
                    }
                };
                r.consume(used);
                read += used;
                if done || used == 0 {
                    return Ok(read);
                }
            }
        }

        pub struct InputReader<R: BufRead> {
            reader: R,
            buf: Vec<u8>,
        }

        impl<R: BufRead> InputReader<R> {
            pub fn new(reader: R) -> InputReader<R> {
                InputReader {
                    reader: reader,
                    buf: Vec::<u8>::new(),
                }
            }

            pub fn read_word(&mut self) {
                read_word(&mut self.reader, &mut self.buf);
            }
            
            pub fn read<T>(&mut self) -> T
                where T: FromStr,
                      T::Err: Debug
            {
                self.buf.clear();
                self.read_word();
                from_utf8(&self.buf).unwrap().trim().parse().unwrap()
            }
        }
    }
}

Measured memory_bytes: 22248