import std.algorithm;
import std.array;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void solve (int n)
{
	readln;
	auto a = readln.splitter.map !(to !(long)).array;
	long res = long.min;
	int best;
	foreach (b; 0..2)
	{
		auto list = a.drop (b).stride (2);
		auto filtered = list.filter !(q{a >= 0});
		auto cur = filtered.empty ? list.reduce !(max) : filtered.sum;
		if (res < cur)
		{
			res = cur;
			best = b;
		}
	}
	writeln (res);

	int [] history;
	auto list = a.drop (best).stride (2);
	auto filtered = list.filter !(q{a >= 0});
	if (filtered.empty)
	{
		auto m = list.reduce !(max);
		auto pos = a.countUntil (m).to !(int);
		foreach_reverse (i; pos + 1..n)
		{
			history ~= i;
		}
		foreach (i; 0..pos)
		{
			history ~= 0;
		}
	}
	else
	{
		if (best)
		{
			history ~= 0;
			a.popFront ();
		}
		while (a.front < 0)
		{
			history ~= 0;
			a.popFront ();
			history ~= 0;
			a.popFront ();
		}
		int pos = 0;
		while (true)
		{
			int cur = pos + 2;
			while (cur < a.length && a[cur] < 0)
			{
				cur += 2;
			}
			if (cur >= a.length)
			{
				while (a.length > pos + 1)
				{
					history ~= a.length - 1;
					a.popBack ();
				}
				break;
			}
			int mid = (pos + cur) / 2;
			while (mid != pos)
			{
				debug {writeln (pos, " ", mid, " ", cur);}
				debug {writeln (a);}
				history ~= mid;
				a = a[0..mid - 1] ~ (a[mid - 1] + a[mid + 1]) ~
				    a[mid + 2..$];
				mid -= 1;
			}
			pos = mid;
		}
	}
	debug {writeln (a);}
	writefln ("%s\n%(%s\n%)", history.length, history.map !(q{a + 1}));
}

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		solve (n);
	}
}
