#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int p[4 * maxn], a[maxn], mt[4 * maxn], n;
long long t[4 * maxn];
void push(int v, int l, int r) {
  if (p[v] != 0) {
    int m = (l + r) / 2;
    t[2 * v] += (m - l + 1) * p[v], mt[2 * v] += p[v];
    t[2 * v + 1] += (r - m) * p[v], mt[2 * v + 1] += p[v];
    p[2 * v] += p[v];
    p[2 * v + 1] += p[v];
    p[v] = 0;
  }
}
void build(int v = 1, int l = 0, int r = n - 1) {
  if (l == r)
    t[v] = a[l], mt[v] = a[l];
  else {
    int tm = (l + r) / 2;
    build(2 * v, l, tm);
    build(2 * v + 1, tm + 1, r);
    t[v] = t[2 * v] + t[2 * v + 1];
    mt[v] = min(mt[2 * v], mt[2 * v + 1]);
  }
}
void update(int l, int r, int v = 1, int tl = 0, int tr = n - 1) {
  if (l == tl && r == tr)
    t[v] -= tr - tl + 1, p[v] -= 1, mt[v] -= 1;
  else {
    push(v, tl, tr);
    int tm = (tl + tr) / 2;
    if (r <= tm)
      update(l, r, 2 * v, tl, tm);
    else if (l > tm)
      update(l, r, 2 * v + 1, tm + 1, tr);
    else {
      update(l, tm, 2 * v, tl, tm);
      update(tm + 1, r, 2 * v + 1, tm + 1, tr);
    }
    t[v] = t[2 * v] + t[2 * v + 1];
    mt[v] = min(mt[2 * v], mt[2 * v + 1]);
  }
}
long long get(int l, int r, int v = 1, int tl = 0, int tr = n - 1) {
  if (l == tl && r == tr)
    return t[v];
  else {
    int tm = (tl + tr) / 2;
    push(v, tl, tr);
    if (r <= tm)
      return get(l, r, 2 * v, tl, tm);
    else if (l > tm)
      return get(l, r, 2 * v + 1, tm + 1, tr);
    return get(l, tm, 2 * v, tl, tm) + get(tm + 1, r, 2 * v + 1, tm + 1, tr);
  }
}
int getm(int l, int r, int v = 1, int tl = 0, int tr = n - 1) {
  if (l == tl && r == tr)
    return mt[v];
  else {
    int tm = (tl + tr) / 2;
    push(v, tl, tr);
    if (r <= tm)
      return getm(l, r, 2 * v, tl, tm);
    else if (l > tm)
      return getm(l, r, 2 * v + 1, tm + 1, tr);
    return min(getm(l, tm, 2 * v, tl, tm),
               getm(tm + 1, r, 2 * v + 1, tm + 1, tr));
  }
}
int findl() {
  int l = 0, r = n - 1, m;
  while (l < r) {
    m = (l + r) / 2;
    if (get(0, m) <= 0)
      l = m + 1;
    else
      r = m;
  }
  if (get(0, l) > 0)
    return l;
  else
    return -1;
}
int findr(int st) {
  int l = st, r = n, m;
  while (l + 1 < r) {
    m = (l + r) / 2;
    if (getm(st, m) > 0)
      l = m;
    else
      r = m;
  }
  if (getm(st, l) > 0)
    return l;
  else
    return -1;
}
vector<pair<int, int> > ans;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  build();
  while (true) {
    int ll = findl();
    if (ll == -1) break;
    int rr = findr(ll);
    if (rr == -1) break;
    update(ll, rr);
    ans.push_back(make_pair(ll + 1, rr + 1));
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); ++i)
    cout << ans[i].first << ' ' << ans[i].second << endl;
  return 0;
}
