#include <bits/stdc++.h>

using namespace std;

#define el '\n'
#define ll long long
#define ld long double
#define pll pair<ll, ll>
#define ppll pair<pll, ll>
#define ff first
#define ss second
#define all(x)  x.begin(), x.end()
#define pb push_back

const ll DIM = 1e6 + 7;
const ll INF = 1e18;

ll sum[DIM], a[DIM];

void solve () {

    ll n;
    cin >> n;

    ll case2 = 1;
    for (int i=1; i<=n; i++) {
        cin >> a[i];
        sum[i] = sum[i-1] + a[i];

        if (a[i] >  1) case2 = 0;
    }

    if (case2) {
        if (sum[n]%3 == 0) {
            cout << 0 << el << 1 << " ";

            ll s = sum[n]/3;
            ll y;
            ll cur = 0;
            for (y = 2; y<n; y++) {
                cur += a[y-1];
                if (cur >= s) {
                    cout << y << " ";
                    break;
                }
            }


            cur = 0;
            for (int z = y+1; z<=n; z++) {
                cur += a[z-1];
                if (cur >= s) {
                    cout << z << " ";
                    break;
                }
            }
        }

        else if (sum[n] % 3 == 1) {
            cout << 1 << el << 1 << " ";

            ll s = sum[n]/3;
            ll y;
            ll cur = 0;
            for (y = 2; y<n; y++) {
                cur += a[y-1];
                if (cur >= s) {
                    cout << y << " ";
                    break;
                }
            }


            cur = 0;
            for (int z = y+1; z<=n; z++) {
                cur += a[z-1];
                if (cur >= s) {
                    cout << z << " ";
                    break;
                }
            }
        }
        else {
            cout << 1 << el << 1 << " ";

            ll s = sum[n]/3;
            ll y;
            ll cur = 0;
            for (y = 2; y<n; y++) {
                cur += a[y-1];
                if (cur > s) {
                    cout << y << " ";
                    break;
                }
            }


            cur = 0;
            for (int z = y+1; z<=n; z++) {
                cur += a[z-1];
                if (cur > s) {
                    cout << z << " ";
                    break;
                }
            }
        }
    }

    else if (n <= 5000) {
        ll mn = INF, rx, ry, rz;
        for (int x=1; x<=n; x++) {
            for (int z=x+2; z<=n; z++) {
                ll sum1, sum2, sum3;

                sum3 = sum[n] - sum[z-1] + sum[x-1];

                ll y = upper_bound(sum+1+x, sum+1+(z-1), sum[x-1] + sum3) - sum;

                //cout << "/" << x << " " << y << " " << z << el;

                sum1 = sum[y-1] - sum[x-1];
                sum2 = sum[z-1] - sum[y-1];

                ll cur = max({sum1, sum2, sum3}) - min({sum1, sum2, sum3});
                if (cur < mn) {
                    mn = cur;

                    rx = x;
                    ry = y;
                    rz = z;
                }

                y--;

                sum1 = sum[y-1] - sum[x-1];
                sum2 = sum[z-1] - sum[y-1];

                cur = max({sum1, sum2, sum3}) - min({sum1, sum2, sum3});
                if (cur < mn) {
                    mn = cur;

                    rx = x;
                    ry = y;
                    rz = z;
                }

                y += 2;
                sum1 = sum[y-1] - sum[x-1];
                sum2 = sum[z-1] - sum[y-1];

                cur = max({sum1, sum2, sum3}) - min({sum1, sum2, sum3});
                if (cur < mn) {
                    mn = cur;

                    rx = x;
                    ry = y;
                    rz = z;
                }

            }
        }
        cout << mn << el << rx << " " << ry << " " << rz << el;
    }
    else {
        cout << 0 << el;

        ll s = sum[n]/3;


        ll rx, ry, rz;
        ll it = 0;
        for (int i = 1; i <= n; i++) {

            while (it < i && sum[it+1] < sum[i] - s) {
                it++;
            }

            if (sum[it] ==  sum[i] - s) {
                rx = it + 1;
                ry = i + 1;

                break;
            }


        }

        for (int z=ry+1; z <= n; z++) {
            if (sum[z-1] - sum[ry-1] == s) {
                rz = z;
                break;
            }
        }

        cout << rx << " " << ry << " " << rz << el;


    }




}

int main()
{

    ll ntest = 1;
    //cin >> ntest;
    while (ntest--) {
        solve();
    }


    return 0;
}
