#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e6 + 10;
const long long maxM = 1e6 + 10;
const long long inf = 1e8;
const long long inf2 = 1e17;
template <class T>
void read(T& x) {
  T s = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
  x = s * w;
}
template <class H, class... T>
void read(H& h, T&... t) {
  read(h);
  read(t...);
}
template <typename... T>
void DummyWrapper(T... t) {}
template <class T>
T unpacker(const T& t) {
  cout << ' ' << t;
  return t;
}
template <typename T, typename... Args>
void pt(const T& t, const Args&... data) {
  cout << t;
  DummyWrapper(unpacker(data)...);
  cout << '\n';
}
int N;
int a[maxn], ca[maxn];
struct node {
  int l, r;
} ans[maxn];
int tail;
void solve() {
  int i = 1, j = 1;
  while (i <= N && j <= N) {
    while (j <= N && ca[j] >= 0) j++;
    if (j > N) break;
    while (i <= N && ca[i] == 0) i++;
    if (i > N) break;
    ca[i] -= 1;
    ca[j] += 1;
    ans[++tail] = {i, j - 1};
  }
  printf("%d\n", tail);
  for (int i = 1; i <= tail; i++) {
    printf("%d %d\n", ans[i].l, ans[i].r);
  }
}
int main() {
  read(N);
  for (int i = 1; i <= N; i++) read(a[i]);
  N++;
  for (int i = 1; i <= N; i++) ca[i] = a[i] - a[i - 1];
  solve();
  return 0;
}
