Problem:
Score : 700 points

Problem Statement

You have an integer sequence of length N: a_1, a_2, ..., a_N.

You repeatedly perform the following operation until the length of the sequence becomes 1:

First, choose an element of the sequence.

If that element is at either end of the sequence, delete the element.

If that element is not at either end of the sequence, replace the element with the sum of the two elements that are adjacent to it. Then, delete those two elements.

You would like to maximize the final element that remains in the sequence.

Find the maximum possible value of the final element, and the way to achieve it.

Constraints

All input values are integers.

2 \leq N \leq 1000

|a_i| \leq 10^9

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

In the first line, print the maximum possible value of the final element in the sequence.

In the second line, print the number of operations that you perform.

In the (2+i)-th line, if the element chosen in the i-th operation is the x-th element from the left in the sequence at that moment, print x.

If there are multiple ways to achieve the maximum value of the final element, any of them may be printed.

Sample Input 1

5
1 4 3 7 5

Sample Output 1

11
3
1
4
2

The sequence would change as follows:

After the first operation: 4, 3, 7, 5

After the second operation: 4, 3, 7

After the third operation: 11(4+7)

Sample Input 2

4
100 100 -1 100

Sample Output 2

200
2
3
1

After the first operation: 100, 200(100+100)

After the second operation: 200

Sample Input 3

6
-1 -2 -3 1 2 3

Sample Output 3

4
3
2
1
2

After the first operation: -4, 1, 2, 3

After the second operation: 1, 2, 3

After the third operation: 4

Sample Input 4

9
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

Sample Output 4

5000000000
4
2
2
2
2

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>

using namespace std;
#define rep(i, n) for(int i = 0 ; i < (int)(n) ; i++)
typedef long long ll;
typedef long double Double;

vector<ll> A;

ll naiveDp[1024][1024][4];
bool naiveF[1024][1024][4];

int BOTH = 0;
int LEFT = 1;
int RIGHT = 2;
int NONE = 3;

ll naive(int l, int r, int flg) {
    if (l + 1 == r) return A[l];
    if (naiveF[l][r][flg]) return naiveDp[l][r][flg];

    ll ans = (ll) -1e18;
    if (!(flg & RIGHT)) ans = max(ans, naive(l + 1, r, flg));
    if (!(flg & LEFT)) ans = max(ans, naive(l, r - 1, flg));

    for (int i = l + 1; i + 1 < r; i++) {
        ans = max(ans, naive(l, i, flg | LEFT) + naive(i + 1, r, flg | RIGHT));
    }
    naiveF[l][r][flg] = true;
    return naiveDp[l][r][flg] = ans;

    assert(0);
}


ll dp[1024][1024][4];
int best[1024][1024][4];

bool f[1024][1024][4];

ll dfs(int l, int r, int flg) {
    if (l + 1 == r) {
        best[l][r][flg] = l;
        return A[l];
    }
    if (f[l][r][flg]) return dp[l][r][flg];

    ll ans = (ll) -1e18;
    int ptr = -1;
    if (!(flg & RIGHT)) {
        if (ans < dfs(l + 1, r, flg)) {
            ans = dfs(l + 1, r, flg);
            ptr = best[l + 1][r][flg];
        }
    }

    if (!(flg & LEFT)) {
        if (ans < dfs(l, r - 1, flg)) {
            ans = dfs(l, r - 1, flg);
            ptr = best[l][r - 1][flg];
        }
    }

    if (l + 2 < r) { // length >= 3
        dfs(l, r - 1, flg);
        dfs(l + 1, r, flg);

        int le = max(l + 1, best[l][r - 1][flg] - 1);
        int ri = min(best[l + 1][r][flg] + 1, r - 2);
        for (int i = le; i <= ri; i++) {
            ll cost = dfs(l, i, flg | LEFT) + dfs(i + 1, r, flg | RIGHT);
            if (ans < cost) {
                ans = cost;
                ptr = i;
            }
        }
    }


    f[l][r][flg] = true;
    best[l][r][flg] = ptr;
    return dp[l][r][flg] = ans;
}

vector<int> ops;

void recover(int l, int r, int flg) {
    if (l + 1 == r) {
        return;
    }

    ll ans = dfs(l, r, flg);
    if (!(flg & RIGHT)) {
        if (ans == dfs(l + 1, r, flg)) {
            ops.push_back(l);
            recover(l + 1, r, flg);
            return;
        }
    }

    if (!(flg & LEFT)) {
        if (ans == dfs(l, r - 1, flg)) {
            ops.push_back(r - 1);
            recover(l, r - 1, flg);
            return;
        }
    }

    if (l + 2 < r) { // length >= 3
        dfs(l, r - 1, flg);
        dfs(l + 1, r, flg);

        int le = max(l + 1, best[l][r - 1][flg] - 1);
        int ri = min(best[l + 1][r][flg] + 1, r - 2);
        for (int i = le; i <= ri; i++) {
            ll cost = dfs(l, i, flg | LEFT) + dfs(i + 1, r, flg | RIGHT);
            if (ans == cost) {
                recover(l, i, flg | LEFT);
                recover(i + 1, r, flg | RIGHT);
                ops.push_back(i);
                return;
            }
        }
    }
}


map<vector<ll>, int> hoge;

vector<ll> op(vector<ll> v, int i) {
    --i;
    if (v.size() == i + 1 || i == 0)
        v.erase(v.begin() + i);
    else {
        v[i] = v[i - 1] + v[i + 1];
        v.erase(v.begin() + i + 1);
        v.erase(v.begin() + i - 1);
    }
    return v;
}

ll veryNaive(vector<ll> a) {
    if (hoge.count(a)) {
        return hoge[a];
    }
    if (a.size() == 1) return a[0];
    vector<ll> b;
    ll ans = -1e18;
    {
        b = a;
        b.erase(b.begin());
        ans = max(ans, veryNaive(b));
    }

    {
        b = a;
        b.pop_back();
        ans = max(ans, veryNaive(b));
    }

    for (int i = 1; i + 1 < a.size(); i++) {
        b = a;
        b[i] = a[i - 1] + a[i + 1];
        b.erase(b.begin() + i + 1);
        b.erase(b.begin() + i - 1);
        ans = max(ans, veryNaive(b));
    }
    hoge[b] = ans;
    return ans;
}


void solve(ll N, vector<ll> a) {
    memset(f, 0, sizeof(f));
    memset(naiveF, 0, sizeof(naiveF));
    A = a;
    hoge.clear();
    ops.clear();
    recover(0, N, BOTH);
    cout << dfs(0, N, BOTH) << endl;
    set<int> wow;
    cout << ops.size() << endl;
    for (int i = 0; i < N; i++) wow.insert(i);
//    vector<int> wahaha;
    for (auto i : ops) {
        int k = 0;
        for (auto j : wow) if (j <= i) k++;
        cout << k << endl;
//        wahaha.push_back(k);
        wow.erase(i);
    }

//    for (auto ap : wahaha) {
//        a = op(a, ap);
//    }
//    cout << "confirm" << " ";
//    for (auto i : a) cout << i << " ";
//    cout << endl;

//    if (dfs(0, N, BOTH) != naive(0, N, BOTH)) {
//        cout << dfs(0, N, BOTH) << " " << veryNaive(a) << " " << naive(0, N, BOTH) << endl;
//    }
}

int main() {
    ll N;
    scanf("%lld", &N);
//    N = 10;
//    while (true) {
    vector<ll> a(N - 1 + 1);
    for (int i = 0; i <= N - 1; i++) {
        scanf("%lld", &a[i]);
//        a[i] = rand() % 100;
    }
    solve(N, a);

//    return 0;
}