#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
const int M = 1e5 + 5;
const int MOD = 1e9 + 7;
const auto Power = [&](int a, long long x) {
int res = 1;
while (x > 0) {
if (x & 1) {
res = 1ll * res * a % MOD;
}
a = 1ll * a * a % MOD;
x /= 2;
}
return res;
};
vector<int> isprime(M, 1);
vector<int> factorize(M, 1);
for (int i = 2; i < M; i++) {
if (isprime[i]) {
for (int j = i; j < M; j += i) {
isprime[j] = 0;
factorize[j] = i;
}
}
}
vector<vector<pair<int, int>>> occ(M);
for (int i = 0; i < N; i++) {
while (A[i] > 1) {
int p = factorize[A[i]];
A[i] /= p;
if (!occ[p].empty() && occ[p].back().first == i) {
occ[p].back().second += 1;
} else {
occ[p].emplace_back(i, 1);
}
}
}
int ans = 1;
for (int p = 2; p < M; p++) {
if (occ[p].empty()) {
continue;
}
long long total_power_sum = 0;
int current_power_sum = 0;
vector<array<int, 3>> st;
st.push_back({-1, MOD, 0});
occ[p].emplace_back(N, 0);
for (int i = 0; i + 1 < (int) occ[p].size(); i++) {
auto [id, freq] = occ[p][i];
while (!st.empty() && st.back()[1] <= freq) {
current_power_sum -= st.back()[2];
st.pop_back();
}
int add = freq * (id - st.back()[0]);
current_power_sum += add;
st.push_back({id, freq, add});
total_power_sum += 1ll * current_power_sum * (occ[p][i + 1].first - id);
}
ans = 1ll * ans * Power(p, total_power_sum) % MOD;
}
cout << ans << '\n';
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpIHsKICBpb3M6OnN5bmNfd2l0aF9zdGRpbygwKTsKICBjaW4udGllKDApOwoKICBpbnQgTjsKICBjaW4gPj4gTjsKCiAgdmVjdG9yPGludD4gQShOKTsKICBmb3IgKGludCBpID0gMDsgaSA8IE47IGkrKykgewogICAgY2luID4+IEFbaV07CiAgfQogIAogIGNvbnN0IGludCBNID0gMWU1ICsgNTsKICBjb25zdCBpbnQgTU9EID0gMWU5ICsgNzsKCiAgY29uc3QgYXV0byBQb3dlciA9IFsmXShpbnQgYSwgbG9uZyBsb25nIHgpIHsKICAgIGludCByZXMgPSAxOwogICAgd2hpbGUgKHggPiAwKSB7CiAgICAgIGlmICh4ICYgMSkgewogICAgICAgIHJlcyA9IDFsbCAqIHJlcyAqIGEgJSBNT0Q7CiAgICAgIH0KICAgICAgYSA9IDFsbCAqIGEgKiBhICUgTU9EOwogICAgICB4IC89IDI7CiAgICB9CiAgICByZXR1cm4gcmVzOwogIH07CgogIHZlY3RvcjxpbnQ+IGlzcHJpbWUoTSwgMSk7CiAgdmVjdG9yPGludD4gZmFjdG9yaXplKE0sIDEpOwoKICBmb3IgKGludCBpID0gMjsgaSA8IE07IGkrKykgewogICAgaWYgKGlzcHJpbWVbaV0pIHsKICAgICAgZm9yIChpbnQgaiA9IGk7IGogPCBNOyBqICs9IGkpIHsKICAgICAgICBpc3ByaW1lW2pdID0gMDsKICAgICAgICBmYWN0b3JpemVbal0gPSBpOwogICAgICB9CiAgICB9CiAgfQoKICB2ZWN0b3I8dmVjdG9yPHBhaXI8aW50LCBpbnQ+Pj4gb2NjKE0pOwogIGZvciAoaW50IGkgPSAwOyBpIDwgTjsgaSsrKSB7CiAgICB3aGlsZSAoQVtpXSA+IDEpIHsKICAgICAgaW50IHAgPSBmYWN0b3JpemVbQVtpXV07CiAgICAgIEFbaV0gLz0gcDsKICAgICAgaWYgKCFvY2NbcF0uZW1wdHkoKSAmJiBvY2NbcF0uYmFjaygpLmZpcnN0ID09IGkpIHsKICAgICAgICBvY2NbcF0uYmFjaygpLnNlY29uZCArPSAxOwogICAgICB9IGVsc2UgewogICAgICAgIG9jY1twXS5lbXBsYWNlX2JhY2soaSwgMSk7CiAgICAgIH0KICAgIH0KICB9CgogIGludCBhbnMgPSAxOwogIGZvciAoaW50IHAgPSAyOyBwIDwgTTsgcCsrKSB7CiAgICBpZiAob2NjW3BdLmVtcHR5KCkpIHsKICAgICAgY29udGludWU7CiAgICB9CiAgICAKICAgIGxvbmcgbG9uZyB0b3RhbF9wb3dlcl9zdW0gPSAwOwogICAgaW50IGN1cnJlbnRfcG93ZXJfc3VtID0gMDsKICAgIAogICAgdmVjdG9yPGFycmF5PGludCwgMz4+IHN0OwogICAgc3QucHVzaF9iYWNrKHstMSwgTU9ELCAwfSk7CiAgICBvY2NbcF0uZW1wbGFjZV9iYWNrKE4sIDApOwoKICAgIGZvciAoaW50IGkgPSAwOyBpICsgMSA8IChpbnQpIG9jY1twXS5zaXplKCk7IGkrKykgewogICAgICBhdXRvIFtpZCwgZnJlcV0gPSBvY2NbcF1baV07CiAgICAgIHdoaWxlICghc3QuZW1wdHkoKSAmJiBzdC5iYWNrKClbMV0gPD0gZnJlcSkgewogICAgICAgIGN1cnJlbnRfcG93ZXJfc3VtIC09IHN0LmJhY2soKVsyXTsKICAgICAgICBzdC5wb3BfYmFjaygpOwogICAgICB9CiAgICAgIGludCBhZGQgPSBmcmVxICogKGlkIC0gc3QuYmFjaygpWzBdKTsKICAgICAgY3VycmVudF9wb3dlcl9zdW0gKz0gYWRkOwogICAgICBzdC5wdXNoX2JhY2soe2lkLCBmcmVxLCBhZGR9KTsKICAgICAgdG90YWxfcG93ZXJfc3VtICs9IDFsbCAqIGN1cnJlbnRfcG93ZXJfc3VtICogKG9jY1twXVtpICsgMV0uZmlyc3QgLSBpZCk7CiAgICB9CgogICAgYW5zID0gMWxsICogYW5zICogUG93ZXIocCwgdG90YWxfcG93ZXJfc3VtKSAlIE1PRDsKICB9CgogIGNvdXQgPDwgYW5zIDw8ICdcbic7CiAgcmV0dXJuIDA7IAp9Cg==