#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, r, l, mid, t[4 * N], sz, ob[4 * N];
vector<pair<int, int> > ans;
void update(int v, int l, int r, int tl, int tr, int val) {
  if (ob[v] != 0) {
    t[v] += ob[v];
    ob[v + v] += ob[v];
    ob[v + v + 1] += ob[v];
    ob[v] = 0;
  }
  if (l > r || l > tr || tl > r) {
    return;
  }
  if (tl <= l && r <= tr) {
    t[v] += val;
    ob[v + v] += val;
    ob[v + v + 1] += val;
    return;
  }
  int mid = (r + l) >> 1;
  update(v + v, l, mid, tl, tr, val);
  update(v + v + 1, mid + 1, r, tl, tr, val);
  t[v] = min(t[v + v], t[v + v + 1]);
}
int get_min(int v, int l, int r, int tl, int tr) {
  if (ob[v] != 0) {
    t[v] += ob[v];
    ob[v + v] += ob[v];
    ob[v + v + 1] += ob[v];
    ob[v] = 0;
  }
  if (l > r || l > tr || tl > r) {
    return 2e9;
  }
  if (tl <= l && r <= tr) {
    return t[v];
  }
  int mid = (r + l) >> 1;
  return min(get_min(v + v, l, mid, tl, tr),
             get_min(v + v + 1, mid + 1, r, tl, tr));
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  sz = 1;
  while (sz < n) {
    sz += sz;
  }
  for (int i = 1; i <= sz + sz; i++) {
    t[i] = 2e9;
  }
  for (int i = 1; i <= n; i++) {
    cin >> t[i + sz - 1];
  }
  for (int i = sz - 1; i >= 1; i--) {
    t[i] = min(t[i + i], t[i + i + 1]);
  }
  for (int i = 1; i <= n; i++) {
    int cur = get_min(1, 1, sz, i, i);
    while (cur--) {
      l = i, r = n;
      while (r - l > 1) {
        mid = (r + l) >> 1;
        if (get_min(1, 1, sz, i, mid)) {
          l = mid;
        } else {
          r = mid;
        }
      }
      if (get_min(1, 1, sz, i, r)) {
        l = r;
      }
      update(1, 1, sz, i, l, -1);
      ans.push_back(make_pair(i, l));
    }
  }
  cout << ans.size() << "\n";
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i].first << " " << ans[i].second << "\n";
  }
}
