import sys N, = map(int, input().split()) mod = 10**9+7 X = list(map(int, input().split())) if 0 in X: print(0) sys.exit() X.append(10**9+7) j = 0 sm = 1 Cs = [0]*N for i in range(N): while sm*X[j]<=10**9: sm *= X[j] # print(j, X[j], sm, j-i) # Cs[j] += j-i j += 1 Cs[i] += j-i sm//=X[i] #print(Cs) D = [] for i in range(N): D.append((i*2, Cs[i])) D.append(((i+Cs[i])*2+1, Cs[i])) #print(sorted(D)) D = sorted(D) R = 1 cnt = 0 xm = 0 for idx, c in D: if idx%2: cnt -= 1 else: idx //= 2 xm -= cnt # print(xm, cnt, c+xm) R = R * pow(X[idx], c+xm, mod) % mod cnt += 1 xm += c print(R)