#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <limits.h>
#include <assert.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <bitset>
#include <vector>
using namespace std;

#define LL long long

#define fi first
#define se second
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(a,b) (((a)+(b))>>1)
#define maxx(a,b) ((a)<(b)?(b):(a))
#define minx(a,b) ((a)<(b)?(a):(b))
#define absx(a) ((a)<0?-(a):(a))
#define mk(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define itr iterator
#define lowbit(x) ((x)&-(x))

typedef unsigned LL ULL;
typedef unsigned uint;
typedef map<int,int> mii;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<LL,LL> pLL;

template< typename T > inline void read(T &x) {
    static bool fr_f; static char fr_ch;
    fr_f=0; x=0; fr_ch=getchar();
    while(fr_ch<'0' || fr_ch>'9') {if(fr_ch=='-') fr_f=1; fr_ch=getchar();}
    while(fr_ch>='0' && fr_ch<='9') {x=(x<<1)+(x<<3)+fr_ch-'0'; fr_ch=getchar();}
    if(fr_f) x=-x;
}

template< typename T > inline void Max(T &a, T b) {if(a<b) a=b;}
template< typename T > inline void Min(T &a, T b) {if(b<a) a=b;}
template< typename T > inline T Abs(T a) {if(a<0) return -a; else return a;}

const double pi   = acos(-1.0) ;
const int MOD     = (int)1e9+7 ;
const int INF     = (int)0x3f3f3f3f ;
const LL  LINF    = (LL)INF<<32|INF ;
const int SINF    = (uint)(-1)>>1 ;
const LL  SLINF   = (ULL)(-1)>>1 ;
const double DINF = 1e50 ;
const double eps  = 1e-8 ;
const int maxn    = (int) 200000+20 ;
const int maxm    = (int) 25000+20 ;
const int maxk    = (int) 1000+20 ;

inline int sig(double x) {return x<-eps?-1:x>eps;}
inline LL fp(LL a,LL n,LL p) {LL res=1; for(;n;n>>=1,a=a*a%p) if(n&1) res=res*a%p; return res;}
template<typename T>inline T gcd(T a,T b) {for(T c;b;c=a%b,a=b,b=c); return a;}

//--------------------start--------------------

int n;
LL a[55];

bool vis[55][55];
vector<pii> dp[55][55];
LL s[55][55][55];

bool can[55][55];

void DP(int l,int r)
{
    if(vis[l][r]) return ;
    vis[l][r]=1;

    int flag=1;
    for(int i=l+1;i<=r;i++) if(a[i-1]>a[i]) flag=0;

    if(flag)
    {
        for(int i=l;i<=r;i++) s[l][r][i]=a[i];
        can[l][r]=1;
        return ;
    }

    DP(l+1,r); DP(l,r-1);

    vector<pii> tmpL,tmpR;
    LL sl[55],sr[55];

    bool flagL=0, flagR=0;

    if(can[l+1][r])
    {
        sl[l]=a[l];
        for(int i=l+1;i<=r;i++) sl[i]=s[l+1][r][i];

        if(sl[l]<=sl[l+1])
        {
            flagL=1;
            tmpL=dp[l+1][r];
        }
        else if(sl[l]+sl[l+1]<=sl[l+1])
        {
            flagL=1;
            tmpL=dp[l+1][r];
            tmpL.pb(mk(l+1,l));
            sl[l]+=sl[l+1];
        }
        else if(sl[l]+sl[l+1]*2<=sl[l+1])
        {
            flagL=1;
            tmpL=dp[l+1][r];
            tmpL.pb(mk(l+1,l));
            tmpL.pb(mk(l+1,l));
            sl[l]+=sl[l+1]*2;
        }
    }

    if(can[l][r-1])
    {
        sr[r]=a[r];
        for(int i=l;i<=r-1;i++) sr[i]=s[l][r-1][i];

        if(sr[r-1]<=sr[r])
        {
            flagR=1;
            tmpR=dp[l][r-1];
        }
        else if(sr[r-1]<=sr[r]+sr[r-1])
        {
            flagR=1;
            tmpR=dp[l][r-1];
            tmpR.pb(mk(r-1,r));
            sr[r]+=sr[r-1];
        }
        else if(sr[r-1]<=sr[r]+sr[r-1]*2)
        {
            flagR=1;
            tmpR=dp[l][r-1];
            tmpR.pb(mk(r-1,r));
            tmpR.pb(mk(r-1,r));
            sr[r]+=sr[r-1]*2;
        }
    }

    can[l][r]=flagL|flagR;
    if(flagL && (!flagR || tmpL.size()<tmpR.size()))
    {
        for(int i=l;i<=r;i++) s[l][r][i]=sl[i];
        dp[l][r]=tmpL;
    }
    else
    {
        for(int i=l;i<=r;i++) s[l][r][i]=sr[i];
        dp[l][r]=tmpR;
    }
}

void work()
{
    read(n);
    for(int i=1;i<=n;i++) read(a[i]);

    DP(1,n);
    cout <<dp[1][n].size() <<endl;
    for(int i=0;i<dp[1][n].size();i++)
    {
        cout <<dp[1][n][i].fi <<" " <<dp[1][n][i].se <<endl;
    }
}

//---------------------end---------------------

int main()
{
#ifdef yukihana0416
freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
#endif // yukihana0416
    work();
    return 0;
}


Measured memory_bytes: 1408