#include <bits/stdc++.h>
const double Pi = acos(-1.0);
using namespace std;
int s[100005], now = 0;
int a[100005];
vector<pair<int, int> > ans;
int main(void) {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    while (now < a[i]) s[now++] = i;
    while (now > a[i]) {
      now--, ans.push_back(make_pair(s[now], i - 1));
    }
  }
  while (now > 0) {
    now--;
    ans.push_back(make_pair(s[now], n));
  }
  printf("%d\n", (int)ans.size());
  for (int i = 0; i < (int)ans.size(); i++)
    printf("%d %d\n", ans[i].first, ans[i].second);
  return 0;
}
