#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>

using namespace std;

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

long long int INF = 1e18;
long long int mod = 1000000007;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "RULD";
//↓,→,↑,←

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll number1,ll number2){
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1 , number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1 , number1);
    }
}


ll i,j,k,ii,jj;
ll n,m;
ll a,b,c,d,e,g,h,r;
ll l,ans;
ll num;
ll x[500005],y[500005],z[500005];
bool dame;
//char s[500005],t[500005];
bool use[500005];
ll xnum,ynum;

int main(){
    //return 0;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> x[i];
        y[i] = x[i];
    }
    bool ok = false;
    for(i=0;i<n;i++){
        if(x[i] > 0){
            ok = true;
        }
    }
    if(!ok){
		c = 0;
        //要素は負のみ
        sort(y,y+n);
        p(y[n-1]);
        p(n-1);
        for(i=0;i<n;i++){
            if(x[i] != y[n-1]){
                p(1);
				c++;
            }else{
                num = i;
                break;
            }
        }
        for(i=n-1;i>num;i--){
            p(i+1-c);
        }
        return 0;
    }else{
        //要素に正のものが存在
		a = 0;
		b = 0;
		for(i=0;i<n;i++){
			if(x[i] < 0)continue;
			if(i % 2 == 0){
				a += x[i];
			}else{
				b += x[i];
			}
		}
		if(a < b){
			p(b);
			num = 1;
		}else{
			p(a);
			num = 0;
		}
		k = 0;
		for(i=0;i<n;i++){
			if((i + num) % 2 == 0 && x[i] > 0){
				use[i] = true;
			}else{
				use[i] = false;
			}
		}
		ll left,right;
		for(i=0;i<n;i++){
			if(!use[i]){
				z[k++] = 0;
				c++;
			}else{
				left = i;
				break;
			}
		}
		for(i=n-1;i>=0;i--){
			if(!use[i]){
				z[k++] = i-c;
			}else{
				right = i;
				break;
			}
		}
		a = right;
		while(a >= left){
			if(!use[a-1] && !use[a] && !use[a+1] && a-1 >= 0){
				z[k++] = a-c;
				use[a] = true;
			}else if(use[a-1] && !use[a] && use[a+1] && a-1>=0){
				z[k++] = a-c;
				use[a] = true;
			}
			a--;
		}
		p(k);
		for(i=0;i<k;i++){
			p(z[i]+1);
		}
    }
    return 0;
}

Measured memory_bytes: 29824