#include <bits/stdc++.h>
using namespace std;
int n, a[100005], ans, sol[100005][2], dp[100005][2], dw;
void adda(int x, int y) {
  sol[ans][0] = x;
  sol[ans++][1] = y;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  ans = 0;
  dw = 0;
  dp[dw][0] = 0;
  dp[dw++][1] = -1;
  for (int i = 0; i < n; ++i) {
    while (dp[dw - 1][0] > a[i]) {
      adda(dp[dw - 2][1] + 1, dp[dw - 1][1]);
      dp[dw - 1][0]--;
      if (dp[dw - 1][0] == dp[dw - 2][0]) {
        dp[dw - 2][1] = dp[dw - 1][1];
        dw--;
      }
    }
    if (dp[dw - 1][0] == a[i]) {
      dp[dw - 1][1] = i;
    } else {
      dp[dw][0] = a[i];
      dp[dw++][1] = i;
    }
  }
  while (dw > 1) {
    adda(dp[dw - 2][1] + 1, dp[dw - 1][1]);
    dp[dw - 1][0]--;
    if (dp[dw - 1][0] == dp[dw - 2][0]) {
      dp[dw - 2][1] = dp[dw - 1][1];
      dw--;
    }
  }
  printf("%d\n", ans);
  for (int i = 0; i < ans; ++i) printf("%d %d\n", sol[i][0] + 1, sol[i][1] + 1);
  return 0;
}
