Problem p02793 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T> bool maxi(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool mini(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#define dame                                                                   \
  {                                                                            \
    cout << "-1"                                                               \
         << "\n";                                                              \
    return;                                                                    \
  }
#define INF2 1000000000000000037
#define INF 1000000007
#define MOD 1000000007
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
//--GLOBAL---------------------------------
const int MAXN = 100024;

ll soinsu[MAXN + 1];

void prime_factors(int n) {
  map<int, int> res;
  for (int i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      res[i]++; // 素数i^{res[i]}
      n /= i;
    }
  }
  if (n != 1)
    res[n]++;
  for (auto x : res) {
    ll sosu = x.first, kosu = x.second;
    maxi(soinsu[sosu], kosu);
  }
}
ll modpow(ll a, ll n = MOD - 2, ll mod = MOD) { // a^n % MOD の計算
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
//--MAIN-----------------------------------
void Main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  rep(i, N) { prime_factors(A[i]); }
  ll ans = 1;
  rep(i, MAXN) {
    while (soinsu[i] != 0) {
      --soinsu[i];
      ans *= i;
      ans %= MOD;
    }
  }
  ll ans2 = 0;
  rep(i, N) {
    ans2 += modpow(A[i]);
    ans2 %= MOD;
  }
  ans *= ans2;
  ans %= MOD;
  cout << ans << "\n";
}

//--START----------------------------------
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------------


Fixed submission:
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T> bool maxi(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool mini(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#define dame                                                                   \
  {                                                                            \
    cout << "-1"                                                               \
         << "\n";                                                              \
    return;                                                                    \
  }
#define INF2 1000000000000000037
#define INF 1000000007
#define MOD 1000000007
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
//--GLOBAL---------------------------------
const int MAXN = 1000024;

ll soinsu[MAXN + 1];

void prime_factors(int n) {
  map<int, int> res;
  for (int i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      res[i]++; // 素数i^{res[i]}
      n /= i;
    }
  }
  if (n != 1)
    res[n]++;
  for (auto x : res) {
    ll sosu = x.first, kosu = x.second;
    maxi(soinsu[sosu], kosu);
  }
}
ll modpow(ll a, ll n = MOD - 2, ll mod = MOD) { // a^n % MOD の計算
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
//--MAIN-----------------------------------
void Main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  rep(i, N) { prime_factors(A[i]); }
  ll ans = 1;
  rep(i, MAXN) {
    while (soinsu[i] != 0) {
      --soinsu[i];
      ans *= i;
      ans %= MOD;
    }
  }
  ll ans2 = 0;
  rep(i, N) {
    ans2 += modpow(A[i]);
    ans2 %= MOD;
  }
  ans *= ans2;
  ans %= MOD;
  cout << ans << "\n";
}

//--START----------------------------------
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------------