#include <bits/stdc++.h>
using namespace std;
stack<int> baz, baste;
int n, ans;
int main() {
  cin >> n;
  for (int i = 0; i <= n; i++) {
    int y = 0;
    if (i != n) cin >> y;
    while (y > ans) baz.push(i + 1), ans++;
    while (y < ans) baste.push(i), ans--;
  }
  cout << baz.size() << endl;
  while (baz.size()) {
    cout << baz.top() << " " << baste.top() << endl;
    baz.pop(), baste.pop();
  }
}
