import math n = int(input()) a = list(map(int, input().split())) sum_total = sum(a) sum_log = 0.0 for num in a: sum_log += math.log(num) mod = 10**9 + 7 if sum_log > math.log(sum_total): product = 1 for num in a: product = (product * num) % mod print(product) else: print(sum_total % mod)