n = int(input()) V = list(map(int, input().split())) if n == 1: print(V[0]) print(1) exit() dp = [0] * n dp[0] = V[0] dp[1] = V[1] bef = [-1] * n for i in range(2, n): dp[i] = dp[i - 2] + V[i] bef[i] = i - 2 if i >= 3 and dp[i - 3] + V[i] > dp[i]: dp[i] = dp[i - 3] + V[i] bef[i] = i - 3 if dp[n - 1] > dp[n - 2]: print(dp[n - 1]) x = n - 1 else: print(dp[n - 2]) x = n - 2 ans = [] while x != -1: ans.append(x + 1) x = bef[x] print(*ans[::-1])