n = gets.to_i v = gets.split.map(&:to_i) dp = Array.new(n+1) dp[0] = 0 dp[1] = v[0] stack = Array.new(n+1) stack[0] = [] stack[1] = [1] (2..n).each do |i| if dp[i-1] > v[i - 1] + dp[i - 2] dp[i] = dp[i-1] stack[i] = stack[i-1] + [] else dp[i] = v[i - 1] + dp[i - 2] stack[i] = stack[i-2] + [i] end end puts dp[n] puts stack[n].join(' ')