n = int(input()) *a, = map(int,input().split()) par = [-1]*n dp = [0]*n for i,ai in enumerate(a): if ai > dp[i]: dp[i] = ai par[i] = -1 for j in range(2,4): if i+j >= n: continue if dp[i+j] < dp[i] + a[i+j]: dp[i+j] = dp[i] + a[i+j] par[i+j] = i idx = max(range(n), key=lambda i:dp[i]) print(dp[idx]) ans = [] while idx >= 0: ans.append(idx+1) idx = par[idx] print(*ans[::-1])