#include <bits/stdc++.h>
using namespace std;
ostream& operator<<(ostream& out, const pair<long long, long long>& p) {
  out << '(' << p.first << ", " << p.second << ')';
  return out;
}
void debugPrint(const vector<pair<long long, long long>>& calls, long long n) {
  vector<long long> a;
  a.resize(n, 0);
  for_each(begin(calls), end(calls), [&](pair<long long, long long> p) {
    for_each(begin(a) + (p.first - 1), begin(a) + p.second,
             [&](long long& n) { n++; });
  });
  for_each(begin(a), end(a), [](long long n) { cout << n << ' '; });
  cout << endl;
}
int main() {
  long long n, tmp = 0;
  cin >> n;
  vector<long long> stack;
  vector<pair<long long, long long>> calls;
  calls.reserve(100000);
  stack.reserve(100000);
  for (long long i = 1; i <= n; ++i) {
    long long p = 0;
    cin >> p;
    while (tmp < p) {
      stack.push_back(i);
      tmp++;
    }
    while (p < tmp) {
      calls.push_back(make_pair(stack.back(), i - 1));
      stack.pop_back();
      tmp--;
    }
  }
  while (0 < tmp) {
    calls.push_back(make_pair(stack.back(), n));
    stack.pop_back();
    tmp--;
  }
  cout << calls.size() << endl;
  for_each(begin(calls), end(calls), [](const pair<long long, long long>& p) {
    cout << p.first << ' ' << p.second << endl;
  });
  return 0;
}
