#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
const long long N = 2e6 + 5;
const long long INF = 1e18L;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << ": " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
long long ar[N];
long long dp[N];
long long lseg[N], rseg[N];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long T = 1;
  while (T--) {
    long long n;
    cin >> n;
    for (long long i = 1; i <= n; i++) {
      cin >> ar[i];
    }
    long long op = 0;
    for (long long i = 0; i <= n; i++) {
      dp[i] = ar[i + 1] - ar[i];
      op += max(0ll, dp[i]);
    }
    long long l = 0, r = 0;
    cout << op << '\n';
    for (long long i = 0; i <= n; i++) {
      if (dp[i] > 0) {
        for (long long j = 0; j < dp[i]; j++) lseg[l++] = i + 1;
      } else {
        for (long long j = 0; j < -dp[i]; j++) rseg[r++] = i;
      }
    }
    for (long long i = 0; i < op; i++) {
      cout << lseg[i] << " " << rseg[i] << "\n";
    }
  }
  return 0;
}
