#include <bits/stdc++.h>
const int maxn = 100020, INF = 1 << 29;
int n;
struct rec {
  int n, x;
} a[maxn];
int al[maxn], ar[maxn];
struct SBT {
  int root, tot;
  int d[maxn], l[maxn], r[maxn], s[maxn];
  SBT() { s[0] = root = tot = 0; }
  void prt(int x, int *a, int &w) {
    if (!x) return;
    prt(l[x], a, w);
    for (int i = 1; i <= w; ++i) a[++a[0]] = d[x];
    prt(r[x], a, w);
  }
  void print(int *a, int w) { prt(root, a, w); }
  void tl(int &x) {
    int y = r[x];
    r[x] = l[y];
    l[y] = x;
    s[y] = s[x];
    s[x] = s[l[x]] + s[r[x]] + 1;
    x = y;
  }
  void tr(int &x) {
    int y = l[x];
    l[x] = r[y];
    r[y] = x;
    s[y] = s[x];
    s[x] = s[l[x]] + s[r[x]] + 1;
    x = y;
  }
  void mt(int &x, bool w) {
    if (!w) {
      if (s[l[l[x]]] > s[r[x]])
        tr(x);
      else if (s[r[l[x]]] > s[r[x]]) {
        tl(l[x]);
        tr(x);
      } else
        return;
    } else {
      if (s[r[r[x]]] > s[l[x]])
        tl(x);
      else if (s[l[r[x]]] > s[l[x]]) {
        tr(r[x]);
        tl(x);
      } else
        return;
    }
    mt(l[x], false);
    mt(r[x], true);
    mt(x, false);
    mt(x, true);
  }
  void ist(int &x, int w) {
    if (!x) {
      x = ++tot;
      s[x] = 1;
      d[x] = w;
      l[x] = r[x] = 0;
    } else {
      ++s[x];
      if (w < d[x])
        ist(l[x], w);
      else
        ist(r[x], w);
      mt(x, w >= d[x]);
    }
  }
  int dl(int &x, int w) {
    --s[x];
    if ((d[x] == w) || ((w < d[x]) && (!l[x])) || ((w > d[x]) && (!r[x]))) {
      int tmp = d[x];
      if ((!l[x]) || (!r[x]))
        x = l[x] + r[x];
      else
        d[x] = dl(l[x], d[x] + 1);
      return tmp;
    } else if (w < d[x])
      return dl(l[x], w);
    else
      return dl(r[x], w);
  }
  int getpre(int w) {
    int t = root, last = -INF;
    while (t) {
      if (d[t] < w && d[t] > last) last = d[t];
      t = (w <= d[t]) ? l[t] : r[t];
    }
    return last;
  }
  int getsuc(int w) {
    int t = root, last = INF;
    while (t) {
      if (d[t] > w && d[t] < last) last = d[t];
      t = (w < d[t]) ? l[t] : r[t];
    }
    return last;
  }
  int select(int k) {
    int t = root;
    while (t) {
      if (s[l[t]] + 1 == k) return d[t];
      if (k > s[l[t]] + 1) {
        k = k - s[l[t]] - 1;
        t = r[t];
      } else
        t = l[t];
    }
  }
  void delet(int w) { dl(root, w); }
  void insert(int w) { ist(root, w); }
  int size() { return s[root]; }
};
SBT left, right;
inline bool cmp(const rec &a, const rec &b) { return a.x > b.x; }
int main() {
  int i, l, r, tl, tr, ts, ans, w;
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) {
    a[i].n = i;
    scanf("%d", &a[i].x);
  }
  std::sort(a + 1, a + n + 1, cmp);
  l = 1;
  ans = al[0] = ar[0] = 0;
  while (l <= n) {
    for (r = l; r < n && a[r + 1].x == a[l].x;) ++r;
    for (i = l; i <= r; ++i) {
      w = a[i].n;
      tr = right.getpre(w);
      tl = left.getsuc(w);
      if (tr + 1 == w) {
        if (tl - 1 == w) {
          right.delet(tr);
          left.delet(tl);
        } else {
          right.delet(tr);
          right.insert(w);
        }
      } else {
        if (tl - 1 == w) {
          left.delet(tl);
          left.insert(w);
        } else {
          right.insert(w);
          left.insert(w);
        }
      }
    }
    ts = (r == n) ? a[r].x : (a[r].x - a[r + 1].x);
    left.print(al, ts);
    right.print(ar, ts);
    l = r + 1;
  }
  ans = al[0];
  printf("%d\n", ans);
  for (i = 1; i <= ans; ++i) printf("%d %d\n", al[i], ar[i]);
  return 0;
}
