#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v(n + 2);
  for (int i = 0; i < n; i++) cin >> v[i + 1];
  vector<pair<int, int> > ans, out;
  for (int i = 1; i < n + 2; i++) {
    int diff = v[i] - v[i - 1];
    if (diff == 0) continue;
    if (diff > 0)
      for (int k = 0; k < diff; k++) ans.push_back(make_pair(i, 0));
    if (diff < 0) {
      for (int k = 0; k < abs(diff); k++) {
        pair<int, int> p = ans[ans.size() - 1];
        ans.pop_back();
        p.second = i - 1;
        out.push_back(p);
      }
    }
  }
  cout << out.size() << endl;
  for (int i = 0; i < out.size(); i++)
    cout << out[i].first << " " << out[i].second << endl;
  return 0;
}
