#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define el '\n'
#define ff first
#define ss second
#define pb push_back
#define point pair <ll, ll>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

const ll N = 1e6 + 10;
const ll inf = 1e18 + 10;

ll a[N], pref[N];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    ll n;
    cin >> n;

    ll total = 0;
    for (ll i = 1; i <= n; i++)
        cin >> a[i], total += a[i];

    total /= 3;
    for (ll i = 1; i <= n; i++)
        pref[i] = pref[i - 1] + a[i];

    auto get = [&](ll l, ll r) -> ll {
        if (l <= r)
            return pref[r] - pref[l - 1];
        return pref[n] - pref[l - 1] + pref[r];
    };

    ll y = 1, z = 1;
    for (ll i = 1; i <= n; i++) {
        y = max(i + 1, y);
        while (y <= n && get(i, y - 1) < total)
            y++;

        if (y == n)
            break;

        z = max(y + 1, z);
        while (z <= n && get(y, z - 1) < total)
            z++;

        if (get(i, y - 1) == total && get(y, z - 1) == total) {
            cout << 0 << el;
            cout << i << " " << y << " " << z << el;
            return 0;
        }
    }

    return 0;
}
