n = gets.to_i v = gets.split.map(&:to_i) dp = {} dp[0] = 0 dp[1] = v[0] stack = Hash.new do |h,k| h[k] = [] end 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(' ')