import java.util.*; public class Exercise79{ public static void main (String[] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); ArrayList nums = new ArrayList(); ArrayList operators = new ArrayList(); for(int i = 0; i < n; i++){ try{ int x = sc.nextInt(); nums.add(String.valueOf(x)); }catch (InputMismatchException e){ operators.add(sc.next()); } } Collections.sort(nums); Collections.sort(operators); // max long sum = 0; long minus = 0; String maxNum = ""; for (int i = nums.size() - 1; i >= operators.size(); i--){ maxNum += nums.get(i); } sum += Long.parseLong(maxNum); for(int i = 0; i < operators.size(); i++){ if(operators.get(i).equals("+")){ sum += Long.parseLong(nums.get(operators.size() - 1 - i)); }else{ sum -= Long.parseLong(nums.get(operators.size() - 1 - i)); } } //min maxNum = ""; if(operators.indexOf("-") != -1){ for (int i = nums.size() - 1; i >= operators.size(); i--){ maxNum += nums.get(i); } minus += Long.parseLong(nums.get(0)); for(int i = 0; i < operators.size() - 1; i++){ if(operators.get(i).equals("+")){ minus += Long.parseLong(nums.get(i + 1)); }else{ minus -= Long.parseLong(nums.get(i + 1)); } } minus -= Long.parseLong(maxNum); }else{ String[] numArray = new String[operators.size() + 1]; for(int i = 0; i < numArray.length; i++){ numArray[i] = ""; } for(int i = 0; i < nums.size(); i++){ numArray[i % numArray.length] += nums.get(i); } for(int i = 0; i < numArray.length; i++){ minus += Long.parseLong(numArray[i]); } } System.out.println(sum); System.out.println(minus); } }