#include <bits/stdc++.h>
std::stack<int> S;
const int N = 101000;
int t[N];
int flag1[N], flag2[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &t[i]);
  int sum = 0;
  for (int i = 0; i <= n; i++)
    if (t[i + 1] > t[i]) {
      flag1[i + 1] += t[i + 1] - t[i];
      sum += t[i + 1] - t[i];
    } else if (t[i + 1] < t[i])
      flag2[i] += t[i] - t[i + 1];
  printf("%d\n", sum);
  int now = 1;
  while (now <= n) {
    for (int i = flag1[now]; i >= 1; i--) {
      S.push(now);
    }
    for (int i = flag2[now]; i >= 1; i--) {
      int a = S.top();
      S.pop();
      printf("%d %d\n", a, now);
    }
    now++;
  }
  scanf(" ");
}
