import std.stdio; import std.conv; import std.algorithm; import std.array; import std.string; import std.typecons; void main() { int N = stdin.readln.chomp.to!int; auto V = stdin.readln.chomp.split(' ').map!(to!int).array; alias R = Tuple!(int, int); alias K = Tuple!(int, bool); R[K] memo; auto next = new int[N]; next[] = -1; R dfs(int n, bool prev_used) { if (n == N) return R(0, -1); auto key = K(n, prev_used); if (key in memo) return memo[key]; if (prev_used) return dfs(n + 1, false); auto a = dfs(n + 1, true); a[0] += V[n]; auto b = dfs(n + 1, false); if (a[0] > b[0]) { next[n] = a[1]; a[1] = n; memo[key] = a; } else { memo[key] = b; } return memo[key]; } auto ans = dfs(0, false); writeln(ans[0]); int n = ans[1]; int[] path; while (n >= 0) { path ~= n + 1; n = next[n]; } writefln("%(%s %)", path); }