#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)1e5 + 1;
int n, a[maxn], cur;
stack<int> st;
vector<pair<int, int> > ans;
int main() {
  scanf("%d", &n);
  for (int i = 0; i <= n; i++) {
    if (i < n)
      scanf("%d", a + i);
    else
      a[i] = 0;
    if (a[i] == cur) continue;
    if (cur < a[i]) {
      while (cur < a[i]) {
        cur++;
        st.push(i + 1);
      }
    } else {
      while (a[i] < cur) {
        cur--;
        ans.push_back(make_pair(st.top(), i));
        st.pop();
      }
    }
  }
  printf("%d\n", ans.size());
  for (int i = 0; i < ans.size(); i++) {
    printf("%d %d\n", ans[i].first, ans[i].second);
  }
  return 0;
}
