#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const double pi = acos(-1);
void print() { cout << '\n'; }
template <typename T, typename... Params>
void print(const T& var1, const Params&... var2) {
  cout << var1 << ' ';
  print(var2...);
}
template <typename T>
void pr(const T& v) {
  for (auto c : v) cout << c << ' ';
  cout << '\n';
}
long long int power(long long int a, long long int b, long long int p) {
  if (b == 0) return 1;
  long long int c = power(a, b / 2, p);
  if (b % 2 == 0)
    return (c * c) % p;
  else
    return (((c * c) % p) * a) % p;
}
long long int invmod(long long int n, long long int p) {
  return power(n, p - 2, p);
}
bool isPrime(long long int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (long long int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
const int maxN = 100001;
int tree[4 * maxN][2];
int A[100000], n;
void build(int node, int start, int end) {
  if (start == end)
    tree[node][0] = A[start], tree[node][1] = start;
  else {
    int mid = (start + end) / 2;
    build(2 * node, start, mid);
    build(2 * node + 1, mid + 1, end);
    tree[node][0] = min(tree[2 * node][0], tree[2 * node + 1][0]);
    if (tree[2 * node][0] < tree[2 * node + 1][0])
      tree[node][1] = tree[2 * node][1];
    else
      tree[node][1] = tree[2 * node + 1][1];
  }
}
pair<int, int> query(int node, int start, int end, int l, int r) {
  if (r < start or end < l) {
    return {1e9, 1e9};
  }
  if (l <= start and end <= r) {
    return make_pair(tree[node][0], tree[node][1]);
  }
  int mid = (start + end) / 2;
  pair<int, int> p1 = query(2 * node, start, mid, l, r);
  pair<int, int> p2 = query(2 * node + 1, mid + 1, end, l, r);
  if (p1.first < p2.first)
    return p1;
  else
    return p2;
}
vector<pair<int, int> > v;
int count(int l, int r, int val) {
  if (l > r) return 0;
  pair<int, int> q = query(1, 0, n - 1, l, r);
  int mini = q.first;
  int idx = q.second;
  mini -= val;
  for (long long int i = 0; i < mini; i++) v.push_back({l + 1, r + 1});
  return (mini + count(l, idx - 1, val + mini) + count(idx + 1, r, val + mini));
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (long long int i = 0; i < n; i++) cin >> A[i];
  build(1, 0, n - 1);
  print(count(0, n - 1, 0));
  for (long long int i = 0; i < ((long long int)(v).size()); i++)
    print(v[i].first, v[i].second);
  return 0;
}
