#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int values[N], tree[4 * N], lazy[4 * N];
void build(int id, int l, int r) {
  if (l == r) {
    tree[id] = values[l];
  } else {
    int mid = (l + r) / 2;
    build(2 * id + 1, l, mid);
    build(2 * id + 2, mid + 1, r);
    tree[id] = min(tree[2 * id + 1], tree[2 * id + 2]);
  }
}
void do_lazy(int id, int l, int r) {
  if (lazy[id]) {
    tree[id] -= lazy[id];
    if (l != r) {
      lazy[2 * id + 1] += lazy[id];
      lazy[2 * id + 2] += lazy[id];
    }
    lazy[id] = 0;
  }
}
int query(int id, int l, int r, int i, int j) {
  if (r < i or l > j) {
    return INT_MAX;
  }
  do_lazy(id, l, r);
  if (l >= i and r <= j) {
    return tree[id];
  }
  int mid = (l + r) / 2;
  return min(query(2 * id + 1, l, mid, i, j),
             query(2 * id + 2, mid + 1, r, i, j));
}
void update(int id, int l, int r, int i, int j, int delta) {
  do_lazy(id, l, r);
  if (r < i or l > j) {
    return;
  }
  if (l >= i and r <= j) {
    lazy[id] = delta;
    do_lazy(id, l, r);
    return;
  }
  int mid = (l + r) / 2;
  update(2 * id + 1, l, mid, i, j, delta);
  update(2 * id + 2, mid + 1, r, i, j, delta);
  tree[id] = min(tree[2 * id + 1], tree[2 * id + 2]);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> values[i];
  }
  build(0, 0, n - 1);
  vector<pair<int, int> > asw;
  for (int i = 0; i < n; ++i) {
    while (query(0, 0, n - 1, i, i) > 0) {
      int l = i, r = n - 1, til = i;
      while (l <= r) {
        int mid = (l + r) / 2;
        if (query(0, 0, n - 1, i, mid) > 0) {
          til = mid;
          l = mid + 1;
        } else {
          r = mid - 1;
        }
      }
      update(0, 0, n - 1, i, til, 1);
      asw.push_back({i + 1, til + 1});
    }
  }
  cout << (int)asw.size() << endl;
  for (int i = 0; i < (int)asw.size(); ++i) {
    cout << asw[i].first << " " << asw[i].second << endl;
  }
  return 0;
}
