#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > ans;
stack<int> st;
int a[101010];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= a[i] - a[i - 1]; j++, st.push(i))
      ;
    for (int j = 1; j <= a[i] - a[i + 1];
         j++, ans.push_back(make_pair(st.top(), i)), st.pop())
      ;
  }
  cout << ans.size() << endl;
  for (auto u : ans) cout << u.first << " " << u.second << endl;
  return 0;
}
