#include <bits/stdc++.h>
using namespace std;
const long long maxn = 5000 * 101;
const long long INF = 1e18;
long long n, a[maxn];
vector<pair<char, long long> > ans1;
vector<pair<long long, long long> > ans;
queue<long long> bra;
int main() {
  std::ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  a[0] = 0;
  a[n + 1] = 0;
  for (int i = 1; i <= n + 1; i++) {
    if (a[i] > a[i - 1]) {
      long long dis = a[i] - a[i - 1];
      for (int j = 0; j < dis; j++) ans1.push_back({'(', i});
    } else if (a[i] < a[i - 1]) {
      long long dis = a[i - 1] - a[i];
      for (int j = 0; j < dis; j++) ans1.push_back({')', i - 1});
    }
  }
  for (int i = 0; i < ans1.size(); i++) {
    if (ans1[i].first == '(') {
      bra.push(ans1[i].second);
    } else {
      long long x2 = bra.front();
      ans.push_back({x2, ans1[i].second});
      bra.pop();
    }
  }
  cout << ans.size() << "\n";
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i].first << " " << ans[i].second << "\n";
  }
  return 0;
}
