Problem p03025 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef tuple<int, int, int> T;

const int MAX_N = (int)2e5 + 5;
const lint MOD = (lint)1e9 + 7;
lint E[MAX_N], inv_pow[MAX_N], ap[MAX_N], bp[MAX_N];
vector<lint> fact, fact_inv, inv;

T ExtendedGcd(int a, int b) {
  if (b == 0)
    return T(1, 0, a);
  int x, y, g;
  tie(x, y, g) = ExtendedGcd(b, a % b);
  return T(y, x - a / b * y, g);
}

void mod_add(lint &a, lint b) { a = (a + b) % MOD; }

lint mod_pow(lint n, lint x) {
  lint res = 1;
  while (x) {
    if (x & 1)
      res = res * n % MOD;
    x >>= 1;
    n = n * n % MOD;
  }
  return res;
}

void createFactInvMod(int n) {
  fact.resize((unsigned int)n + 1);
  fact_inv.resize((unsigned int)n + 1);
  fact[0] = 1;
  for (int i = 1; i <= n; i++)
    fact[i] = fact[i - 1] * i % MOD;
  fact_inv[n] = mod_pow(fact[n], MOD - 2);
  for (int i = n - 1; 0 <= i; i--)
    fact_inv[i] = fact_inv[i + 1] * (i + 1) % MOD;
}

void createInvMod(int n) {
  inv.resize((unsigned int)n + 1);
  createFactInvMod(n);
  inv[0] = 0;
  for (int i = 1; i <= n; i++)
    inv[i] = fact[i - 1] * fact_inv[i] % MOD;
}

lint comb(lint n, lint r) {
  return fact[n] * fact_inv[r] % MOD * fact_inv[n - r] % MOD;
}

int main() {
  ios::sync_with_stdio(false), cin.tie(nullptr);
  lint N, A, B, C, D, ans = 0;
  cin >> N >> A >> B >> C >> D;
  createInvMod(100);
  ap[0] = 1, bp[0] = 1;
  for (lint i = 0; i < 2 * N; i++) {
    ap[i + 1] = ap[i] * A % MOD;
    bp[i + 1] = bp[i] * B % MOD;
    inv_pow[i] = mod_pow(A + B, MOD - i - 1);
    E[i] = 100 * i * inv[100 - C] % MOD;
  }
  for (lint i = N; i < 2 * N; i++) {
    mod_add(ans, (ap[N] * bp[i - N] % MOD + ap[i - N] * bp[N] % MOD) % MOD *
                     E[i] % MOD * inv_pow[i] % MOD * comb(i - 1, N - 1) % MOD);
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef tuple<int, int, int> T;

const int MAX_N = (int)2e5 + 5;
const lint MOD = (lint)1e9 + 7;
lint E[MAX_N], inv_pow[MAX_N], ap[MAX_N], bp[MAX_N];
vector<lint> fact, fact_inv, inv;

T ExtendedGcd(int a, int b) {
  if (b == 0)
    return T(1, 0, a);
  int x, y, g;
  tie(x, y, g) = ExtendedGcd(b, a % b);
  return T(y, x - a / b * y, g);
}

void mod_add(lint &a, lint b) { a = (a + b) % MOD; }

lint mod_pow(lint n, lint x) {
  lint res = 1;
  while (x) {
    if (x & 1)
      res = res * n % MOD;
    x >>= 1;
    n = n * n % MOD;
  }
  return res;
}

void createFactInvMod(int n) {
  fact.resize((unsigned int)n + 1);
  fact_inv.resize((unsigned int)n + 1);
  fact[0] = 1;
  for (int i = 1; i <= n; i++)
    fact[i] = fact[i - 1] * i % MOD;
  fact_inv[n] = mod_pow(fact[n], MOD - 2);
  for (int i = n - 1; 0 <= i; i--)
    fact_inv[i] = fact_inv[i + 1] * (i + 1) % MOD;
}

void createInvMod(int n) {
  inv.resize((unsigned int)n + 1);
  createFactInvMod(n);
  inv[0] = 0;
  for (int i = 1; i <= n; i++)
    inv[i] = fact[i - 1] * fact_inv[i] % MOD;
}

lint comb(lint n, lint r) {
  return fact[n] * fact_inv[r] % MOD * fact_inv[n - r] % MOD;
}

int main() {
  ios::sync_with_stdio(false), cin.tie(nullptr);
  lint N, A, B, C, ans = 0;
  cin >> N >> A >> B >> C;
  createInvMod(max(2 * N, 100LL));
  ap[0] = 1, bp[0] = 1;
  for (lint i = 0; i < 2 * N; i++) {
    ap[i + 1] = ap[i] * A % MOD;
    bp[i + 1] = bp[i] * B % MOD;
    inv_pow[i] = mod_pow(A + B, MOD - i - 1);
    E[i] = 100 * i * inv[100 - C] % MOD;
  }
  for (lint i = N; i < 2 * N; i++) {
    mod_add(ans, (ap[N] * bp[i - N] % MOD + ap[i - N] * bp[N] % MOD) % MOD *
                     E[i] % MOD * inv_pow[i] % MOD * comb(i - 1, N - 1) % MOD);
  }
  cout << ans << endl;
  return 0;
}