#line 1 "main.cpp" #include #line 2 "/home/user/Library/utils/macros.hpp" #define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i)) #define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i)) #define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i)) #define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i)) #define ALL(x) std::begin(x), std::end(x) #line 4 "/home/user/Library/modulus/modpow.hpp" inline int32_t modpow(uint_fast64_t x, uint64_t k, int32_t MOD) { assert (/* 0 <= x and */ x < (uint_fast64_t)MOD); uint_fast64_t y = 1; for (; k; k >>= 1) { if (k & 1) (y *= x) %= MOD; (x *= x) %= MOD; } assert (/* 0 <= y and */ y < (uint_fast64_t)MOD); return y; } #line 5 "/home/user/Library/modulus/modinv.hpp" inline int32_t modinv_nocheck(int32_t value, int32_t MOD) { assert (0 <= value and value < MOD); if (value == 0) return -1; int64_t a = value, b = MOD; int64_t x = 0, y = 1; for (int64_t u = 1, v = 0; a; ) { int64_t q = b / a; x -= q * u; std::swap(x, u); y -= q * v; std::swap(y, v); b -= q * a; std::swap(b, a); } if (not (value * x + MOD * y == b and b == 1)) return -1; if (x < 0) x += MOD; assert (0 <= x and x < MOD); return x; } inline int32_t modinv(int32_t x, int32_t MOD) { int32_t y = modinv_nocheck(x, MOD); assert (y != -1); return y; } #line 6 "/home/user/Library/modulus/mint.hpp" /** * @brief quotient ring / 剰余環 $\mathbb{Z}/n\mathbb{Z}$ */ template struct mint { int32_t value; mint() : value() {} mint(int64_t value_) : value(value_ < 0 ? value_ % MOD + MOD : value_ >= MOD ? value_ % MOD : value_) {} mint(int32_t value_, std::nullptr_t) : value(value_) {} explicit operator bool() const { return value; } inline mint operator + (mint other) const { return mint(*this) += other; } inline mint operator - (mint other) const { return mint(*this) -= other; } inline mint operator * (mint other) const { return mint(*this) *= other; } inline mint & operator += (mint other) { this->value += other.value; if (this->value >= MOD) this->value -= MOD; return *this; } inline mint & operator -= (mint other) { this->value -= other.value; if (this->value < 0) this->value += MOD; return *this; } inline mint & operator *= (mint other) { this->value = (uint_fast64_t)this->value * other.value % MOD; return *this; } inline mint operator - () const { return mint(this->value ? MOD - this->value : 0, nullptr); } inline bool operator == (mint other) const { return value == other.value; } inline bool operator != (mint other) const { return value != other.value; } inline mint pow(uint64_t k) const { return mint(modpow(value, k, MOD), nullptr); } inline mint inv() const { return mint(modinv(value, MOD), nullptr); } inline mint operator / (mint other) const { return *this * other.inv(); } inline mint & operator /= (mint other) { return *this *= other.inv(); } }; template mint operator + (int64_t value, mint n) { return mint(value) + n; } template mint operator - (int64_t value, mint n) { return mint(value) - n; } template mint operator * (int64_t value, mint n) { return mint(value) * n; } template mint operator / (int64_t value, mint n) { return mint(value) / n; } template std::istream & operator >> (std::istream & in, mint & n) { int64_t value; in >> value; n = value; return in; } template std::ostream & operator << (std::ostream & out, mint n) { return out << n.value; } #line 8 "/home/user/Library/number/fast_fourier_transformation.hpp" /** * @note O(N log N) * @note radix-2, decimation-in-frequency, Cooley-Tukey * @note cache std::polar (~ 2x faster) */ template void fft_inplace(std::vector > & f, bool inverse) { const int n = f.size(); assert (n == pow(2, log2(n))); // cache static std::vector > cache; if ((int)cache.size() != n / 2) { const R theta = 2 * M_PI / n; cache.resize(n / 2); REP (irev, n / 2) { cache[irev] = std::polar(1, irev * theta); } } // bit reverse int i = 0; REP3 (j, 1, n - 1) { for (int k = n >> 1; (i ^= k) < k; k >>= 1); if (j < i) swap(f[i], f[j]); } // divide and conquer for (int mh = 1; (mh << 1) <= n; mh <<= 1) { int irev = 0; for (int i = 0; i < n; i += (mh << 1)) { auto w = (inverse ? conj(cache[irev]) : cache[irev]); for (int k = n >> 2; (irev ^= k) < k; k >>= 1); REP3 (j, i, mh + i) { int k = j + mh; std::complex x = f[j] - f[k]; f[j] += f[k]; f[k] = w * x; } } } } template std::vector > fft(std::vector > f) { f.resize(pow(2, ceil(log2(f.size())))); fft_inplace(f, false); return f; } template std::vector > ifft(std::vector > f) { f.resize(pow(2, ceil(log2(f.size())))); fft_inplace(f, true); return f; } /** * @brief FFT convolution * @note O(N log N) * @note (f \ast g)(i) = \sum_{0 \le j \lt i + 1} f(j) g(i - j) */ template std::vector fft_convolution(std::vector const & a, std::vector const & b) { assert (not a.empty() and not b.empty()); int m = a.size() + b.size() - 1; int n = pow(2, ceil(log2(m))); std::vector > x(n), y(n); copy(ALL(a), x.begin()); copy(ALL(b), y.begin()); fft_inplace(x, false); fft_inplace(y, false); std::vector > z(n); REP (i, n) { z[i] = x[i] * y[i]; } fft_inplace(z, true); std::vector c(m); REP (i, m) { c[i] = std::is_integral::value ? round(z[i].real() / n) : z[i].real() / n; } return c; } #line 5 "main.cpp" using namespace std; constexpr int64_t MOD = 1000000007; mint solve(int n, const vector &a) { // \prod_i \prod_{j > i} (A_i + A_j) mint x = 1; { int max_a = *max_element(ALL(a)); vector cnt(max_a + 1); for (int a_i : a) { ++ cnt[a_i]; } cnt = fft_convolution(cnt, cnt); for (int a_i : a) { -- cnt[2 * a_i]; } REP (i, cnt.size()) { cnt[i] /= 2; } REP (i, cnt.size()) { int64_t k = round(cnt[i]); assert (abs(cnt[i] - k) <= 1e-6); x *= mint(i).pow(k); } } // \prod_i \prod_{j > i} A_i^{A_j} mint y = 1; { int64_t sum_a_j = 0; REP_R (i, n) { y *= mint(a[i]).pow(sum_a_j); sum_a_j += a[i]; } } // \min_i \mimn_{j > i} (A_i + A_j)A_i^{A_j} mint z = 0; { double log_z = INFINITY; int64_t a_j = a[n - 1]; REP_R (i, n - 1) { double log_a_i_a_j = log(a[i] + a_j) + a_j * log(a[i]); if (log_a_i_a_j < log_z) { log_z = log_a_i_a_j; z = mint(a[i] + a_j) * mint(a[i]).pow(a_j); } a_j = min(a[i], a_j); } } return x * y / z; } int main() { int n; cin >> n; vector a(n); REP (i, n) { cin >> a[i]; } auto ans = solve(n, a); cout << ans << endl; return 0; }