#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void ri(T &i) {
  char c;
  for (c = getchar(); c < '0' || c > '9'; c = getchar())
    ;
  for (i = 0; c >= '0' && c <= '9'; c = getchar())
    i = (i << 3) + (i << 1) + (c - 48);
}
struct node {
  int ind, num;
};
int n;
int ans;
int ansa[1000000][2];
node tree[300009];
int a[100009];
node basenode;
node process(node a, node b) {
  if (a.num < b.num)
    return a;
  else
    return b;
}
void buildtree(int i, int lo, int hi) {
  if (lo >= hi) {
    tree[i].num = a[lo];
    tree[i].ind = lo;
    return;
  }
  int mid = (hi + lo) / 2;
  buildtree(2 * i + 1, lo, mid);
  buildtree(2 * i + 2, mid + 1, hi);
  tree[i] = process(tree[2 * i + 1], tree[2 * i + 2]);
}
node query(int i, int lo, int hi, int start, int stop) {
  if (start > hi || stop < lo) return basenode;
  if (start <= lo && hi <= stop) return tree[i];
  int mid;
  mid = (lo + hi) / 2;
  node m1, m2;
  m1 = query(2 * i + 1, lo, mid, start, stop);
  m2 = query(2 * i + 2, mid + 1, hi, start, stop);
  return process(m1, m2);
}
void fx(int start, int end, int sum) {
  if (end < start) return;
  node temp;
  temp = query(0, 0, n - 1, start - 1, end - 1);
  for (typeof(temp.num - sum) i = 0; i < temp.num - sum; i++) {
    ansa[ans][0] = start;
    ansa[ans][1] = end;
    ans++;
  }
  fx(start, temp.ind, temp.num);
  fx(temp.ind + 2, end, temp.num);
}
int main() {
  ri(n);
  basenode.num = 10000000;
  basenode.ind = -1;
  for (typeof(n) i = 0; i < n; i++) {
    ri(a[i]);
  }
  ans = 0;
  buildtree(0, 0, n - 1);
  node u = query(0, 0, n - 1, 0, 2);
  fx(1, n, 0);
  cout << ans << endl;
  for (typeof(ans) i = 0; i < ans; i++) {
    printf("%d %d\n", ansa[i][0], ansa[i][1]);
  }
}
