import sys
from itertools import permutations
def get_operations(in_operation: list) -> list:
basic_operation = ['+', '-', '*', '/']
operations : list = []
for i in range(len(in_operation)): # [2, 1, 1, 1]
for j in range(in_operation[i]):
operations.append(basic_operation[i])
return operations
def get_min_max_value(operations: list) -> None:
global minimum, maximum
for case in permutations(operations, N-1):
total = numbers[0]
for i in range(1, N):
if case[i-1] == "+":
total += numbers[i]
elif case[i-1] == "-":
total -= numbers[i]
elif case[i-1] == "*":
total *= numbers[i]
elif case[i-1] == "/":
total = int(total / numbers[i])
if total > maximum:
maximum = total
if total < minimum:
minimum = total
if __name__ == "__main__":
input = sys.stdin.readline
N = int(input())
numbers = list(map(int, input().split()))
in_operation = list(map(int, input().split()))
maximum = -1e9
minimum = 1e9
operations = get_operations(in_operation)
get_min_max_value(operations)
print (maximum)
print (minimum)