#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n;
  cin >> n;
  long long a[n + 1];
  a[n] = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  stack<int> st;
  int s = 0;
  vector<string> ans;
  for (int i = 0; i < n + 1; i++) {
    while (s < a[i]) {
      st.push(i + 1);
      s++;
    }
    while (s > a[i]) {
      int ind = st.top();
      st.pop();
      ans.push_back(to_string(ind) + " " + to_string(i));
      s--;
    }
  }
  cout << ans.size() << endl;
  for (auto s : ans) {
    cout << s << endl;
  }
}
