#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, tmp = 0, res = 0, j = 0;
  cin >> n;
  vector<int> a(n + 1);
  for (i = 0; i < n; i++) cin >> a[i];
  stack<int> s;
  vector<pair<int, int> > output(100000);
  for (i = 0; i <= n; i++) {
    while (a[i] > tmp) {
      s.push(i + 1);
      tmp++;
    }
    while (a[i] < tmp) {
      output[j] = make_pair(s.top(), i);
      s.pop();
      j++;
      tmp--;
    }
  }
  cout << j << endl;
  for (i = 0; i < j; i++)
    cout << output[i].first << " " << output[i].second << endl;
  return 0;
}
