#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
const int N = 1e5;
int32_t n, a[N + 1];
vector<int32_t> b;
vector<pair<int32_t, int32_t>> ans;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout << fixed;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i <= n; i++) {
    while ((int)b.size() < a[i]) b.push_back(i);
    while ((int)b.size() > a[i])
      ans.emplace_back(b.back() + 1, i), b.pop_back();
  }
  cout << ans.size() << endl;
  for (pii lr : ans) {
    cout << lr.first << ' ' << lr.second << '\n';
  }
  return 0;
}
