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