#include <bits/stdc++.h>
using namespace std;
int n, a[100005], dg;
stack<int> s;
vector<pair<int, int> > v;
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  for (int i = 1; i <= n + 1; ++i) {
    for (int t = 0; t < a[i] - dg; ++t) s.push(i);
    dg = max(a[i], dg);
    while (s.size() && dg > a[i]) {
      v.push_back({s.top(), i - 1});
      s.pop();
      --dg;
    }
  }
  cout << v.size() << endl;
  for (int i = 0; i < v.size(); ++i) {
    cout << v[i].first << " " << v[i].second << endl;
  }
}
