#include <bits/stdc++.h>
using namespace std;
const double EPS = 0.0000000001;
int main() {
  int n;
  cin >> n;
  stack<pair<int, int> > st;
  pair<int, int> r[100000];
  int rn = 0;
  for (int i = 1; i <= n; i++) {
    int t;
    cin >> t;
    while (!st.empty() && (st.top()).first > t) {
      int x = (st.top()).first, y = (st.top()).second;
      st.pop();
      r[rn++] = make_pair(y, (i - 1));
      x--;
      if (x)
        if (st.empty() || (st.top()).first < x) st.push(make_pair(x, y));
    };
    if (t)
      if (st.empty() || (st.top()).first < t) st.push(make_pair(t, i));
  }
  while (!st.empty()) {
    {
      int x = (st.top()).first, y = (st.top()).second;
      st.pop();
      r[rn++] = make_pair(y, (n));
      x--;
      if (x)
        if (st.empty() || (st.top()).first < x) st.push(make_pair(x, y));
    };
  }
  cout << rn << endl;
  for (int i = 0; i < rn; i++)
    cout << (r[i]).first << " " << (r[i]).second << endl;
  return 0;
}
