Problem p03083 (C++)

Buggy submission (status: Runtime Error):
// minamoto
#include <bits/stdc++.h>
#define R register
#define fp(i, a, b) for (R int i = (a), I = (b) + 1; i < I; ++i)
#define fd(i, a, b) for (R int i = (a), I = (b)-1; i > I; --i)
#define go(u) for (int i = head[u], v = e[i].v; i; i = e[i].nx, v = e[i].v)
using namespace std;
char sr[1 << 21], z[20];
int K = -1, Z = 0;
inline void Ot() { fwrite(sr, 1, K + 1, stdout), K = -1; }
void print(R int x) {
  if (K > 1 << 20)
    Ot();
  if (x < 0)
    sr[++K] = '-', x = -x;
  while (z[++Z] = x % 10 + 48, x /= 10)
    ;
  while (sr[++K] = z[Z], --Z)
    ;
  sr[++K] = '\n';
}
const int N = 205, M = 1e5 + 5, P = 1e9 + 7, inv2 = 500000004;
inline int add(R int x, R int y) { return x + y >= P ? x + y - P : x + y; }
inline int dec(R int x, R int y) { return x - y < 0 ? x - y + P : x - y; }
inline int mul(R int x, R int y) { return 1ll * x * y - 1ll * x * y / P * P; }
int ksm(R int x, R int y) {
  R int res = 1;
  for (; y; y >>= 1, x = mul(x, x))
    (y & 1) ? res = mul(res, x) : 0;
  return res;
}
int fac[N], ifac[N], bin[N], pw[N], pb[N], b, w;
inline int C(R int n, R int m) {
  return m > n ? 0 : 1ll * fac[n] * ifac[m] % P * ifac[n - m] % P;
}
int main() {
  //	freopen("testdata.in","r",stdin);
  scanf("%d%d", &b, &w);
  fac[0] = ifac[0] = 1;
  fp(i, 1, b + w) fac[i] = mul(fac[i - 1], i);
  ifac[b + w] = ksm(fac[b + w], P - 2);
  fd(i, b + w - 1, 1) ifac[i] = mul(ifac[i + 1], i + 1);
  bin[0] = 1;
  fp(i, 1, b + w) bin[i] = mul(bin[i - 1], inv2);
  fp(i, 1, b + w) {
    pw[i] = add(pw[i - 1], mul(C(i - 1, w - 1), bin[i]));
    pb[i] = add(pb[i - 1], mul(C(i - 1, b - 1), bin[i]));
    print(add(1ll * (1 + P - pw[i - 1] + P - pb[i - 1]) * inv2 % P, pw[i - 1]));
  }
  return Ot(), 0;
}

Fixed submission:
// minamoto
#include <bits/stdc++.h>
#define R register
#define fp(i, a, b) for (R int i = (a), I = (b) + 1; i < I; ++i)
#define fd(i, a, b) for (R int i = (a), I = (b)-1; i > I; --i)
#define go(u) for (int i = head[u], v = e[i].v; i; i = e[i].nx, v = e[i].v)
using namespace std;
char sr[1 << 21], z[20];
int K = -1, Z = 0;
inline void Ot() { fwrite(sr, 1, K + 1, stdout), K = -1; }
void print(R int x) {
  if (K > 1 << 20)
    Ot();
  if (x < 0)
    sr[++K] = '-', x = -x;
  while (z[++Z] = x % 10 + 48, x /= 10)
    ;
  while (sr[++K] = z[Z], --Z)
    ;
  sr[++K] = '\n';
}
const int N = 2e5 + 5, P = 1e9 + 7, inv2 = 500000004;
inline int add(R int x, R int y) { return x + y >= P ? x + y - P : x + y; }
inline int dec(R int x, R int y) { return x - y < 0 ? x - y + P : x - y; }
inline int mul(R int x, R int y) { return 1ll * x * y - 1ll * x * y / P * P; }
int ksm(R int x, R int y) {
  R int res = 1;
  for (; y; y >>= 1, x = mul(x, x))
    (y & 1) ? res = mul(res, x) : 0;
  return res;
}
int fac[N], ifac[N], bin[N], pw[N], pb[N], b, w;
inline int C(R int n, R int m) {
  return m > n ? 0 : 1ll * fac[n] * ifac[m] % P * ifac[n - m] % P;
}
int main() {
  //	freopen("testdata.in","r",stdin);
  scanf("%d%d", &b, &w);
  fac[0] = ifac[0] = 1;
  fp(i, 1, b + w) fac[i] = mul(fac[i - 1], i);
  ifac[b + w] = ksm(fac[b + w], P - 2);
  fd(i, b + w - 1, 1) ifac[i] = mul(ifac[i + 1], i + 1);
  bin[0] = 1;
  fp(i, 1, b + w) bin[i] = mul(bin[i - 1], inv2);
  fp(i, 1, b + w) {
    pw[i] = add(pw[i - 1], mul(C(i - 1, w - 1), bin[i]));
    pb[i] = add(pb[i - 1], mul(C(i - 1, b - 1), bin[i]));
    print(add(1ll * (1 + P - pw[i - 1] + P - pb[i - 1]) * inv2 % P, pw[i - 1]));
  }
  return Ot(), 0;
}