Problem p03025 (C++)

Buggy submission (status: Runtime Error):
// Optimise
#include <bits/stdc++.h>
using namespace std;

#define Online 1
// #define multitest 1
#define Debug 1
void ControlIO();
void TimerStart();
void TimerStop();
#ifdef Debug
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1> void ZZ(const char *name, Arg1 &&arg1) {
  std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  std::cerr.write(names, comma - names) << " = " << arg1;
  ZZ(comma, args...);
}
#else
#define db(...)
#endif
typedef long long ll;
typedef long double ld;
#define f first
#define s second
#define pb push_back
const long long mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll power(int base, int index) {
  if (index == 0)
    return 1;
  ll temp = power(base, index / 2);
  temp = (temp * temp) % mod;
  if (index & 1)
    temp = (temp * base) % mod;
  return temp;
}

int n, a, b, c;

int _n = 1e5 + 10;
vector<ll> Fact(_n), Inv(_n);
int kmod = 1000000007;

void pre() {
  Fact[0] = 1;
  for (int i = 1; i < _n; ++i)
    Fact[i] = (Fact[i - 1] * i) % kmod;
  Inv[_n - 1] = power(Fact[_n - 1], kmod - 2);
  for (int i = _n - 2; i >= 0; --i)
    Inv[i] = (Inv[i + 1] * (1 + i)) % kmod;
  // db(Inv[2]*2%mod);
}

ll com(int m) {
  // db(m, n);
  ll x = (Fact[m - 1] * Inv[n - 1]) % mod;
  x *= Inv[m - n];
  x %= mod;
  ll temp = (power(a, n) * power(b, m - n)) % mod +
            (power(a, m - n) * power(b, n)) % mod;
  // db(temp);
  temp %= mod;
  temp *= m;
  // db(temp);
  temp %= mod;
  temp *= x;
  // db(temp);
  return temp % mod;
}

void solve() {
  pre();
  cin >> n >> a >> b >> c;
  ll ans = 0;
  ll div = power(a + b, mod - 2);
  a = (a * div) % mod;
  b = (b * div) % mod;
  for (int i = n; i < 2 * n; ++i) {
    ans += com(i);
    ans %= mod;
  }
  ans *= power(100 - c, mod - 2);
  ans %= mod;
  ans *= 100;
  cout << (ans % mod) << '\n';
}

int main() {
  ControlIO();
  int t = 1;
#ifdef multitest
  cin >> t;
#endif
  TimerStart();
  while (t--)
    solve();
  TimerStop();
  return 0;
}

void ControlIO() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
#ifndef Online
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

auto TimeStart = chrono::steady_clock::now();
auto TimeEnd = chrono::steady_clock::now();

void TimerStart() {
#ifndef Online
  TimeStart = chrono::steady_clock::now();
#endif
}

void TimerStop() {
#ifndef Online
  TimeEnd = chrono::steady_clock::now();
  auto ElapsedTime = TimeEnd - TimeStart;
  cout << "\n\nTime elapsed: " << chrono::duration<double>(ElapsedTime).count()
       << " seconds.\n";
#endif
}

Fixed submission:
// Optimise
#include <bits/stdc++.h>
using namespace std;

#define Online 1
// #define multitest 1
#define Debug 1
void ControlIO();
void TimerStart();
void TimerStop();
#ifdef Debug
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1> void ZZ(const char *name, Arg1 &&arg1) {
  std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  std::cerr.write(names, comma - names) << " = " << arg1;
  ZZ(comma, args...);
}
#else
#define db(...)
#endif
typedef long long ll;
typedef long double ld;
#define f first
#define s second
#define pb push_back
const long long mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll power(int base, int index) {
  if (index == 0)
    return 1;
  ll temp = power(base, index / 2);
  temp = (temp * temp) % mod;
  if (index & 1)
    temp = (temp * base) % mod;
  return temp;
}

int n, a, b, c;

int _n = 2e5 + 10;
vector<ll> Fact(_n), Inv(_n);
int kmod = 1000000007;

void pre() {
  Fact[0] = 1;
  for (int i = 1; i < _n; ++i)
    Fact[i] = (Fact[i - 1] * i) % kmod;
  Inv[_n - 1] = power(Fact[_n - 1], kmod - 2);
  for (int i = _n - 2; i >= 0; --i)
    Inv[i] = (Inv[i + 1] * (1 + i)) % kmod;
  // db(Inv[2]*2%mod);
}

ll com(int m) {
  // db(m, n);
  ll x = (Fact[m - 1] * Inv[n - 1]) % mod;
  x *= Inv[m - n];
  x %= mod;
  ll temp = (power(a, n) * power(b, m - n)) % mod +
            (power(a, m - n) * power(b, n)) % mod;
  // db(temp);
  temp %= mod;
  temp *= m;
  // db(temp);
  temp %= mod;
  temp *= x;
  // db(temp);
  return temp % mod;
}

void solve() {
  pre();
  cin >> n >> a >> b >> c;
  ll ans = 0;
  ll div = power(a + b, mod - 2);
  a = (a * div) % mod;
  b = (b * div) % mod;
  for (int i = n; i < 2 * n; ++i) {
    ans += com(i);
    ans %= mod;
  }
  ans *= power(100 - c, mod - 2);
  ans %= mod;
  ans *= 100;
  cout << (ans % mod) << '\n';
}

int main() {
  ControlIO();
  int t = 1;
#ifdef multitest
  cin >> t;
#endif
  TimerStart();
  while (t--)
    solve();
  TimerStop();
  return 0;
}

void ControlIO() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
#ifndef Online
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

auto TimeStart = chrono::steady_clock::now();
auto TimeEnd = chrono::steady_clock::now();

void TimerStart() {
#ifndef Online
  TimeStart = chrono::steady_clock::now();
#endif
}

void TimerStop() {
#ifndef Online
  TimeEnd = chrono::steady_clock::now();
  auto ElapsedTime = TimeEnd - TimeStart;
  cout << "\n\nTime elapsed: " << chrono::duration<double>(ElapsedTime).count()
       << " seconds.\n";
#endif
}