#include <bits/stdc++.h>
using namespace std;
int n, i, j, ar[1010000];
stack<int> q;
vector<pair<int, int> > ans;
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &ar[i]);
  ar[0] = ar[n + 1] = 0;
  for (i = 0; i <= n; i++) {
    if (ar[i + 1] >= ar[i]) {
      int dif = ar[i + 1] - ar[i];
      for (j = 0; j < dif; j++) q.push(i + 1);
    } else {
      int dif = ar[i] - ar[i + 1];
      for (j = 0; j < dif; j++) {
        ans.push_back(make_pair(q.top(), i));
        q.pop();
      }
    }
  }
  printf("%d\n", ans.size());
  for (i = 0; i < ans.size(); i++)
    printf("%d %d\n", ans[i].first, ans[i].second);
  return 0;
}
