package com.company; import java.util.*; public class Main { private static long RemoveLargest(List list, int operatorCount) { long value = 0L; int size = list.size(); for(int i = 0; i < size - operatorCount;i++) { value *=10L; value += list.get(0); list.remove(0); } return value; } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); List list = new ArrayList(0); Integer plusCount = 0; Integer minusCount = 0; for(int i = 0; i < n;i++) { String token = scanner.next(); if(token.equals("+")) { plusCount++; continue; } if(token.equals("-")) { minusCount++; continue; } int value = Integer.parseInt(token); list.add(value); } Collections.sort(list); Collections.reverse(list); Long largest = RemoveLargest(list, plusCount+minusCount); Long maxValue = largest; for(int i = 0; i < plusCount;i++) { maxValue += list.get(i); } for(int i = plusCount;i < plusCount + minusCount;i++) { maxValue -= list.get(i); } Long minValue = maxValue; if(minusCount > 0) { minValue = -maxValue; } System.out.println(maxValue.toString() + " " + minValue.toString()); } }