#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<pair<int, int> > v;
  vector<pair<int, int> > res;
  int n, d = 1, pre = 0, cur;
  for (cin >> n; n; n--, d++) {
    cin >> cur;
    if (cur > pre) {
      for (int i = 0; i < cur - pre; i++) v.push_back(make_pair(d, -1));
    } else if (cur < pre) {
      for (int i = 0; i < pre - cur; i++) {
        v[v.size() - 1].second = d - 1;
        res.push_back(v[v.size() - 1]);
        v.pop_back();
      }
    }
    pre = cur;
  }
  for (int i = 0; i < cur; i++) {
    v[v.size() - 1].second = d - 1;
    res.push_back(v[v.size() - 1]);
    v.pop_back();
  }
  cout << res.size() << endl;
  for (int i = 0; i < res.size(); i++)
    cout << res[i].first << " " << res[i].second << endl;
}
