#include <bits/stdc++.h>
using namespace std;
int const N = 1e5 + 10;
int n, a[N];
vector<pair<int, int> > ans;
struct node {
  int menor, lazy;
} seg[4 * N];
void build(int idx, int i, int j) {
  if (i == j) {
    seg[idx].menor = a[i];
    return;
  }
  int mid = (i + j) >> 1;
  int left = idx << 1;
  int right = left | 1;
  build(left, i, mid);
  build(right, mid + 1, j);
  seg[idx].menor = min(seg[left].menor, seg[right].menor);
}
void refresh(int idx, int i, int j) {
  if (!seg[idx].lazy) return;
  int left = idx << 1;
  int right = left | 1;
  if (i != j) {
    seg[left].lazy += seg[idx].lazy;
    seg[right].lazy += seg[idx].lazy;
  }
  seg[idx].menor -= seg[idx].lazy;
  seg[idx].lazy = 0;
}
int get(int idx, int i, int j, int pos) {
  refresh(idx, i, j);
  if (i == j) return seg[idx].menor;
  int mid = (i + j) >> 1;
  int left = idx << 1;
  int right = left | 1;
  if (pos <= mid)
    return get(left, i, mid, pos);
  else
    return get(right, mid + 1, j, pos);
  seg[idx].menor = min(seg[left].menor, seg[right].menor);
}
void update(int idx, int i, int j, int ini, int fim) {
  refresh(idx, i, j);
  if (i > j || j < ini || fim < i) return;
  if (ini <= i && j <= fim) {
    seg[idx].lazy++;
    refresh(idx, i, j);
    return;
  }
  int mid = (i + j) >> 1;
  int left = idx << 1;
  int right = left | 1;
  update(left, i, mid, ini, fim);
  update(right, mid + 1, j, ini, fim);
  seg[idx].menor = min(seg[left].menor, seg[right].menor);
}
int find(int idx, int i, int j, int pos) {
  refresh(idx, i, j);
  if (j < pos || seg[idx].menor != 0) return -1;
  if (i == j) return i;
  int mid = (i + j) >> 1;
  int left = idx << 1;
  int right = left | 1;
  int ret = -1;
  ret = find(left, i, mid, pos);
  if (ret != -1) return ret;
  ret = find(right, mid + 1, j, pos);
  return ret;
}
void solve() {
  build(1, 1, n + 1);
  for (int i = 1; i <= n; i++) {
    int A = get(1, 1, n + 1, i);
    while (A > 0) {
      A--;
      int pos = find(1, 1, n + 1, i);
      if (pos == -1)
        pos = i;
      else
        pos = pos - 1;
      ans.push_back(pair<int, int>(i, pos));
      update(1, 1, n + 1, i, pos);
    }
  }
  printf("%d\n", (int)(ans.size()));
  for (int i = 0; i < (int)(ans.size()); i++)
    printf("%d %d\n", ans[i].first, ans[i].second);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  solve();
  return 0;
}
