#include <bits/stdc++.h>
using namespace std;
int f[100000 + 100], g[100000 + 100];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> g[i];
  }
  int gns = g[0];
  for (int i = 1; i < n; ++i)
    if (g[i] > g[i - 1]) gns += g[i] - g[i - 1];
  int w = g[0], x = 0;
  while (w--) {
    f[x] = 1;
    x++;
  }
  cout << gns << endl;
  g[n] = 0;
  for (int i = 1; i <= n; ++i) {
    if (g[i] >= g[i - 1]) {
      int q = (g[i] - g[i - 1]);
      while (q--) {
        f[x] = i + 1;
        x++;
      }
    } else {
      int p = g[i - 1] - g[i];
      while (p--) {
        x--;
        cout << f[x] << " " << i << endl;
      }
    }
  }
  return 0;
}
