#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
using namespace std;

int main()
{
    int n;
    cin >> n;

    vector<int> A(n);

    int mx = 0;
    int mn = INT_MAX;
    int count1 = 0;

    long long total = 0;

    for (int i=0; i<n; i++)
    {
        cin >> A[i];
        mx = max(mx, A[i]);
        mn = min(mn, A[i]);
    
        if (A[i] == 1) count1++;
        
        total += A[i];
    }

    if (n == 3)
    {
        long long delta = mx - mn;
        cout << delta << endl << "1 2 3\n";
        return 0;
    }

    if (mx <= 1)
    {
        int x=1, y=-1, z=-1;
        
        int a, b, c;
        if (count1%3 == 0)
        {
            a = count1/3;
            b = a;
            c = a;
        }
        else if (count1%3 == 1)
        {
            a = count1/3;
            b = a;
            c = a+1;
        }
        else if (count1%3 == 2)
        {
            a = count1/3;
            b = a+1;
            c = a+1;
        }

        if (A[0] == 1) a--;
        for (int i=1; i<n; i++)
        {
            if (y == -1)
            {
                if (a <= 0)
                {
                    y = i+1;
                }
            }
            else if (z == -1)
            {
                if (b <= 0)
                {
                    z = i+1;
                    break;
                }
            }

            if (A[i] == 1)
            {
                if (y == -1) a--;
                else if (z == -1) b--;
            }
        }
        if (z == -1) z = n;

        cout << (count1%3 == 0 ? 0 : 1) << endl;
        cout << x << ' ' << y << ' ' << z << endl;
    }

    if (total%3 == 0)
    {
        int x=0, y=0, z=0;

        long long group = total/3;

        map<long long, int> pref;
        map<long long, int> pref2;

        bool findSecond=0;

        long long cur = 0;
        long long prev_cur = 0;
        long long redundant = 0;
        for (int i=0; i<n; i++)
        {
            cur += A[i];
            
            if (cur == group)
            {
                if (findSecond == 0)
                {
                    x = 1;
                    y = i+2;
                    prev_cur = cur;
                    cur = 0;
                    findSecond = 1;
                }
                else
                {
                    z = i+2;
                    break;
                }
            }
            if (cur > group)
            {
                redundant = cur - group;

                if (findSecond == 0)
                {
                    auto iter = pref.find(redundant);
                    if (iter != pref.end())
                    {
                        x = iter->second+2;
                        y = i+2;
                        prev_cur = cur;
                        cur = 0;
                        findSecond = 1;
                    }
                }
                // else
                // {
                //     if (pref2.find(redundant) != pref2.end())
                //     {
                //         z = i;
                //         break;
                //     }
                // }
            }

            if (findSecond == 0)
                pref.insert({cur, i});
            // else
            //     pref2.insert({cur, i});

            if (i == n-1)
            {
                if (findSecond)
                {
                    i = y-2;
                    x = 0;
                    y = 0;
                    findSecond = 0;
                    cur = prev_cur;
                    prev_cur = 0;
                    pref.insert({prev_cur, i});
                    // pref2.clear();
                }
                else
                {
                    break;
                }
            }
        }

        cout << "0\n" << x << ' ' << y << ' ' << z << endl;
    }

}