N = gets.to_i A = gets.split.map(&:to_i) L = 10 ** 9 MOD = 10 ** 9 + 7 if A.include?(0) puts 0 exit end rui = Array.new(2 * N + 1, 0) counter = Array.new(N, 0) l = 0 r = 0 val = A[0] while l <= r # pp [:l, l, :r, r] if val >= L len = r - l counter[l] = len rui[l + 1] -= 1 rui[l + len + 1] += 1 val /= A[l] l += 1 elsif r == N - 1 len = r - l + 1 counter[l] = len rui[l + 1] -= 1 rui[l + len + 1] += 1 val /= A[l] l += 1 else r += 1 val *= A[r] end end # pp rui # pp counter ans = 1 cnt = 0 sub = 0 N.times do |i| a = A[i] cnt += counter[i] sub += rui[i] cnt += sub ans *= a.pow(cnt, MOD) ans %= MOD end puts ans