#include <bits/stdc++.h>
template <typename A, typename B>
inline bool mnset(A &x, B y) {
  return (x > y) ? (x = y, 1) : 0;
}
template <typename A, typename B>
inline bool mxset(A &x, B y) {
  return (x < y) ? (x = y, 1) : 0;
}
using namespace std;
int n, k = 0, a[100002], s[100002];
int ans1[100002], ans2[100002];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    ;
  }
  for (int i = 1; i <= n + 1; i++) {
    if (a[i - 1] < a[i]) {
      for (int j = a[i - 1] + 1; j <= a[i]; j++) {
        s[j] = i;
      }
    } else {
      for (int j = a[i] + 1; j <= a[i - 1]; j++) {
        k++;
        ans1[k] = s[j];
        ans2[k] = i - 1;
      }
    }
  }
  printf("%d ", k);
  printf("\n");
  for (int i = 1; i <= k; i++) {
    printf("%d %d ", ans1[i], ans2[i]);
    printf("\n");
  }
  return 0;
}
