#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const long long inf = 1e18;
int a[100005], pre[100005];
int main() {
  ios_base::sync_with_stdio(0);
  int n, mn = 1e9;
  cin >> n;
  a[0] = 0;
  a[n + 1] = 0;
  vector<pair<int, int> > ans;
  for (int i = 1; i <= n + 1; i++) {
    cin >> a[i];
    int cur = 0, pr = a[i - 1];
    if (i <= n) cur = a[i];
    if (cur > pr) {
      for (int j = pr + 1; j <= cur; j++) {
        pre[j] = i;
      }
    } else {
      for (int j = cur + 1; j <= pr; j++) {
        ans.push_back({pre[j], i - 1});
      }
    }
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i].first << " " << ans[i].second << endl;
  }
}
