import itertools
def calculate_expression(numbers, operators):
result = numbers[0]
for i in range(len(operators)):
if operators[i] == '+':
result += numbers[i + 1]
elif operators[i] == '-':
result -= numbers[i + 1]
elif operators[i] == '*':
result *= numbers[i + 1]
elif operators[i] == '/':
if result < 0:
result = -((-result) // numbers[i + 1])
else:
result //= numbers[i + 1]
return result
n = int(input())
numbers = list(map(int, input().split()))
operand_num = list(map(int, input().split()))
operands = ['+', '-', '*', '/']
operand = []
for i in range(4):
operand.extend([operands[i]] * operand_num[i])
max_result = float('-inf')
min_result = float('inf')
for perm in itertools.permutations(operand, n - 1):
result = calculate_expression(numbers, list(perm))
max_result = max(max_result, result)
min_result = min(min_result, result)
print(max_result)
print(min_result)