#include <bits/stdc++.h>
using namespace std;
vector<int> sorted;
vector<set<int> > v;
set<int> solve(int lf, int rg) {
  if (lf == rg) {
    return v[lf];
  }
  int md = (lf + rg) >> 1;
  set<int> x = solve(lf, md);
  set<int> y = solve(md + 1, rg);
  for (int val : y) {
    v[md + 1].insert(val);
  }
  for (int val : x) {
    v[md].insert(val);
  }
  if ((int)(x).size() < (int)(y).size()) {
    for (int val : x) {
      v[md + 1].insert(val);
      y.insert(val);
    }
    return y;
  } else {
    for (int val : y) {
      v[md].insert(val);
      x.insert(val);
    }
    return x;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<pair<int, int> > a(n);
  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    sorted.push_back(x);
    a[i] = {x, y};
  }
  sort((sorted).begin(), (sorted).end());
  sorted.resize(unique((sorted).begin(), (sorted).end()) - sorted.begin());
  v.resize((int)(sorted).size());
  for (int i = 0; i < n; ++i) {
    a[i].first = lower_bound((sorted).begin(), (sorted).end(), a[i].first) -
                 sorted.begin();
    v[a[i].first].insert(a[i].second);
  }
  solve(0, (int)(v).size() - 1);
  vector<pair<int, int> > ans;
  for (int i = 0; i < (int)(v).size(); ++i) {
    for (int y : v[i]) {
      ans.push_back({sorted[i], y});
    }
  }
  cout << (int)(ans).size() << "\n";
  for (int i = 0; i < (int)(ans).size(); ++i) {
    cout << ans[i].first << " " << ans[i].second << "\n";
  }
}
