import qualified Data.IntMap.Strict as M import Data.List main = do getLine vs <- map read . words <$> getLine let (maxv,(_,h)) = sushi (zip [1..] vs) print maxv putStrLn $ unwords (map show (reverse h)) sushi = M.findMax . foldl dp (M.singleton 0 (True,[])) dp im (i,v) = let (maxv,(_,h)) = M.findMax im in M.insertWith const maxv (True,h) im' where im' = M.map (\(p,h) -> (False, i:h)) $ M.mapKeys (+v) (M.filter (id.fst) im)