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: Runtime Error)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N=1005;
const ll inf=(ll)1e15;
ll a[N];
bool mark[N];
ll dp[N][N],dp1[N][N],dp2[N][N],dp3[N][N];
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int n;
  cin>>n;
  int mx=INT_MIN,mxind=-1;
  rep(i,1,n+1)
    {
      cin>>a[i];
      if(a[i]>mx) mx=a[i],mxind=i;
    }
  if(n<=200)
    {
      rep(i,1,n+1)
	dp[i][i]=dp1[i][i]=dp2[i][i]=a[i],dp3[i][i]=a[i];
      rep(i,1,n) dp[i][i+1]=max(a[i],a[i+1]),dp1[i][i+1]=a[i],dp2[i][i+1]=a[i+1],dp3[i][i+1]=-inf;
      rep(j,3,n+1)
	{
	  rep(i,1,n-j+2)
	    {
	      dp[i][i+j-1]=-inf;
	      ll sum=0;
	      rep(k,i+1,i+j-1)
		dp[i][i+j-1]=max(dp[i][i+j-1],dp2[i][k-1]+dp1[k+1][i+j-1]);
	      rep(k,i,i+j)
		rep(l,k,i+j) dp[i][i+j-1]=max(dp[i][i+j-1],dp[k][l]);
	      dp1[i][i+j-1]=a[i];
	      rep(k,i+1,i+j-1)
		dp1[i][i+j-1]=max(dp1[i][i+j-1],dp3[i][k-1]+max((ll)0,dp1[k+1][i+j-1]));
	      dp2[i][i+j-1]=a[i+j-1];
	      rep(k,i+1,i+j-1)
		dp2[i][i+j-1]=max(dp2[i][i+j-1],max((ll)0,dp2[i][k-1])+dp3[k+1][i+j-1]);
	      dp3[i][i+j-1]=-inf;
	      rep(k,i+1,i+j-1)
		dp3[i][i+j-1]=max(dp3[i][k-1]+dp3[k+1][i+j-1],dp3[i][i+j-1]);
	    }
	}
    }
  if(mx<0)
    {
      cout<<mx<<endl;
      cout<<n-1<<endl;
      repv(i,mxind+1,n+1) cout<<i<<endl;
      rep(i,1,mxind) cout<<1<<endl;
      return 0;
    }
  ll ans=-inf;
  int ind=-1;
  rep(j,0,2)
    {
      ll sum=0;
      int cnt=0;
      for(int i=1+j;i<=n;i+=2)
	if(a[i]>=0) sum+=a[i],cnt++;
      if(sum>ans) ans=sum,ind=j;
    }
  if(n>200) dp[1][n]=ans;
  assert(ans==dp[1][n]);
  cout<<ans<<endl;
  vi inds;
  for(int i=1+ind;i<=n;i+=2)
    if(a[i]>=0) inds.pb(i),mark[i]=true;
  vi rem;
  int sz=n;
  rep(i,1,inds[0]) rem.pb(1),sz--;
  repv(i,inds.back()+1,n+1) rem.pb(sz),sz--;
  vi newarr;
  rep(i,inds[0],inds.back()+1) newarr.pb(i);
  while(sz(newarr)>1)
    {
      vi tmp;
      rep(i,0,sz(newarr))
	{
	  if(mark[newarr[i]]) continue;
	  if(mark[newarr[i-1]] && mark[newarr[i+1]])
	    {
	      rem.pb(i+1);
	      break;
	    }
	  if(!mark[newarr[i-1]] && !mark[newarr[i+1]])
	    {
	      rem.pb(i+1);
	      break;
	    }
	}
      rep(i,0,rem.back()-1)
	tmp.pb(newarr[i]);
      rep(i,rem.back()+1,sz(newarr))
	tmp.pb(newarr[i]);
      swap(tmp,newarr);
    }
  cout<<sz(rem)<<endl;
  for(int x:rem) cout<<x<<endl;
  return 0 ;
}