#include <bits/stdc++.h>
using namespace std;
int v[100005][2];
int main() {
  stack<int> s;
  int n, a, i;
  scanf("%d", &n);
  int k = 0;
  for (i = 0; i < n; ++i) {
    scanf("%d", &a);
    while (a > s.size()) s.push(i + 1);
    while (a < s.size()) {
      v[k][0] = s.top();
      v[k][1] = i;
      k++;
      s.pop();
    }
  }
  while (s.size()) {
    v[k][0] = s.top();
    v[k][1] = n;
    k++;
    s.pop();
  }
  printf("%d\n", k);
  for (i = 0; i < k; ++i) printf("%d %d\n", v[i][0], v[i][1]);
  return 0;
}
