#include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Wshadow"
#pragma GCC diagnostic ignored "-Wsign-compare"
using namespace std;
const long long inf = 1e18 + 9;
const long long N = 1e6 + 5;
const long long mod = 1e9 + 7;
long long n, m, k = 0, t = 1, x, y, z, l, r, w, d, q, ct = 0, ans = 0, f = 0;
string s, p;
set<long long> si;
map<long long, long long> mi;
deque<pair<long long, long long> > val[100000 + 5];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cerr.tie(NULL);
  cin >> n;
  long long a[n + 1];
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    val[a[i]].push_back({i, i});
  }
  vector<pair<long long, long long> > ans;
  long long highest = *max_element(a + 1, a + n + 1);
  while (highest) {
    sort(val[highest].begin(), val[highest].end());
    if (val[highest].size() == 1) {
      val[highest - 1].push_back(
          {val[highest][0].first, val[highest][0].second});
      ans.push_back({val[highest][0].first, val[highest][0].second});
      highest--;
      continue;
    }
    long long f = 0;
    long long pehla, antim;
    for (auto i : val[highest]) {
      if (!f) {
        f = 1;
        pehla = i.first;
        antim = i.second;
        continue;
      }
      if (i.first - antim == 1) {
        antim = i.second;
      } else {
        ans.push_back({pehla, antim});
        val[highest - 1].push_back({pehla, antim});
        pehla = i.first;
        antim = i.second;
      }
    }
    ans.push_back({pehla, antim});
    val[highest - 1].push_back({pehla, antim});
    val[highest].clear();
    highest--;
  }
  cout << ans.size() << "\n";
  for (auto i : ans) {
    cout << i.first << " " << i.second << "\n";
  }
}
