#include <bits/stdc++.h>
using namespace std;
inline long long in() {
  int32_t x;
  scanf("%d", &x);
  return x;
}
inline long long lin() {
  long long x;
  scanf("%lld", &x);
  return x;
}
inline string get() {
  char ch[2000010];
  scanf("%s", ch);
  return ch;
}
inline void read(long long *a, long long n) {
  for (long long i = 0; i < n; i++) a[i] = in();
}
template <class blank>
inline void out(blank x) {
  cout << x << "\n";
  exit(0);
}
const long long maxn = 1e5 + 10;
const long long maxm = 1e6 + 10;
const long long maxlg = 21;
const long long base = 29;
const long long mod = 1e9 + 7;
const long long INF = 1e18 + 10;
const long long SQ = 317 + 5;
long long n, a[maxn], mini[4 * maxn], lazy[4 * maxn];
inline void shift(long long p) {
  lazy[2 * p + 1] += lazy[p], lazy[2 * p + 2] += lazy[p];
  mini[2 * p + 1] += lazy[p], mini[2 * p + 2] += lazy[p];
  lazy[p] = 0;
}
inline void build(long long p = 0, long long l = 0, long long r = n - 1) {
  if (l == r) {
    mini[p] = a[l];
    return;
  }
  long long mid = (l + r) >> 1;
  build(2 * p + 1, l, mid);
  build(2 * p + 2, mid + 1, r);
  mini[p] = min(mini[2 * p + 1], mini[2 * p + 2]);
}
inline long long get(long long ql, long long qr, long long p = 0,
                     long long l = 0, long long r = n - 1) {
  if (l > qr || r < ql) return INF;
  if (l >= ql && r <= qr) return mini[p];
  long long mid = (l + r) >> 1;
  shift(p);
  return min(get(ql, qr, 2 * p + 1, l, mid),
             get(ql, qr, 2 * p + 2, mid + 1, r));
}
inline void update(long long ql, long long qr, long long sub, long long p = 0,
                   long long l = 0, long long r = n - 1) {
  if (l > qr || r < ql) return;
  if (l >= ql && r <= qr) {
    lazy[p] -= sub;
    mini[p] -= sub;
    return;
  }
  shift(p);
  long long mid = (l + r) >> 1;
  update(ql, qr, sub, 2 * p + 1, l, mid),
      update(ql, qr, sub, 2 * p + 2, mid + 1, r);
  mini[p] = min(mini[2 * p + 1], mini[2 * p + 2]);
}
vector<pair<long long, long long> > Q;
int32_t main() {
  n = in();
  read(a, n);
  build();
  for (long long i = 0; i < n; i++) {
    while (true) {
      if (!get(i, i)) break;
      long long low = i, hi = n;
      while (low + 1 < hi) {
        long long mid = (low + hi) >> 1;
        if (get(i, mid))
          low = mid;
        else
          hi = mid;
      }
      long long val = get(i, low);
      update(i, low, val);
      while (val--) Q.push_back({i + 1, low + 1});
    }
  }
  cout << Q.size() << "\n";
  for (auto pt : Q) cout << pt.first << " " << pt.second << "\n";
}
