//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <vector>

namespace n91 {

using i8 = std::int_fast8_t;
using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u8 = std::uint_fast8_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

constexpr usize operator"" _z(unsigned long long x) noexcept {
  return static_cast<usize>(x);
}

class rep {
  const usize f, l;

public:
  class itr {
    friend rep;
    usize i;
    constexpr itr(const usize x) noexcept : i(x) {}

  public:
    void operator++() noexcept { ++i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  constexpr rep(const usize first, const usize last) noexcept
      : f(first), l(last) {}
  constexpr itr begin() const noexcept { return itr(f); }
  constexpr itr end() const noexcept { return itr(l); }
};
class revrep {
  const usize f, l;

public:
  class itr {
    friend revrep;
    usize i;
    constexpr itr(usize x) noexcept : i(x) {}

  public:
    void operator++() noexcept { --i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  constexpr revrep(usize first, usize last) noexcept : f(--first), l(--last) {}
  constexpr itr begin() const noexcept { return itr(l); }
  constexpr itr end() const noexcept { return itr(f); }
};
template <class T> using vec_alias = std::vector<T>;
template <class T> auto md_vec(const usize n, const T &value) {
  return std::vector<T>(n, value);
}
template <class... Args> auto md_vec(const usize n, Args... args) {
  return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> constexpr T difference(const T &a, const T &b) {
  return a < b ? b - a : a - b;
}

} // namespace n91

#include <utility>

namespace n91 {

template <class T> constexpr T gcd(T m, T n) noexcept {
  while (n != static_cast<T>(0)) {
    m %= n;
    std::swap(m, n);
  }
  return m;
}

template <class T> constexpr T lcm(const T &m, const T &n) noexcept {
  return m / gcd(m, n) * n;
}

} // namespace n91

#include <cassert>
#include <cstddef>
#include <utility>
#include <vector>

namespace n91 {

class incremental_connectivity {
protected:
  class node_type;

public:
  using container_type = std::vector<node_type>;
  using size_type = typename container_type::size_type;
  class connected_component {
    friend incremental_connectivity;
    const node_type &root;
    constexpr connected_component(const node_type &root) noexcept
        : root(root) {}

  public:
    constexpr size_type representative() const noexcept { return root.parent; }
    constexpr size_type size() const noexcept { return root.size; }
    constexpr bool operator==(const connected_component &rhs) const noexcept {
      return &root == &rhs.root;
    }
    constexpr bool operator!=(const connected_component &rhs) const noexcept {
      return &root != &rhs.root;
    }
  };

protected:
  class node_type {
  public:
    size_type parent, size;
  };
  container_type tree;

public:
  incremental_connectivity() : tree() {}
  explicit incremental_connectivity(const size_type size) : tree(size, {0, 1}) {
    for (size_type i = 0; i < size; ++i)
      tree[i].parent = i;
  }

  bool empty() const { return tree.empty(); }
  size_type size() const { return tree.size(); }

  connected_component find_cc(size_type x) {
    while (tree[x].parent != x) {
      x = tree[x].parent = tree[tree[x].parent].parent;
    }
    return connected_component(tree[x]);
  }

  std::pair<size_type, size_type> unite(size_type x, size_type y) {
    assert(x < size());
    assert(y < size());
    x = find_cc(x).representative();
    y = find_cc(y).representative();
    if (x != y) {
      if (tree[x].size < tree[y].size)
        std::swap(x, y);
      tree[x].size += tree[y].size;
      tree[y].parent = x;
    }
    return {x, y};
  }
};

} // namespace n91

#include <algorithm>
#include <array>
#include <iostream>
#include <queue>
#include <string>
#include <utility>

namespace n91 {

void main_() {

  constexpr usize limit = 100000_z;
  incremental_connectivity ic(limit * 2_z);

  usize n;
  std::cin >> n;

  for (const auto i : rep(0_z, n)) {
    usize x, y;
    std::cin >> x >> y;
    --x;
    --y;
    ic.unite(x, limit + y);
  }

  struct counter {
    u64 x, y;
  };

  std::array<counter, limit * 2_z> count = {};

  for (const auto i : rep(0_z, limit)) {
    ++count[ic.find_cc(i).representative()].x;
    ++count[ic.find_cc(limit + i).representative()].y;
  }

  u64 ans = static_cast<u64>(0);

  for (const auto &cc : count) {
    ans += cc.x * cc.y;
  }

  std::cout << ans - static_cast<u64>(n) << std::endl;
}

} // namespace n91

int main() {
  n91::main_();
  return 0;
}


Measured memory_bytes: 6528