#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  vector<int> s;
  vector<pair<int, int> > ans;
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    while (x > s.size()) s.push_back(i);
    while (x < s.size()) {
      ans.push_back(make_pair(s.back(), i - 1));
      s.pop_back();
    }
  }
  while (!s.empty()) {
    ans.push_back(make_pair(s.back(), n));
    s.pop_back();
  }
  printf("%d\n", ans.size());
  for (int i = 0; i < ans.size(); i++) {
    printf("%d %d\n", ans[i].first, ans[i].second);
  }
}
