from enum import Enum, auto from collections import defaultdict from itertools import product def to_list(cons_cell: tuple) -> list: if len(cons_cell) == 0: return [] res = [] x = cons_cell while x is not None: a, x = x res.append(a) return res class E(Enum): EAT = auto() NOT_EAT = auto() INF = 1 << 62 N = int(input()) V = list(map(int, input().split())) def is_valid(prev_state, curr_state) -> bool: if prev_state == E.EAT and curr_state == E.EAT: return False return True def recur_dp(p, dp): if p == N: ma = max(dp.values()) for s in E: if dp[s] == ma: return s, ma, None assert False pp = defaultdict(lambda: -INF) dp, pp = pp, dp for fm, to in product(E, repeat=2): if pp[fm] == -INF: continue if not is_valid(fm, to): continue val = pp[fm] + V[p] if to == E.EAT else pp[fm] dp[to] = max(dp[to], val) next_state, max_v, path = recur_dp(p+1, dp) # 復元 for fm in E: if not is_valid(fm, next_state): continue match next_state: case E.EAT: if pp[fm] + V[p] == max_v: return fm, pp[fm], (p, path) case E.NOT_EAT: if pp[fm] == max_v: return fm, max_v, path assert False dp = defaultdict(lambda: -INF) dp[E.NOT_EAT] = 0 _, _, path = recur_dp(0, dp) inds = to_list(path) print(sum([V[p] for p in inds])) print(*[p+1 for p in inds])