#include <bits/stdc++.h>
using namespace std;
int a[100010];
struct node {
  int high, x, y;
};
node st[100010];
vector<node> ans;
int main() {
  int n, i, top;
  int tot;
  node tmp;
  while (~scanf("%d", &n)) {
    top = -1;
    ans.clear();
    for (i = 0; i < n; i++) scanf("%d", &a[i]);
    for (i = 0; i < n; i++) {
      if (top < 0 || a[i] > st[top].high) {
        tmp.high = a[i];
        tmp.x = tmp.y = i;
        st[++top] = tmp;
      } else {
        for (; top > 0 && st[top - 1].high >= a[i];) {
          tmp = st[top];
          tmp.high -= st[top - 1].high;
          ans.push_back(tmp);
          st[--top].y = tmp.y;
        }
        tmp = st[top];
        tmp.high -= a[i];
        ans.push_back(tmp);
        st[top].high = a[i];
        st[top].y = i;
      }
    }
    for (; top > 0; top--) {
      tmp = st[top];
      tmp.high -= st[top - 1].high;
      ans.push_back(tmp);
      st[top - 1].y = st[top].y;
    }
    ans.push_back(st[top]);
    for (tot = i = 0; i < (int)ans.size(); i++) tot += ans[i].high;
    printf("%d\n", tot);
    for (i = 0; i < (int)ans.size(); i++) {
      while (ans[i].high--) printf("%d %d\n", ans[i].x + 1, ans[i].y + 1);
    }
  }
  return 0;
}
