#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  vector<int> lb, rb;
  int pre = 0, cur;
  for (int ii = 0; ii < n; ii++) {
    cin >> cur;
    if (cur > pre) {
      for (int k = 0; k < cur - pre; k++) lb.push_back(ii + 1);
    } else {
      for (int k = 0; k < pre - cur; k++) rb.push_back(ii);
    }
    pre = cur;
  }
  for (int k = 0; k < pre; k++) rb.push_back(n);
  cout << lb.size() << "\n";
  for (int k = 0; k < lb.size(); k++) {
    cout << lb[k] << " " << rb[k] << "\n";
  }
}
