# frozen_string_literal: true N = gets.to_i POINTS = gets.split.map(&:to_i) DP = {} ARRAY = {} DP[-1] = 0 ARRAY[-1] = [] DP[0] = POINTS[0] ARRAY[0] = [0] DP[1] = POINTS[1] ARRAY[1] = [1] (2...N).each do |i| point = POINTS[i] i1 = i - 3 i2 = i - 2 index = DP[i1] > DP[i2] ? i1 : i2 DP[i] = DP[index] + point ARRAY[i] = ARRAY[index] + [i] end index = DP[N - 1] > DP[N - 2] ? N - 1 : N - 2 puts DP[index] puts ARRAY[index].map { |i| i+1 }.join(' ')