#include <map>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define rg register
#define FILE "empodia"
using namespace std;
const int N = 1100010;
int n,A[N],sta[N],nxt_1[N],nxt_2[N],Ans,bin[N<<1],R[N];
vector<int>G[N];
inline int gi(){
rg int x=0,res=1;rg char ch=getchar();
while(ch<'0' || ch>'9'){if(ch=='-')res^=1;ch=getchar();}
while(ch>='0'&&ch<='9')x=x*10+ch-48,ch=getchar();
return res?x:-x;
}
inline void link(int u,int v){
G[u].push_back(v);
}
inline void getnxt_1(rg int tp=0){
sta[0]=n+1;
for(rg int i=n;i>=1;--i){
while(tp && A[sta[tp]]<A[i])tp--;
nxt_1[i]=sta[tp];sta[++tp]=i;
link(nxt_1[i],i);
}
}
inline void getnxt_2(rg int tp=0){
sta[0]=n+1;
for(rg int i=n;i>=1;--i){
while(tp && A[sta[tp]]>A[i])tp--;
nxt_2[i]=sta[tp];sta[++tp]=i;
}
}
inline void dfs(int x){
int g=A[x],qt=bin[g];
if(bin[g]<=nxt_2[x])R[x]=bin[g];
bin[g]=x;
for(int i=0,j=G[x].size();i<j;i++)
dfs(G[x][i]);
bin[g]=qt;
}
int main(){
freopen(FILE".in","r",stdin);
freopen(FILE".out","w",stdout);
n=gi();memset(bin,127,sizeof(bin));
for(rg int i=1;i<=n;++i)A[i]=gi()+1;
getnxt_1();getnxt_2();
memset(R,127,sizeof(R));
for(int i=1;i<=n;++i)A[i]=A[i]-i+n;
dfs(n);
for(int i=n,Mx=R[0];i>=1;--i){
if(R[i]>Mx)R[i]=R[0];
Mx=min(Mx,R[i]);
}
for(int i=1;i<=n;++i)if(R[i]<=n)Ans++;
printf("%d\n",Ans);
for(int i=1;i<=n;++i)
if(R[i]<=n)printf("%d %d\n",i,R[i]);
fclose(stdin);fclose(stdout);
return 0;
}