package main import ( "bufio" "fmt" "os" "strconv" ) var wg = bufio.NewScanner(os.Stdin) const ( inf = int(1e18) initialBufSize = int(1e6) maxBufSize = int(1e6) mod = int(1e9 + 7) maxnum = int(1e9) ) var buf []byte = make([]byte, initialBufSize) func init() { wg.Split(bufio.ScanWords) wg.Buffer(buf, maxBufSize) } func max(a, b int) int { if a > b { return a } else { return b } } func modInv(a, modulo int) int { b := modulo u, v := 1, 0 for b > 0 { t := a / b a, b = b, a-t*b u, v = v, u-t*v } u %= modulo if u < 0 { u += modulo } return u } func powMod(x, n, mod int) int { retval := 1 for mul := x; n > 0; { if n&1 == 1 { retval = retval * mul % mod } mul = mul * mul % mod n >>= 1 } return retval } func nextInt() int { wg.Scan() i, e := strconv.Atoi(wg.Text()) if e != nil { panic(e) } return i } func main() { n := nextInt() a := make([]int, n) for i := 0; i < n; i++ { a[i] = nextInt() } itrs := make([]int, n) for product, itr, i := 1, 0, 0; i < n; i++ { itr = max(itr, i) for itr < n && product*a[itr] <= maxnum { product *= a[itr] itr++ } itrs[i] = itr if itr != i { product /= a[i] } } product_a := make([]int, n) product_product_a := make([]int, n) for i := 0; i < n; i++ { if i > 0 { product_a[i] = product_a[i-1] * a[i] % mod } else { product_a[i] = a[i] % mod } } for i := 0; i < n; i++ { if i > 0 { product_product_a[i] = product_product_a[i-1] * product_a[i] % mod } else { product_product_a[i] = product_a[i] % mod } } final_ans := 1 subtask := func(l, r int) int { if l > 0 { retval := product_product_a[r-1] * modInv(product_product_a[l-1], mod) % mod retval = retval * modInv(powMod(product_a[l-1], r-l, mod), mod) % mod return retval } else { retval := product_product_a[r-1] % mod return retval } } for l := 0; l < n; l++ { if itrs[l] == l { continue } //itrs[l] > l final_ans = final_ans * subtask(l, itrs[l]) % mod } fmt.Printf("%d\n", final_ans) }