#include <bits/stdc++.h>
int ans[100010][2], p, q;
int main() {
  int n, x, p = 0, q = 0, s = 0, i;
  scanf("%d", &n);
  for (i = 1; i <= n + 1; i++) {
    if (i <= n)
      scanf("%d", &x);
    else
      x = 0;
    while (s < x) ans[p++][0] = i, s++;
    while (s > x) ans[q++][1] = i - 1, s--;
  }
  printf("%d\n", p);
  for (i = 0; i < p; i++) printf("%d %d\n", ans[i][0], ans[i][1]);
  return 0;
}
