#include <bits/stdc++.h>

using namespace std;
#define int long long
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define FORd(i, a, b) for(int i = b-1; i>=a; --i)
#define fr first
#define sd second
#define vii vector<int>
#define pii pair<int, int>
#define vpii vector<pii>
#define pr(s) cout << s << endl
#define pr2(s, q) cout << s << ' ' << q << endl
#define pr3(s, q, r) cout << s << ' ' << q << ' ' << r << endl
#define fl(s) cout << s << ' '
#define fl2(s, q) cout << s << ' ' << q << ' '
#define fl3(s, q, r) cout << s << ' ' << q << ' ' << r << ' '
//#define endl '\n'
#define all(A) A.begin(), A.end()
#define rall(A) A.begin(), A.end()
#define bub(A) sort(all(A))
#define rbub(A) sort(rall(A))
#define pb push_back
#define ins insert
#define ppb pop_back
#define INF 100000000001ll
const int nmax = 3000007;
int n, a[nmax], p[nmax], pT[nmax], s, aT[nmax];
int a1[nmax], a2[nmax], a1T[nmax], a2T[nmax], res = INF;
int sum(int a, int d){
    return p[a+d] - p[a-1];
}
int sumT(int a, int d){
    return pT[a+d] - pT[a-1];
}
int SUM(int a, int b){
    return p[b] - p[a-1];
}
int SUMT(int a, int b){
    return pT[b] - pT[a];
}
int ans[3], tmp[3];
void solve(){
    cin >> n;
    FOR(i, 1, n+1){
        cin >> a[i];
        a[i + n] = a[i];
        a[i + 2*n] = a[i];
        aT[n+1-i] = a[i];
        aT[2*n+1-i] = a[i];
        aT[3*n+1-i] = a[i];
        s += a[i];
        p[i] = p[i-1] + a[i];
    }
    FOR(i, n+1, 3*n + 1){
        p[i] = p[i-1] + a[i];
    }
    FOR(i, 1, 3*n+1){
        pT[i] = pT[i-1] + aT[i];
    }
    FOR(i, n+1, 2*n+1){
        int l = 0, r = n - 1;
        while(l < r){
            int m = (l+r) >> 1;
            if(sum(i, m) >= s/3){
                r = m;
            }
            else{
                l = m + 1;
            }
        }
        a1[i] = l;
        a1[i-n] = l;
        a1[i+n] = l;
        int L = 0, R = n-1;
        while(L < R){
            int M = (L+R+1) >> 1;
            if(sum(i, M) <= s/3){
                L = M;
            }
            else{
                R = M - 1;
            }
        }
        a2[i] = L;
        a2[i-n] = L;
        a2[i+n] = L;
        //pr2(a1[i], a2[i]);
    }
    FOR(i, n+1, 2*n+1){
        int l = 0, r = n - 1;
        while(l < r){
            int m = (l+r) >> 1;
            if(sumT(i, m) >= s/3){
                r = m;
            }
            else{
                l = m + 1;
            }
        }
        a1T[i] = l;
        a1T[i-n] = l;
        a1T[i+n] = l;
        int L = 0, R = n-1;
        while(L < R){
            int M = (L+R+1) >> 1;
            if(sumT(i, M) <= s/3){
                L = M;
            }
            else{
                R = M - 1;
            }
        }
        a2T[i] = L;
        a2T[i-n] = L;
        a2T[i+n] = L;
        //pr2(a1T[i], a2T[i]);

    }
    FOR(i, n+1, 2*n+1){
        tmp[0] = i;
        tmp[1] = i + a1[i] + 1;
        tmp[2] = n + i - a2T[3*n+2-i] - 1;
        int sr = sum(i, a1[i]);
        int sl = sumT((3*n+2-i), a2T[(3*n+2-i)]);
        int sm = s - sr - sl;
        int k, m;
        if(sm == 0) continue;
        //pr3(i, sl, sr);
        if(sr < sm){
            int l = 0, r = n-1;
            while(l<r){
                m = (l+r) >> 1;
                k = 2*sum(i + a1[i] + 1, m);
                if(sr + k > sm){
                    r = m;
                }
                else{
                    l = m + 1;
                }
            }
            tmp[1] += l + 1;
            sr += sum(i + a1[i] + 1, l);
        }
        if(sl > sm){
            int l = 0, r = n-1;
            while(l<r){
                m = (l+r) >> 1;
                k = 2*sum(n + i - a2T[3*n+2-i] - 1, m);
                if(sm + k > sl){
                    r = m;
                }
                else{
                    l = m + 1;
                }
            }
            tmp[2] += l + 1;
            sl -= sum(n + i - a2T[3*n+2-i] - 1, m);
        }
        //pr3(i, sl, sr);
        if(sr - sl < res){
            res = sr - sl;
            ans[0] = tmp[0]%n;
            ans[1] = tmp[1]%n;
            ans[2] = tmp[2]%n;
        }
    }
    ////////////////////////////////
    FOR(i, n+1, 2*n+1){
        tmp[0] = i;
        tmp[1] = i + a2[i] + 1;
        tmp[2] = n + i - a1T[3*n+2-i] - 1;
        int sr = sum(i, a2[i]);
        int sl = sumT((3*n+2-i), a1T[(3*n+2-i)]);
        int sm = s - sr - sl;
        int k, m;
        if(sm == 0) continue;
        //pr3(i, sl, sr);
        if(sr > sm){
            int l = 0, r = n-1;
            while(l<r){
                m = (l+r) >> 1;
                k = 2*sumT(3*n + 1 - i - a2[i], m);
                if(sm + k > sr){
                    r = m;
                }
                else{
                    l = m + 1;
                }
            }
            tmp[1] -= l + 1;
            sr -= sumT(3*n + 1 - i - a2[i], m);
        }
        if(sl < sm){
            int l = 0, r = n-1;
            while(l<r){
                m = (l+r) >> 1;
                k = 2*sumT(2*n + 2 - i + a1T[3*n+2-i] + 1, m);
                if(sl + k > sm){
                    r = m;
                }
                else{
                    l = m + 1;
                }
            }
            tmp[2] -= l + 1;
            sl += sumT(2*n + 2 - i + a1T[3*n+2-i] + 1, m);
        }
        //pr3(i, sl, sr);
        if(sl - sr < res){
            res = sl - sr;
            ans[0] = tmp[0]%n;
            ans[1] = tmp[1]%n;
            ans[2] = tmp[2] % n;
        }
    }
    FOR(i, 0, 3){
        if(ans[i] == 0){ans[i] += n;}
    }
    sort(ans, ans+3);
    pr(res);
    FOR(i, 0, 3) fl(ans[i]);

}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int ttt = 1;
   // cin >> ttt;
   // freopen("input.txt" , "r", stdin);

    while(ttt--) {solve();}
    return 0;
}
