#include <bits/stdc++.h>
using namespace std;
int A[100002], tree[100002 * 3], n;
void init(int n, int i, int j) {
  if (i == j) {
    tree[n] = i;
    return;
  }
  init(n << 1, i, (i + j) >> 1);
  init((n << 1) + 1, ((i + j) >> 1) + 1, j);
  int vl = tree[n << 1], vr = tree[(n << 1) + 1];
  if (A[vl] <= A[vr])
    tree[n] = vl;
  else
    tree[n] = vr;
}
int query(int n, int i, int j, int b, int e) {
  if (i > e || j < b) return -1;
  if (i >= b && j <= e) return tree[n];
  int p1 = query(n << 1, i, (i + j) >> 1, b, e);
  int p2 = query((n << 1) + 1, ((i + j) >> 1) + 1, j, b, e);
  if (p1 == -1) return p2;
  if (p2 == -1) return p1;
  if (A[p1] < A[p2]) return p1;
  return p2;
}
void call(int i, int j, int now, vector<pair<int, int> > &ans) {
  if (i > j) return;
  int idx = query(1, 0, n - 1, i, j);
  int v = A[idx] - now;
  call(i, idx - 1, now + v, ans);
  call(idx + 1, j, now + v, ans);
  for (__typeof(v) ii = 0; ii < (v); ii++) ans.push_back(make_pair(i, j));
}
int main() {
  cin >> n;
  for (__typeof(n) i = 0; i < (n); i++) cin >> A[i];
  init(1, 0, n - 1);
  vector<pair<int, int> > ans;
  call(0, n - 1, 0, ans);
  cout << ((int)ans.size()) << endl;
  for (__typeof(((int)ans.size())) i = 0; i < (((int)ans.size())); i++)
    cout << ans[i].first + 1 << " " << ans[i].second + 1 << endl;
  return 0;
}
