# No.1237 EXP Multiple! # https://yukicoder.me/problems/no/1237 from math import factorial def f(x): return x ** factorial(x) n = int(input()) A = list(map(int, input().split())) MOD = 10 ** 9 + 7 if any(a == 0 for a in A): print(0) exit() if any(a > 9 for a in A): print(MOD) exit() ans = 1 for a in A: if ans >= MOD: print(MOD) exit() ans *= f(a) print(MOD % ans)