#include <bits/stdc++.h>
using namespace std;
struct debugger {
  template <typename T>
  debugger& operator,(const T& v) {
    cerr << v << " ";
    return *this;
  }
} debug;
template <typename T1, typename T2>
inline ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <typename T>
inline ostream& operator<<(ostream& os, const vector<T>& v) {
  bool first = true;
  os << "[";
  for (typename vector<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii) {
    if (!first) os << ", ";
    os << *ii;
    first = false;
  }
  return os << "]";
}
const int NN = 112345;
int od[NN], inp[NN];
vector<pair<int, int> > ans[NN];
bool cmp(int x, int y) {
  if (inp[x] == inp[y]) return (x < y);
  return (inp[x] < inp[y]);
}
void solve() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> inp[i], od[i] = i;
  sort(od + 1, od + 1 + n, cmp);
  ans[0].push_back(make_pair(1, n));
  int cnt = 0;
  for (int i = 1, j = 1; i <= inp[od[n]] and j <= n; ++i) {
    int sz = (int)ans[i - 1].size();
    for (int k = 0; k < sz and j <= n; ++k) {
      int st = ans[i - 1][k].first, en = ans[i - 1][k].second;
      while (j <= n and st <= en and inp[od[j]] == i - 1 and od[j] <= en) {
        if (st <= od[j] - 1) ans[i].push_back(make_pair(st, od[j] - 1)), ++cnt;
        st = od[j++] + 1;
      }
      if (st <= en) ans[i].push_back(make_pair(st, en)), ++cnt;
    }
  }
  cout << cnt << endl;
  for (int i = 1; i <= inp[od[n]] + 1; ++i) {
    int sz = (int)ans[i].size();
    for (int j = 0; j < sz; ++j)
      cout << ans[i][j].first << " " << ans[i][j].second << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  solve();
  return 0;
}
