open System [] let main argv = let n = Console.ReadLine() |> int let cs = Console.ReadLine().Split(' ') |> Array.map char let (ds, cnt_add, cnt_sub) = cs |> Array.fold (fun (ds, cnt_add, cnt_sub) -> function | '+' -> (ds, cnt_add + 1, cnt_sub) | '-' -> (ds, cnt_add, cnt_sub + 1) | c -> ((int (string c)) :: ds, cnt_add, cnt_sub) ) ([], 0, 0) let cnt_place = List.length ds - 1 - (cnt_add + cnt_sub) let ds = ds |> List.sort |> List.rev // decending let t1 = ds |> Seq.take (cnt_place + 1) |> Seq.fold (fun x d -> x * 10 + d) 0 let ds1 = t1 :: (ds |> Seq.skip (cnt_place + 1) |> List.ofSeq) let f ds = + (ds |> Seq.take (cnt_add + 1) |> Seq.sum) - (ds |> Seq.skip (cnt_add + 1) |> Seq.sum) let ma = f ds1 let mi = f (ds1 |> List.rev) printfn "%d %d" ma mi //exit code 0