#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
struct range_s {
  int l, r;
};
int main(int argc, char *argv[]) {
  int a[MAXN];
  stack<int> s;
  int n, i, j, ans;
  struct range_s range[MAXN];
  while (scanf("%d", &n) != EOF) {
    for (i = 1; i <= n; ++i) {
      scanf("%d", a + i);
    }
    a[0] = a[n + 1] = 0;
    while (!s.empty()) s.pop();
    ans = 0;
    for (i = 1; i <= a[1]; ++i) {
      s.push(1);
    }
    for (i = 2; i <= n + 1; ++i) {
      if (a[i] > a[i - 1]) {
        for (j = 1; j <= a[i] - a[i - 1]; ++j) {
          s.push(i);
        }
      } else {
        for (j = 1; j <= a[i - 1] - a[i]; ++j) {
          range[ans].l = s.top();
          range[ans].r = i - 1;
          ++ans;
          s.pop();
        }
      }
    }
    printf("%d\n", ans);
    for (i = 0; i < ans; ++i) {
      printf("%d %d\n", range[i].l, range[i].r);
    }
  }
  return 0;
}
