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: Accepted)

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

ll n;
ll a[1001];
vector<P> b[2];
ll res[2];
vector<ll> idxs[2];
vector<ll> c;
vector<ll> ans;

int main(){
  cin>>n;
  rep(i,n)cin>>a[i];
  rep(i,n){
    if(i%2==0){
      b[0].push_back(P(a[i],i));
    }else{
      b[1].push_back(P(a[i],i));
    }
  }

  if(b[0].size()>0){
    sort(all(b[0]));
    reverse(all(b[0]));
    res[0]=b[0][0].fi;
    idxs[0].push_back(b[0][0].se);
    repl(i,1,b[0].size()){
      if(b[0][i].fi>0){
        res[0]+=b[0][i].fi;
        idxs[0].push_back(b[0][i].se);
      }
    }
  }
  if(b[1].size()>0){
    sort(all(b[1]));
    reverse(all(b[1]));
    res[1]=b[1][0].fi;
    idxs[1].push_back(b[1][0].se);
    repl(i,1,b[1].size()){
      if(b[1][i].fi>0){
        res[1]+=b[1][i].fi;
        idxs[1].push_back(b[1][i].se);
      }
    }
  }

  rep(i,n)c.push_back(i);

  if(res[0]>res[1]){
    sort(all(idxs[0]));
    while(*c.begin()!=*idxs[0].begin()){
      ans.push_back(0);
      c.erase(c.begin()+0);
    }
    while(*c.rbegin()!=*idxs[0].rbegin()){
      ans.push_back(c.size()-1);
      c.erase(c.begin()+c.size()-1);
    }
    rep(i,idxs[0].size()-1){
      ll nxt=idxs[0][i+1];
      while(c[2]!=nxt){
        ans.push_back(2);
        c.erase(c.begin()+3); c.erase(c.begin()+1);
      }
      ans.push_back(1);
      c.erase(c.begin()+2); c.erase(c.begin()+0);
    }
    cout<<res[0]<<endl;
  }else{
    sort(all(idxs[1]));
    while(*c.begin()!=*idxs[1].begin()){
      ans.push_back(0);
      c.erase(c.begin()+0);
    }
    while(*c.rbegin()!=*idxs[1].rbegin()){
      ans.push_back(c.size()-1);
      c.erase(c.begin()+c.size()-1);
    }
    rep(i,idxs[1].size()-1){
      ll nxt=idxs[1][i+1];
      while(c[2]!=nxt){
        ans.push_back(2);
        c.erase(c.begin()+3); c.erase(c.begin()+1);
      }
      ans.push_back(1);
      c.erase(c.begin()+2); c.erase(c.begin()+0);
    }
    cout<<res[1]<<endl;
  }
  cout<<ans.size()<<endl;
  rep(i,ans.size())cout<<ans[i]+1<<endl;
  return 0;
}