-- yukicoder My Practice -- author: Leonardone @ NEETSDKASU import Data.List main = do n <- getLine c <- getLine putStrLn $ solve c solve c = let cc = words c (mc, nm) = partition (== "-") cc (pc, np) = partition (== "+") nm sc = sort np fn1 _ 0 s cs = (s, cs) fn1 f n s (c:cs) = fn1 f (n - 1) (f s $ read c) cs lm = length mc lp = length pc (sm1, nm1) = fn1 (-) lm 0 sc (sm2, nm2) = fn1 (+) lp sm1 nm1 maxsum = sm2 + (read $ reverse $ concat nm2) (sx1, nx1) = fn1 (+) (lp + 1) 0 sc (sx2, nx2) = if lm < 2 then (sx1, nx1) else fn1 (-) (lm - 1) sx1 nx1 minsum = if lm == 0 then fn2 (lp + 1) sc 1 0 else sx2 - (read $ reverse $ concat nx2) in unwords $ map show [maxsum, minsum] fn2 _ [] _ s = s fn2 n xs b s = let (ys, zs) = splitAt n xs sm = sum $ map read ys in fn2 n zs (b * 10) (sm + s * b)