#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 3;
int inp[MAX];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i < n + 1; i++) cin >> inp[i];
  vector<int> v1, v2;
  for (int i = 0; i < n + 1; i++) {
    if (inp[i] < inp[i + 1])
      for (int o = 0; o < inp[i + 1] - inp[i]; o++) v1.push_back(i + 1);
    else if (inp[i] > inp[i + 1])
      for (int o = 0; o < inp[i] - inp[i + 1]; o++) v2.push_back(i);
  }
  cout << v1.size() << endl;
  for (int i = 0; i < v1.size(); i++) cout << v1[i] << " " << v2[i] << endl;
  return 0;
}
