#include #include #include using namespace std; typedef long long int ll; constexpr int kMod = int(1E9 + 7), kN = 262144, kkMod = 1004535809; ll Pow(ll a, ll b, int p = kMod) { ll ans = 1; while (b) { if (b & 1) ans = ans * a % p; a = a * a % p; b >>= 1; } return ans; } void Ntt(vector &v, bool on, int sz) { ll wn, u, t, w, inv; for (int i = 1, j = sz >> 1, k; i < (sz - 1); i++) { if (i < j) swap(v[i], v[j]); k = sz >> 1; while (j & k) { j ^= k; k >>= 1; } j |= k; } for (int i = 2; i <= sz; i <<= 1) { wn = on ? Pow(3, (kkMod - 1) / i, kkMod) : Pow(3, kkMod - 1 - (kkMod - 1) / i, kkMod); for (int j = 0; j < sz; j += i) { w = 1; for (int k = j; k < j + (i >> 1); k++) { u = v[k]; t = (w * v[k + (i >> 1)]) % kkMod; v[k] = (u + t) % kkMod; v[k + (i >> 1)] = (u - t + kkMod) % kkMod; w = (w * wn) % kkMod; } } } if (on) { inv = Pow(sz, kkMod - 2, kkMod); for (int i = 0; i < sz; i++) v[i] = v[i] * inv % kkMod; } } int a[kN]; ll ts[kN]; bool Lesser(int ax, int ay, int bx, int by) { long double left = (ax + ay), right = (bx + by); left *= pow(ax, ay), right *= pow(bx, by); return left > right; } int main() { int n, l, r, nm; ll ans = 1, tmp = 1; vector v(kN); scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); ts[0] = 0; for (int i = 1; i <= n; i++) ts[i] = (ts[i - 1] + a[i]) % (kMod - 1); for (int i = 1; i <= n; i++) v[a[i]]++; Ntt(v, false, kN); for (int i = 0; i < kN; i++) v[i] = v[i] * v[i] % kkMod; Ntt(v, true, kN); for (int i = 1; i <= n; i++) v[a[i] << 1]--; for (int i = 1; i < kN; i++) v[i] >>= 1; for (int i = 1; i < kN; i++) tmp = tmp * Pow(i, v[i]) % kMod; for (int i = 1; i <= n; i++) ans = ans * Pow(a[i], ts[n] - ts[i] + kMod - 1) % kMod; l = a[n - 1], r = a[n], nm = a[n]; for (int i = n - 2; i >= 1; i--) { nm = min(nm, a[i + 1]); if (Lesser(l, r, a[i], nm)) { l = a[i]; r = nm; } } ans = ans * tmp % kMod; printf("%lld\n", ans * Pow((l + r) * Pow(l, r) % kMod, kMod - 2) % kMod); }