#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  stack<pair<int, int> > S;
  S.push(make_pair(0, -1));
  vector<pair<int, int> > ans;
  for (int i = 0; i <= n; i++) {
    int a;
    if (i < n)
      cin >> a;
    else
      a = 0;
    while (S.top().first > a) {
      pair<int, int> last = S.top();
      S.pop();
      ans.push_back(make_pair(last.second, i - 1));
      last.first--;
      if (last.first > S.top().first) S.push(last);
    }
    if (S.top().first != a) S.push(make_pair(a, i));
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i].first + 1 << " " << ans[i].second + 1 << endl;
}
