#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int a[100100];
  cin >> n;
  for (int i = 0; i < (int)(n); i++) cin >> a[i];
  stack<int> l, num;
  vector<pair<int, int> > ans;
  l.push(0);
  num.push(0);
  for (int i = 0; i < n; i++) {
    while (num.top() > a[i]) {
      int tmp = num.top();
      num.pop();
      int hoge = l.top();
      l.pop();
      if (num.top() >= a[i]) {
        tmp -= num.top();
        while (tmp--) ans.push_back(pair<int, int>(hoge, i));
      } else if (num.top() < a[i]) {
        tmp -= a[i];
        while (tmp--) ans.push_back(pair<int, int>(hoge, i));
        l.push(hoge);
        num.push(a[i]);
      }
    }
    if (num.top() < a[i]) {
      l.push(i + 1);
      num.push(a[i]);
    }
  }
  while (num.top()) {
    int tmp = num.top();
    num.pop();
    tmp -= num.top();
    while (tmp--) ans.push_back(pair<int, int>(l.top(), n));
    l.pop();
  }
  cout << ans.size() << endl;
  for (int i = 0; i < (int)(ans.size()); i++) {
    cout << ans[i].first << " " << ans[i].second << endl;
  }
}
