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)

// includes
#include <bits/stdc++.h>

// macros
#define ll long long int
#define pb emplace_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(st, itr) for(auto itr = (st).begin(); itr != (st).end(); ++itr)
#define vrep(v, i) for(int i = 0; i < (v).size(); i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define FI first
#define SE second
#define dump(a, n) for(int i = 0; i < n; i++)cout << a[i] << "\n "[i + 1 != n];
#define dump2(a, n, m) for(int i = 0; i < n; i++)for(int j = 0; j < m; j++)cout << a[i][j] << "\n "[j + 1 != m];
using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef complex<double> cd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;

// solve
template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;}
template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}
template <typename T> ostream &operator<<(ostream &os, const vector<T>& vec){for(int i = 0; i < vec.size(); i++){ os << vec[i]; if(i + 1 != vec.size())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){os << p.first << " " << p.second; return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << itr->first << ":" << itr->second; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << itr->first << ":" << itr->second; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}

int n;
vector<ll> a;
bool vis[1001][1001];
ll dp[1001][1001];
vector<ll> ans;
int cut[1001][1001];
int at = 0;

ll calc(int l, int r){
  if(vis[l][r])return dp[l][r];
  vis[l][r] = true;
  ll res = - linf;
  if(r - l == 1){
    cut[l][r] = l;
    res = a[l];
  }
  else if(l == 0){
    if(r - l == 2){
      res = a[l+1];
      cut[l][r] = l + 1;
    }
    else{
      res = max(res, a[r - 1]);
      for(int j = l + 1; j < r - 1; j++){
        ll ansl = calc(l, j);
        ll ansr = calc(j + 1, r);
        ll tmp = max(ansr, ansl + ansr);
        if(tmp > res){
          cut[l][r] = j;
          res = tmp;
        }
      }
    }
  }else if(r == n){
    if(r - l == 2){
      res = a[l];
      cut[l][r] = l;
    }
    else{
      res = max(res, a[l]);
      for(int j = l + 1; j < r - 1; j++){
        ll ansl = calc(l, j);
        ll ansr = calc(j + 1, r);
        ll tmp = max(ansl, ansl + ansr);
        if(tmp > res){
          cut[l][r] = j;
          res = tmp;
        }
      }
    }
  }else{
    if(r - l == 2)res = - linf;
    else{
      for(int j = l + 1; j < r - 1; j++){
        ll ansl = calc(l, j);
        ll ansr = calc(j + 1, r);
        ll tmp = ansl + ansr;
        if(tmp > res){
          cut[l][r] = j;
          res = tmp;
        }
      }
    }
  }
  return dp[l][r] = res;
}

void calc2(int l, int r){
  //cout << l << " " << r << endl;
  if(r - l == 1)return;
  if(l == 0){
    if(r - l == 2){
      ans[at++] = l;
      return;
    }
    if(dp[l][r] == a[r-1]){
      for(int j = 0; j < r - 1; j++)ans[at++] = r - 2 - j;
      return;
    }
    int i = cut[l][r];
    if(dp[l][r] == calc(i+1, r)){
      ans[at++] = i;
      ans[at++] = cut[l][i];
    }else{
      ans[at++] = i;
    }
    calc2(l, i);
    calc2(i + 1, r);
  }else if(r == n){
    if(r - l == 2){
      ans[at++] = r - 1;
      return;
    }
    if(dp[l][r] == a[l]){
      for(int j = 1; j + l < r; j++)ans[at++] = j + l;
      return;
    }
    int i = cut[l][r];
    if(dp[l][r] == calc(l, i)){
      ans[at++] = i;
      ans[at++] = cut[i+1][r];
    }else{
      ans[at++] = i;
    }
    calc2(l, i);
    calc2(i+1, r);
  }else{
    int i = cut[l][r];
    ans[at++] = i;
    calc2(l, i);
    calc2(i+1, r);
  }
}

int main(int argc, char const* argv[])
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  a.resize(n);
  ans.resize(n);
  cin >> a;
  cout << calc(0, n) << endl;
  calc2(0, n);
  ans.resize(at);
  cout << at << endl;
  reverse(all(ans));
  //cout << ans << endl;
  vector<bool> used(n, false);
  rep(i, sz(ans)){
    int cnt = 0;
    for(int j = 0; j < ans[i]; j++)if(!used[j])cnt++;
    cout << cnt + 1 << endl;
    used[ans[i]] = true;
  }
  return 0;
}