from itertools import permutationsn =int(input())nums =list(map(int,input().split()))a,b,c,d =map(int,input().split())cals = []for i inrange(a): cals.append('+')for i inrange(b): cals.append('-')for i inrange(c): cals.append('*')for i inrange(d): cals.append('//')cal_cases =list(permutations(cals,len(cals)))# print(cal_cases)# 연산자 배치의 모든 경우min_answer =int(1e9)max_answer =-int(1e9)for cal_case in cal_cases:# cal_case = [+ + - * //]# nums = [1,2,3,4,5,6] num = nums[0]for i inrange(len(cal_case)):if cal_case[i]=='+': num += nums[i+1]elif cal_case[i]=='-': num -= nums[i +1]elif cal_case[i]=='*': num *= nums[i +1]elif cal_case[i]=='//':if num <0: num *=-1 num = num // nums[i+1] num *=-1else: num = num // nums[i +1] min_answer =min(num, min_answer) max_answer =max(num, max_answer)print(max_answer)print(min_answer)