from enum import IntEnum, auto # ステート遷移 class E(IntEnum): EAT = 0 NOT_EAT = auto() def nexts(self): match self: case E.EAT: return [E.NOT_EAT] case E.NOT_EAT: return [E.EAT, E.NOT_EAT] assert False def cost(self, x: int) -> int: match self: case E.EAT: return x case E.NOT_EAT: return 0 assert False @staticmethod def states(): for fm in E: for to in fm.nexts(): yield fm, to N = int(input()) V = list(map(int, input().split())) dp = [[0] * len(E) for _ in range(N+1)] for i, v in enumerate(V): for fm, to in E.states(): dp[i+1][to] = max(dp[i+1][to], dp[i][fm] + to.cost(v)) # 復元 v = max(dp[N]) ans = [] for i in reversed(range(1, N+1)): if dp[i][E.EAT] == v: ans.append(i) v -= V[i-1] elif dp[i][E.NOT_EAT] == v: pass else: assert False print(max(dp[N])) print(*reversed(ans))