import sys sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI2(): return list(map(int,sys.stdin.readline().rstrip())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def LS2(): return list(sys.stdin.readline().rstrip()) N = I() V = [0]+LI() if N == 1: print(V[1]) print(1) exit() dp = [0]*(N+1) prev = [0]*(N+1) dp[1] = V[1] dp[2] = V[2] for i in range(3,N+1): if dp[i-2] >= dp[i-3]: prev[i] = i-2 dp[i] = dp[i-2]+V[i] else: prev[i] = i-3 dp[i] = dp[i-3]+V[i] if dp[-1] >= dp[-2]: ANS = [N] while prev[N] != 0: ANS.append(prev[N]) N = prev[N] ANS.reverse() print(dp[-1]) print(*ANS) else: ANS = [N-1] while prev[N] != 0: ANS.append(prev[N]) N = prev[N] ANS.reverse() print(dp[-2]) print(*ANS)