#include <bits/stdc++.h>
using namespace std;
const long long linf = 1e18 + 5;
const int mod = (int)1e9 + 7;
const int logN = 17;
const int inf = 1e9;
const int N = 2e5 + 5;
int main() {
  int n, t;
  vector<pair<int, int> > ans;
  scanf("%d", &n);
  queue<int> q;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &t);
    while (q.size() > t) {
      ans.push_back(make_pair(q.front(), i - 1));
      q.pop();
    }
    while (q.size() < t) q.push(i);
  }
  while (q.size()) {
    ans.push_back(make_pair(q.front(), n));
    q.pop();
  }
  cout << ans.size() << '\n';
  for (__typeof(ans.begin()) it = ans.begin(); it != ans.end(); it++)
    cout << it->first << ' ' << it->second << '\n';
  return 0;
}
