#include <bits/stdc++.h>
#include <random>

using namespace std;

#define ll long long
#define endl '\n'
#define ld long double
#define pb push_back

const ll clasik = 7e5+7;
const ll INF = 1e17;
const ll mod = 1e9+7;
const ll mln = 1e6+111;

ll pref[2*mln];
ll df[mln];

ll okolo = 0;
vector <ll> v;

ll res = INF;
ll n;
ll res_ = 0 , res__ = 0 , res___ = 0;
void count2(ll l1 , ll r1 , ll l2 , ll r2 ) {
    //cout<<l1<<" "<<r1<<" "<<l2<<" "<<r2<<endl;
    if (r2+1 > n) return;
    if (r2+1 <= l2) return;
    ll s1 = pref[r1] - pref[l1-1];
    ll s2 = pref[r2] - pref[r1];
    ll s3 = pref[l1 - 1 + n] - pref[r2];
    
    if (res > max(s1 , max(s2 , s3)) - min(s1 , min(s2 , s3))) {
        res = max(s1 , max(s2 , s3)) - min(s1 , min(s2 , s3));
        res_ = l1;
        res__ = l2;
        res___ = r2+1;
    }
}

void count1(ll l , ll r) {
    
    ll sum = pref[r] - pref[l-1];

    ll p2 = lower_bound(v.begin() , v.end() , pref[r] + okolo) - v.begin();
    if (p2 == n) p2--;
    //cout<<"??"<<endl;

    //cout<<l<<" "<<r<<" "<<sum<<endl;

    count2(l , r , r+1 , p2+1);
    count2(l , r , r+1 , p2);

}

void solve() {



    cin>>n;

    bool ok = 0;

    for (int i = 1 ; i<=n ; i++) {
        cin>>df[i];
        if (df[i]!=1) {
            ok = 1;
        }
        pref[i] = pref[i-1] + df[i];
        v.pb(pref[i]);
    }

    for (int i = n+1 ; i<=2*n ; i++) {
        pref[i] = pref[i-1] + df[i - n];
        v.pb(pref[i]);
    }

    if (ok == 0) {
        
        okolo = pref[n]/3;
        if (pref[n]%3 == 2) okolo++;
        vector <ll> vv;
        vv.pb(1);
        ll cnt = 0;
        for (int i = 1 ; i<=n ; i++) {
            cnt+=df[i];
            if (cnt == okolo) {
                vv.pb(i+1);
                cnt = 0;
            }
        }

        ll s1 = pref[vv[1] - 1] - pref[0];
        ll s2 = pref[vv[2] - 1] - pref[vv[1]];
        ll s3 = pref[n] - s1 - s2;
        //cout<<s1<<" "<<s2<<" "<<s3<<endl;
        cout<<max(s1 , max(s2 , s3)) - min(s1 , min(s2 , s3))<<endl;
        cout<<vv[0]<<" "<<vv[1]<<" "<<vv[2]<<endl;

        return;
    }

    okolo = pref[n]/3;

    for (int i = 1 ; i<=n ; i++) {
        ll p1 = lower_bound(v.begin() , v.end() , okolo + pref[i-1]) - v.begin();
        if (p1 - i + 1 == n - 1) p1--;
        count1(i , p1+1);
        count1(i , p1);
    }

    cout<<res<<endl;
    cout<<res_<<" ";
    cout<<res__<<" ";
    cout<<res___<<" ";
    cout<<endl;

}

signed main() {
    
    int t = 1;

    //cin>>t;

    while(t--) solve();

    return 0;
}