{-# LANGUAGE FlexibleContexts, OverloadedStrings #-} import Control.Applicative import Control.Monad import qualified Data.ByteString.Char8 as B import Data.Maybe (fromJust) import Text.Printf import Debug.Trace import Data.Array.IArray import Data.Array.ST getInts :: IO [Int] getInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine inf = 114514 g tot xs = runSTArray $ do arr <- newArray (0,tot) (-inf) writeArray arr (head xs) 0 foldM (\a x -> do a' <- newArray (0,tot) (-inf) plused <- forM [i | i <- [0..tot], i+x <= tot] (\i -> readArray a i >>= \s -> return (i+x, s*2 + 1)) forM_ plused (\(i,x) -> writeArray a' i x) multied <- forM [i | i <- [0..tot], i*x <= tot] (\i -> readArray a i >>= \s -> return (i*x, s*2)) forM_ multied $ \(i,x) -> do px <- readArray a' i if x > px then writeArray a' i x else return () return a' ) arr (tail xs) solve tot xs = (g tot xs)!tot conv x n = (\(_,_,s) -> reverse s) $ until (\(i,_,_) -> i <= 1) (\(i,x,s) -> (i-1, x `div` 2, s ++ (if x`mod`2 == 0 then "*" else "+"))) (n,x,"") main = do [n] <- getInts [tot] <- getInts xs <- getInts putStrLn $ conv (solve tot xs) n