Problem p03083 (C++)

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

const int64_t MOD = 1'000'000'007;
int64_t fact[200001], factinv[200001];

int64_t mpow(int64_t x, int64_t y) {
  if (y == 0)
    return 1;
  if (y == 1)
    return x % MOD;
  if (y % 2 == 0)
    return mpow(x * x % MOD, y / 2) % MOD;
  return mpow(x * x % MOD, y / 2) * x % MOD;
}

int64_t comb(int64_t n, int64_t r) {
  if (r > n)
    return 0;
  return fact[n] * factinv[r] % MOD * factinv[n - r] % MOD;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout.setf(ios_base::fixed, ios_base::floatfield);

  int B, W;
  cin >> B >> W;
  if (B == 0) {
    for (int i = 0; i < B + W; i++)
      cout << 0 << endl;
    return 0;
  }
  if (W == 0) {
    for (int i = 0; i < B + W; i++)
      cout << 1 << endl;
    return 0;
  }

  const int64_t half = mpow(2, MOD - 2);
  fact[0] = fact[1] = 1;
  for (int i = 2; i <= 200000; i++)
    fact[i] = i * fact[i - 1] % MOD;
  factinv[200000] = mpow(fact[200000], MOD - 2);
  for (int i = 199999; i >= 0; i--)
    factinv[i] = (i + 1) * factinv[i + 1] % MOD;

  int64_t p[100001], q[100001];
  p[0] = q[0] = 0;
  for (int i = 1; i < B + W; i++) {
    p[i] = p[i - 1];
    q[i] = q[i - 1];
    if (W - 1 >= 0 && i - W >= 0) {
      p[i] =
          (p[i] + comb(i - 1, W - 1) * mpow(half, i - 1) % MOD * half % MOD) %
          MOD;
    }
    if (B - 1 >= 0 && i - B >= 0) {
      q[i] =
          (q[i] + comb(i - 1, B - 1) * mpow(half, i - 1) % MOD * half % MOD) %
          MOD;
    }
  }

  for (int i = 0; i < B + W; i++) {
    cout << (p[i] + (1 - p[i] - q[i] + 2 * MOD) % MOD * half % MOD) % MOD
         << endl;
  }

  return 0;
}

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

const int64_t MOD = 1'000'000'007;
int64_t fact[200001], factinv[200001];

int64_t mpow(int64_t x, int64_t y) {
  if (y == 0)
    return 1;
  if (y == 1)
    return x % MOD;
  if (y % 2 == 0)
    return mpow(x * x % MOD, y / 2) % MOD;
  return mpow(x * x % MOD, y / 2) * x % MOD;
}

int64_t comb(int64_t n, int64_t r) {
  if (r > n)
    return 0;
  return fact[n] * factinv[r] % MOD * factinv[n - r] % MOD;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout.setf(ios_base::fixed, ios_base::floatfield);

  int B, W;
  cin >> B >> W;
  if (B == 0) {
    for (int i = 0; i < B + W; i++)
      cout << 0 << endl;
    return 0;
  }
  if (W == 0) {
    for (int i = 0; i < B + W; i++)
      cout << 1 << endl;
    return 0;
  }

  const int64_t half = mpow(2, MOD - 2);
  fact[0] = fact[1] = 1;
  for (int i = 2; i <= 200000; i++)
    fact[i] = i * fact[i - 1] % MOD;
  factinv[200000] = mpow(fact[200000], MOD - 2);
  for (int i = 199999; i >= 0; i--)
    factinv[i] = (i + 1) * factinv[i + 1] % MOD;

  int64_t p[200001], q[200001];
  p[0] = q[0] = 0;
  for (int i = 1; i < B + W; i++) {
    p[i] = p[i - 1];
    q[i] = q[i - 1];
    if (W - 1 >= 0 && i - W >= 0) {
      p[i] =
          (p[i] + comb(i - 1, W - 1) * mpow(half, i - 1) % MOD * half % MOD) %
          MOD;
    }
    if (B - 1 >= 0 && i - B >= 0) {
      q[i] =
          (q[i] + comb(i - 1, B - 1) * mpow(half, i - 1) % MOD * half % MOD) %
          MOD;
    }
  }

  for (int i = 0; i < B + W; i++) {
    cout << (p[i] + (1 - p[i] - q[i] + 2 * MOD) % MOD * half % MOD) % MOD
         << endl;
  }

  return 0;
}