package main import ( "bufio" "fmt" "os" "sort" "strconv" ) var sc = bufio.NewScanner(os.Stdin) var rdr = bufio.NewReaderSize(os.Stdin, 1000000) func main() { sc.Split(bufio.ScanWords) n := nextInt() var ns []int var ss []string for i := 0; i < n; i++ { w := nextLine() if w == "+" || w == "-" { ss = append(ss, w) continue } num, _ := strconv.Atoi(w) ns = append(ns, num) } sort.Ints(ns) sort.Strings(ss) big := ns[len(ns)-1] for i := len(ns) - 2; i >= len(ss); i-- { big *= 10 big += ns[i] } max := big for i, ope := range ss { nI := len(ss) - 1 - i switch ope { case "+": max += ns[nI] case "-": max -= ns[nI] } } min := ns[0] ns[len(ss)] = big ns = ns[1:] for i, ope := range ss { switch ope { case "+": min += ns[i] case "-": min -= ns[i] } } fmt.Println(max, min) } func nextLine() string { sc.Scan() return sc.Text() } func nextInt() int { i, _ := strconv.Atoi(nextLine()) return i }