local n = io.read("*n") local v = io.read("*n") local ta, tb = {}, {} ta[1] = {v, "1"} tb[1] = {0, "0"} local mma = math.max for i = 2, n do v = io.read("*n") if ta[i - 1][1] < tb[i - 1][1] + v then ta[i] = {tb[i - 1][1] + v, tb[i - 1][2] .. "1"} else ta[i] = {ta[i - 1][1], ta[i - 1][2] .. "0"} end if ta[i - 1][1] < tb[i - 1][1] then tb[i] = {tb[i - 1][1], tb[i - 1][2] .. "0"} else tb[i] = {ta[i - 1][1], ta[i - 1][2] .. "0"} end end if ta[n][1] < tb[n][1] then print(tb[n][1]) local tbl = {} for i = 1, n do if tb[n][2]:sub(i, i) == "1" then table.insert(tbl, i) end end print(table.concat(tbl, " ")) else print(ta[n][1]) local tbl = {} for i = 1, n do if ta[n][2]:sub(i, i) == "1" then table.insert(tbl, i) end end print(table.concat(tbl, " ")) end