N = gets.to_i V = gets.split.map(&:to_i) dp = Array.new(N, 0) path = Array.new(N, -1) max_v = 0 start = -1 N.times do |i| if dp[i] < V[i] dp[i] = V[i] path[i] = -1 end (i + 2).upto(N - 1) do |j| nv = dp[i] + V[j] next if dp[j] >= nv dp[j] = nv path[j] = i end if max_v < dp[i] max_v = dp[i] start = i end end cur = start ans = [cur + 1] while path[cur] != -1 cur = path[cur] ans << cur + 1 end puts max_v puts ans.reverse.join(' ')