#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265358979323846;
int a[100010], d[100010];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  for (int i = 1; i <= n + 1; i++) d[i] = a[i] - a[i - 1];
  stack<int> st;
  int r = 0;
  for (int i = 1; i <= n; i++) {
    if (d[i] > 0) r += d[i];
  }
  cout << r << endl;
  for (int i = 1; i <= n + 1; i++) {
    if (d[i] > 0) {
      for (int j = 0; j < d[i]; j++) {
        st.push(i);
      }
    }
    if (d[i] < 0) {
      for (int j = 0; j > d[i]; j--) {
        printf("%d %d\n", st.top(), i - 1);
        st.pop();
      }
    }
  }
  return 0;
}
