#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "]"; return os; }


// import here

int main(){
    LL n;
    cin >> n;
    vector<LL> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    vector<vector<LL>> memo(5, vector<LL>(n+1, -10000000000000LL));
    memo[0][0] = 0;
    vector<vector<LL>> ref(5, vector<LL>(n+1));

    for(int i = 0; i < n; ++i){
        // erase head
        memo[0][i+1] = 0;
        ref [0][i+1] = 0;

        // not erase a[i]
        memo[1][i+1] = memo[0][i] + a[i];
        ref [1][i+1] = 0;
        if(memo[1][i+1] < memo[2][i] + a[i]){
            memo[1][i+1] = memo[2][i] + a[i];
            ref [1][i+1] = 2;
        }

        // erase seq odd
        memo[2][i+1] = memo[1][i];
        ref [2][i+1] = 1;
        if(memo[2][i+1] < memo[3][i]){
            memo[2][i+1] = memo[3][i];
            ref [2][i+1] = 3;
        }

        // erase seq even
        memo[3][i+1] = memo[2][i];
        ref [3][i+1] = 2;

        // erase tail
        memo[4][i+1] = memo[1][i];
        ref [4][i+1] = 1;
        if(memo[4][i+1] < memo[4][i]){
            memo[4][i+1] = memo[4][i];
            ref [4][i+1] = 4;
        }
    }
    LL ans = memo[1][n];
    LL cur = 1;
    if(ans < memo[4][n]){
        ans = memo[4][n];
        cur = 4;
    }

/*
    for(int i = 0; i <=4; ++i){
        cout << memo[i] << endl;
    }
    for(int i = 0; i <=4; ++i){
        cout << ref[i] << endl;
    }
    */

    cout << ans << endl;
    vector<LL> flags(n);
    LL begin = 0;
    LL end = n;

    for(int i = n; i > 0; --i){
        //cerr << i << " : cur=" << cur << endl;
        if(cur != 1){
            flags[i-1] = 1;
        }
        if(cur == 0) begin++;
        if(cur == 4) end--;
        cur = ref[cur][i];
    }

/*
    for(int i = 0; i < n; ++i){
        cerr << flags[i];
    }
    cerr << endl;
    */

    cerr << "head=" << begin << endl;
    cerr << "tail=" << n - end << endl;
    vector<LL> res;
    for(int i = n-1; i >= end; --i){
        res.push_back(i+1);
    }
    for(LL i = end-1; i >= begin; --i){
        LL len = 0;
        while(i >= begin && flags[i]){
            len++;
            --i;
        }
        while(len > 0){
            if(len > 1){
                len -= 2;
                res.push_back(i+3);
            }else{
                --len;
                res.push_back(i+2);
            }
        }
    }
    for(LL i = 0; i < begin; ++i){
        res.push_back(1);
    }
    cout << res.size() << endl;
    for(LL v: res){
        cout << v << endl;
    }

    return 0;
}



Measured memory_bytes: 384