#include int ri() { int n; scanf("%d", &n); return n; } int pow(int a, int b, int mod) { int res = 1; for (; b; b >>= 1) { if (b & 1) res = (int64_t) res * a % mod; a = (int64_t) a * a % mod; } return res; } int inv(int i, int mod) { return pow(i, mod - 2, mod); } template struct NTT { int get_mod() { return mod; } void ntt(std::vector &a, bool inverse) { int n = a.size(); assert((n & -n) == n); int h = pow(proot, (mod - 1) / n, mod); if (inverse) h = inv(h, mod); for (int i = 0, j = 1; j < n - 1; j++) { for (int k = n >> 1; k > (i ^= k); k >>= 1); if (j < i) std::swap(a[i], a[j]); } for (int i = 1; i < n; i <<= 1) { int base = pow(h, n / i / 2, mod); int w = 1; for (int j = 0; j < i; j++) { for (int k = j; k < n; k += i << 1) { int u = a[k]; int d = (int64_t) a[k + i] * w % mod; a[k] = u + d; if (a[k] >= mod) a[k] -= mod; a[k + i] = u - d; if (a[k + i] < 0) a[k + i] += mod; } w = (int64_t) w * base % mod; } } if (inverse) { int ninv = inv(a.size(), mod); for (auto &i : a) i = (int64_t) i * ninv % mod; } } std::vector conv(const std::vector a_, const std::vector b_) { std::vector a = a_, b = b_; size_t size = 1; for (; size < a_.size() + b_.size(); size <<= 1); a.resize(size); b.resize(size); ntt(a, false); ntt(b, false); for (size_t i = 0; i < size; i++) a[i] = (int64_t) a[i] * b[i] % mod; ntt(a, true); a.resize(a_.size() + b_.size() - 1); return a; } }; #define MOD 1000000007 std::vector conv(const std::vector a, const std::vector b) { NTT<998244353, 3> ntt1; NTT<469762049, 3> ntt2; auto r0 = ntt1.conv(a, b); auto r1 = ntt2.conv(a, b); int n = r0.size(); std::vector res; for (int i = 0; i < n; i++) { int64_t cur = r0[i]; while (cur % 469762049 != r1[i]) cur += 998244353; res.push_back(cur); } return res; } int main() { int n = ri(); int a[n]; for (int i = 0; i < n; i++) a[i] = ri(); std::multiset > all; for (int i = 0; i < n; i++) all.insert({a[i], i}); std::pair optimal; double min = 1000000000; for (int i = 0; i < n; i++) { all.erase(all.find({a[i], i})); double cur = log(a[i]) * all.begin()->first; if (min > cur) min = cur, optimal = {i, all.begin()->second}; } int64_t sum[n]; sum[n - 1] = 0; for (int i = n - 2; i >= 0; i--) sum[i] = sum[i + 1] + a[i + 1]; int res = 1; for (int i = 0; i < n; i++) res = (int64_t) res * pow(a[i], sum[i] % (MOD - 1), MOD) % MOD; std::vector num(100001); for (int i = 0; i < n; i++) num[a[i]]++; auto conved = conv(num, num); for (int i = 0; i < n; i++) conved[a[i] + a[i]]--; for (int i = 1; i <= 200000; i++) assert(conved[i] % 2 == 0), conved[i] >>= 1, res = (int64_t) res * pow(i, conved[i] % (MOD - 1), MOD) % MOD; res = (int64_t) res * inv((int64_t) (a[optimal.first] + a[optimal.second]) * pow(a[optimal.first], a[optimal.second], MOD) % MOD, MOD) % MOD; std::cout << res << std::endl; return 0; }