N = int(input()) A = list(map(int, input().split())) M = 10**9 + 7 f = lambda x: 1 if x == 1 else x * f(x - 1) ans = 1 for a in A: if a == 0: print(0) exit() if a > 3: print(M) exit() ans *= a**f(a) if ans > M: print(M) exit() print(M % ans)