{-# 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 g tot xs = runSTArray $ do arr <- newArray (0,tot) "%" writeArray arr (head xs) "" foldM (\a x -> do a' <- newArray (0,tot) "%" plused <- forM [i | i <- [0..tot], i+x <= tot] (\i -> readArray a i >>= \s -> return (i+x, B.append s "+")) 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, B.append s "*")) 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 main = do [n] <- getInts [tot] <- getInts xs <- getInts B.putStrLn $ solve tot xs