alexjercan/bugnet huggingface dataset:
Problem p02653 (C++) — buggy submission, verdict: Runtime Error

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

const int maxn = 5010, P = 1000000007;
int n, A, B, ans, pw[maxn], f[maxn][maxn][2], pre[maxn][maxn][2], h[maxn];

int main() {
  scanf("%d %d %d", &n, &A, &B);
  if (A < B)
    swap(A, B);
  pw[0] = pw[1] = 1;
  for (int i = 2; i <= n; i++) {
    pw[i] = (pw[i - 1] + pw[i - 1]) % P;
  }
  f[0][0][0] = f[0][0][1] = 1, h[0] = 1;
  pre[0][0][0] = pre[0][0][1] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
      (f[i][j][0] += pre[i - 1][i - j][1]) %= P;
      if (i >= B)
        (f[i][j][1] += pre[i - B][i - j][0]) %= P;
    }
    for (int j = max(0, i - B + 1); j < i; j++) {
      (f[i][0][1] += h[j]) %= P;
    }
    for (int j = A; j <= i; j++) {
      int s = 1LL * (f[i][j][0] + f[i][j][1]) * pw[n - i] % P;
      (ans += s) %= P, f[i][j][0] = f[i][j][1] = 0;
    }
    for (int j = 0; j <= i; j++) {
      (h[i] += f[i][j][0]) %= P;
      pre[i][i - j][0] = (pre[i - 1][i - j][0] + f[i][j][0]) % P;
      pre[i][i - j][1] = (pre[i - 1][i - j][1] + f[i][j][1]) % P;
    }
  }
  printf("%d\\n", (ans + P) % P);
  return 0;
}

Error: -11

Fixed submission:

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

const int maxn = 5010, P = 1000000007;
int n, A, B, ans, pw[maxn], f[maxn][maxn][2], pre[maxn][maxn][2], h[maxn];

int main() {
  scanf("%d %d %d", &n, &A, &B);
  if (A < B)
    swap(A, B);
  pw[0] = pw[1] = 1;
  for (int i = 2; i <= n; i++) {
    pw[i] = (pw[i - 1] + pw[i - 1]) % P;
  }
  f[0][0][0] = f[0][0][1] = 1, h[0] = 1;
  pre[0][0][0] = pre[0][0][1] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
      (f[i][j][0] += pre[i - 1][i - j][1]) %= P;
      (f[i][j][1] += pre[i - B][i - j][0]) %= P;
    }
    for (int j = max(0, i - B + 1); j < i; j++) {
      (f[i][0][1] += h[j]) %= P;
    }
    for (int j = A; j <= i; j++) {
      int s = 1LL * (f[i][j][0] + f[i][j][1]) * pw[n - i] % P;
      (ans += s) %= P, f[i][j][0] = f[i][j][1] = 0;
    }
    for (int j = 0; j <= i; j++) {
      (h[i] += f[i][j][0]) %= P;
      pre[i][i - j][0] = (pre[i - 1][i - j][0] + f[i][j][0]) % P;
      pre[i][i - j][1] = (pre[i - 1][i - j][1] + f[i][j][1]) % P;
    }
  }
  printf("%d\\n", (ans + P) % P);
  return 0;
}
Problem p02653 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;

long long mod = 1000000007;
long long N, A, B;
long long dp[6009][6009][2];
long long ru[6009][6009];
long long power[6009];
long long Answer;

void init() {
  power[0] = 1;
  for (int i = 1; i <= 5000; i++)
    power[i] = (2LL * power[i - 1]) % mod;
}

void solve(int pos) {
  // 累積和を取る
  for (int i = 0; i <= N; i++) {
    ru[pos][i] = ru[pos - 1][i];
    ru[pos][i] += dp[pos - 1][i][0];
    ru[pos][i] %= mod;
  }

  // 長い方を使う場合
  for (int i = 0; i <= N; i++) {
    dp[pos][i][0] += dp[pos - 1][i][1];
    dp[pos][i][0] += dp[pos - 1][i][0];
    dp[pos][i][0] %= mod;
    if ((pos - i) >= A) {
      Answer += dp[pos][i][0] * power[N - pos];
      Answer %= mod;
      dp[pos][i][0] = 0;
    }
  }

  // 短い方を使う場合（そして失敗する場合）
  long long rem = 0;
  for (int i = 0; i <= N; i++) {
    int cl = max(0LL, pos - B + 1), cr = max(-1, pos - 1);
    rem += (ru[cr + 1][i] - ru[cl][i] + mod) % mod;
    rem %= mod;
  }
  dp[pos][pos][1] = rem;

  // 短い方を使う場合（そして成功する場合）
  for (int i = 0; i <= N; i++) {
    int cr = max(-1LL, pos - B);
    long long val = ru[cr + 1][i];
    dp[pos][i][1] += val;
    if ((pos - i) >= A) {
      Answer += dp[pos][i][1] * power[max(0LL, N - pos - 1)];
      Answer %= mod;
      dp[pos][i][1] = 0;
    }
  }
}

int main() {
  cin >> N >> A >> B;
  if (A < B)
    swap(A, B);
  init();

  dp[0][0][0] = 1;
  for (int i = 1; i <= N; i++)
    solve(i);
  cout << Answer << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;

long long mod = 1000000007;
long long N, A, B;
long long dp[6009][6009][2];
long long ru[6009][6009];
long long power[6009];
long long Answer;

void init() {
  power[0] = 1;
  for (int i = 1; i <= 5000; i++)
    power[i] = (2LL * power[i - 1]) % mod;
}

void solve(int pos) {
  // 累積和を取る
  for (int i = 0; i <= N; i++) {
    ru[pos][i] = ru[pos - 1][i];
    ru[pos][i] += dp[pos - 1][i][0];
    ru[pos][i] %= mod;
  }

  // 長い方を使う場合
  for (int i = 0; i <= N; i++) {
    dp[pos][i][0] += dp[pos - 1][i][1];
    dp[pos][i][0] += dp[pos - 1][i][0];
    dp[pos][i][0] %= mod;
    if ((pos - i) >= A) {
      Answer += dp[pos][i][0] * power[N - pos];
      Answer %= mod;
      dp[pos][i][0] = 0;
    }
  }

  // 短い方を使う場合（そして失敗する場合）
  long long rem = 0;
  for (int i = 0; i <= N; i++) {
    int cl = pos - B + 1, cr = pos - 1;
    rem += (ru[cr + 1][i] - ru[cl][i] + mod) % mod;
    rem %= mod;
  }
  dp[pos][pos][1] = rem;

  // 短い方を使う場合（そして成功する場合）
  for (int i = 0; i <= N; i++) {
    int cr = pos - B;
    long long val = ru[cr + 1][i];
    dp[pos][i][1] += val;
    if ((pos - i) >= A) {
      Answer += dp[pos][i][1] * power[max(0LL, N - pos - 1)];
      Answer %= mod;
      dp[pos][i][1] = 0;
    }
  }
}

int main() {
  cin >> N >> A >> B;
  if (A < B)
    swap(A, B);
  init();

  dp[0][0][0] = 1;
  for (int i = 1; i <= N; i++)
    solve(i);
  cout << Answer << endl;
  return 0;
}
Problem p02653 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
#define mod 1000000007
#define maxn 5010

int n, a, b;
int ksm(int x, int y) {
  int re = 1;
  for (; (y & 1 ? re = 1ll * re * x % mod : 0), y;
       y >>= 1, x = 1ll * x * x % mod)
    ;
  return re;
}
int g[maxn][2], f[maxn][2];
void add(int &x, int y) { x = (x + y >= mod ? x + y - mod : x + y); }

int main() {
  scanf("%d %d %d", &n, &a, &b);
  if (a > b)
    swap(a, b);
  g[1][1] = 1;
  for (int i = 2; i < b; i++) {
    g[i][1] = (g[i - 1][0] + g[i - 1][1]) % mod;
    for (int j = a; j < i; j++)
      add(g[i][0], g[i - j][1]);
  }
  f[0][0] = f[0][1] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j < min(a, i + 1); j++)
      add(f[i][0], f[i - j][1]);
    for (int j = 1; j < min(b, i + 1); j++) {
      if (i == n)
        add(f[i][0], 1ll * f[i - j][0] * g[j][0] % mod);
      if (i == j)
        add(f[i][1], (g[j][0] + g[j][1]) % mod);
      else
        add(f[i][1], 1ll * f[i - j][0] * g[j][1] % mod);
    }
  }
  printf("%d", (ksm(2, n) - (f[n][0] + f[n][1]) % mod + mod) % mod);
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
#define mod 1000000007
#define maxn 1010

int n, a, b;
int ksm(int x, int y) {
  int re = 1;
  for (; (y & 1 ? re = 1ll * re * x % mod : 0), y;
       y >>= 1, x = 1ll * x * x % mod)
    ;
  return re;
}
int g[maxn][2], f[maxn][2];
void add(int &x, int y) { x = (x + y >= mod ? x + y - mod : x + y); }

int main() {
  scanf("%d %d %d", &n, &a, &b);
  if (a > b)
    swap(a, b);
  g[1][1] = 1;
  for (int i = 2; i < b; i++) {
    g[i][1] = (g[i - 1][0] + g[i - 1][1]) % mod;
    for (int j = a; j < i; j++)
      add(g[i][0], g[i - j][1]);
  }
  f[0][0] = f[0][1] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j < min(a, i + 1); j++)
      add(f[i][0], f[i - j][1]);
    for (int j = 1; j < min(b, i + 1); j++) {
      if (i == n)
        add(f[i][0], 1ll * f[i - j][0] * g[j][0] % mod);
      if (i == j)
        add(f[i][1], (g[j][0] + g[j][1]) % mod);
      else
        add(f[i][1], 1ll * f[i - j][0] * g[j][1] % mod);
    }
  }
  printf("%d", (ksm(2, n) - (f[n][0] + f[n][1]) % mod + mod) % mod);
}
Problem p02653 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
int dp0[5005][5005], dp1[5005][5005], dp2[5005][5005], sum1[5005][5005];
int main() {
  int n, a, b;
  scanf("%d%d%d", &n, &a, &b);
  if (a > b)
    swap(a, b);
  dp1[0][0] = 1;
  for (int j = 0; j <= n; j++)
    sum1[0][j] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= a - 1; j++)
      if (i - j >= 0)
        dp0[i][0] = (dp0[i][0] + sum1[i - j][n]) % mod;
    if (i >= a)
      for (int j = 0; j <= b - a - 1; j++)
        dp2[i][j + a] = (dp2[i][j + a] + dp1[i - a][j]) % mod;

    for (int j = 0; j < b - 1; j++) {
      dp2[i][j + 1] = (dp2[i][j + 1] + dp2[i - 1][j]) % mod;
    }
    for (int j = 0; j < b - 1; j++) {
      dp1[i][j + 1] = (dp1[i][j + 1] + dp0[i - 1][j]) % mod;
      dp1[i][j + 1] = (dp1[i][j + 1] + dp1[i - 1][j]) % mod;
      dp1[i][j + 1] = (dp1[i][j + 1] + dp2[i - 1][j]) % mod;
    }

    for (int j = 0; j <= n; j++) {
      if (j == 0)
        sum1[i][j] = dp1[i][j];
      else
        sum1[i][j] = (sum1[i][j - 1] + dp1[i][j]) % mod;
    }
  }
  int ans = 1;
  for (int i = 1; i <= n; i++)
    ans = ans * 2 % mod;
  for (int j = 0; j <= n; j++) {
    ans = (ans - dp0[n][j] + mod) % mod;
    ans = (ans - dp1[n][j] + mod) % mod;
    ans = (ans - dp2[n][j] + mod) % mod;
  }
  printf("%d\\n", ans);
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
int dp0[5005][5005], dp1[5005][5005], dp2[5005][5005], sum1[5005][5005];
int main() {
  int n, a, b;
  scanf("%d%d%d", &n, &a, &b);
  if (a > b)
    swap(a, b);
  dp1[0][0] = 1;
  for (int j = 0; j <= n; j++)
    sum1[0][j] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= a - 1; j++)
      dp0[i][0] = (dp0[i][0] + sum1[i - j][n]) % mod;
    for (int j = 0; j <= b - a - 1; j++)
      dp2[i][j + a] = (dp2[i][j + a] + dp1[i - a][j]) % mod;

    for (int j = 0; j < b - 1; j++) {
      dp2[i][j + 1] = (dp2[i][j + 1] + dp2[i - 1][j]) % mod;
    }
    for (int j = 0; j < b - 1; j++) {
      dp1[i][j + 1] = (dp1[i][j + 1] + dp0[i - 1][j]) % mod;
      dp1[i][j + 1] = (dp1[i][j + 1] + dp1[i - 1][j]) % mod;
      dp1[i][j + 1] = (dp1[i][j + 1] + dp2[i - 1][j]) % mod;
    }

    for (int j = 0; j <= n; j++) {
      if (j == 0)
        sum1[i][j] = dp1[i][j];
      else
        sum1[i][j] = (sum1[i][j - 1] + dp1[i][j]) % mod;
    }
  }
  int ans = 1;
  for (int i = 1; i <= n; i++)
    ans = ans * 2 % mod;
  for (int j = 0; j <= n; j++) {
    ans = (ans - dp0[n][j] + mod) % mod;
    ans = (ans - dp1[n][j] + mod) % mod;
    ans = (ans - dp2[n][j] + mod) % mod;
  }
  printf("%d\\n", ans);
}
Problem p02653 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;

const int N = 5200;
const int MOD = 1e9 + 7;

int dp[N][2];
int dp1[N][2];

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  if (a > b)
    swap(a, b);
  dp1[0][0] = 1;
  for (int i = 1; i < b; i++) {
    for (int j = a; j <= i; j++) {
      dp1[i][0] = (dp1[i][0] + dp1[i - j][1]) % MOD;
    }
    dp1[i][1] = (dp1[i - 1][0] + dp1[i - 1][1]) % MOD;
  }

  dp[0][1] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j < a && j <= i; j++) {
      dp[i][0] = (dp[i][0] + dp[i - j][1]) % MOD;
    }
    for (int j = 1; j < b && j <= i; j++) {
      dp[i][1] = (dp[i][1] + 1ll * dp[i - j][0] * dp1[j][1]) % MOD;
    }
    // cout << i << " " << dp[i][0] << " " << dp[i][1] << "\\n";
  }
  int ans = 1;
  for (int i = 0; i < n; i++)
    ans = (ans + ans) % MOD;

  for (int p = 0; p < b; p++) {
    for (int s = 0; s < b && s + p < n; s++) {
      ans = (ans - 1ll * (dp1[p][1] + dp1[p][0]) * (dp1[s][1] + dp1[s][0]) %
                       MOD * dp[n - p - s][0]) %
            MOD;
      ans = (ans + MOD) % MOD;
    }
  }

  cout << ans;
}

/*

*/


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;

const int N = 5200;
const int MOD = 1e9 + 7;

int dp[N][N][2];
int summover[N][2];

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  if (a > b)
    swap(a, b);
  dp[0][0][1] = 1;
  summover[0][1] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j < a && j <= i; j++) {
      dp[i][0][0] = (dp[i][0][0] + summover[i - j][1]) % MOD;
    }
    for (int j = a; j <= b && j <= i; j++) {
      for (int h = 0; h < b; h++) {
        dp[i][h + j][0] = (dp[i][h + j][0] + dp[i - j][h][1]) % MOD;
      }
    }
    for (int j = 1; j <= b; j++) {
      dp[i][j][1] = (dp[i][j][1] + dp[i - 1][j - 1][1]) % MOD;
      dp[i][j][1] = (dp[i][j][1] + dp[i - 1][j - 1][0]) % MOD;
    }
    for (int j = 0; j < b; j++)
      summover[i][0] = (summover[i][0] + dp[i][j][0]) % MOD;
    for (int j = 0; j < b; j++)
      summover[i][1] = (summover[i][1] + dp[i][j][1]) % MOD;
  }
  int ans = 1;
  for (int i = 0; i < n; i++)
    ans = (ans + ans) % MOD;
  cout << (1ll * ans + 2ll * MOD - (summover[n][0] + summover[n][1])) % MOD;
}

/*

*/
Problem p02653 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define Tp template <typename Ty>
#define Ts template <typename Ty, typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int &
#define I inline
#define W while
#define N 5000
#define X 1000000007
#define Inc(x, y) ((x += (y)) >= X && (x -= X))
#define swap(x, y) (x ^= y ^= x ^= y)
using namespace std;
int n, a, b, f[N + 5][2], g[N + 5], w[N + 5][2];
I int QP(RI x, RI y) {
  RI t = 1;
  W(y) y & 1 && (t = 1LL * t * x % X), x = 1LL * x * x % X, y >>= 1;
  return t;
}
int main() {
  RI i, j, t;
  if (scanf("%d%d%d", &n, &a, &b), t = QP(2, n), a > b && swap(a, b), a == 1)
    return printf("%d\\n", t), 0;
  for (f[0][0] = f[0][1] = i = 1; i <= n; ++i)
    for (j = 1; j <= i; ++j)
      j >= a &&Inc(f[i][0], f[i - j][1]), Inc(f[i][1], f[i - j][0]);
  for (g[0] = i = 1; i <= n; ++i)
    g[i] = (f[i][0] + f[i][1]) % X;
  for (i = 1; i ^ n; ++i) {
    for (i < a && (w[i][0] = 1), j = 1; j ^ min(i, a); ++j)
      Inc(w[i][0], w[i - j][1]);
    for (i < b && (w[i][1] = g[i - 1]), j = 1; j ^ min(i, b); ++j)
      Inc(w[i][1], (j <= 2 ? 1LL : 1LL * g[j - 2]) * w[i - j][0] % X);
    n - i < a &&Inc(t, X - w[i][1]),
        n - i < b &&Inc(t, X - 1LL * w[i][0] * g[n - i - 1] % X);
  }
  return printf("%d\\n", t), 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define Tp template <typename Ty>
#define Ts template <typename Ty, typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int &
#define I inline
#define W while
#define N 200
#define LN 63
#define ull unsigned long long
using namespace std;
int n;
ull a[N + 5], v[LN + 5];
char op[N + 5];
I void Clear() {
  for (RI i = LN; ~i; --i)
    v[i] = 0;
}
I void Ins(ull x) {
  for (RI i = LN; ~i; --i)
    if ((x >> i) & 1) {
      if (!v[i])
        return (void)(v[i] = x);
      x ^= v[i];
    }
}
I bool Q(ull x) {
  for (RI i = LN; ~i; --i)
    if ((x >> i) & 1) {
      if (!v[i])
        return 0;
      x ^= v[i];
    }
  return 1;
}
int main() {
  RI Tt, i, ans;
  scanf("%d", &Tt);
  W(Tt--) {
    for (Clear(), scanf("%d", &n), i = 1; i <= n; ++i)
      scanf("%llu", a + i);
    for (scanf("%s", op + 1), ans = 1, i = n; i; --i)
      if (op[i] == '1') {
        if (!Q(a[i])) {
          ans = 0;
          break;
        }
      } else
        Ins(a[i]);
    putchar(49 - ans), putchar('\\n');
  }
  return 0;
}
Problem p02653 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
int M(int x) { return x >= mod ? x - mod : x; }
void Add(int &x, int y) { (x += y) >= mod ? x -= mod : x; }

int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
int n, A, B;
int f[5003][5003], g[5003][5003];
int pf[10004][5003], pg[10004][5003];

int S(int *p, int l, int r) { return M(p[r] - (l > 0 ? p[l - 1] : 0) + mod); }

int main() {
  // clock_t c = clock();
  // cerr << clock() - c << endl;
  n = read(), A = read(), B = read();
  if (A > B)
    swap(A, B);
  int res = 1;
  for (int i = 1; i <= n; ++i)
    res = M(res << 1);
  if (A == 1)
    return printf("%d\\n", res), 0;

  for (int i = 1; i <= B; ++i)
    f[0][i] = pf[i + n][0] = g[0][i] = pg[i + n][0] = 1;

  for (int i = 1; i <= n; ++i) {
    int s = 0;
    for (int x = 1; x <= min(A - 1, i); ++x)
      Add(s, g[i - x][B]);
    for (int j = 1; j <= B; ++j) {
      f[i][j] = pf[j - i + n][i] = M(s + S(pg[j - i + n], i - j, i - A));
      g[i][j] = pg[j - i + n][i] = S(pf[j - i + n], i - j, i - 1);
    }

    for (int j = n - i + 1; j <= B + n - i - 1; ++j)
      Add(pf[j][i], pf[j][i - 1]), Add(pg[j][i], pg[j][i - 1]);
  }
  printf("%d\\n", M(res + mod - M(g[n][B] + f[n][B])));
  // cerr << clock() - c << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
int M(int x) { return x >= mod ? x - mod : x; }
void Add(int &x, int y) { (x += y) >= mod ? x -= mod : x; }

int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
int n, A, B;
int f[5003][5003], g[5003][5003];
int pf[10004][5003], pg[10004][5003];

int S(int *p, int l, int r) { return M(p[r] - (l > 0 ? p[l - 1] : 0) + mod); }

int main() {
  n = read(), A = read(), B = read();
  if (A > B)
    swap(A, B);
  int res = 1;
  for (int i = 1; i <= n; ++i)
    res = M(res << 1);
  if (A == 1)
    return printf("%d\\n", res), 0;

  for (int i = 1; i <= B; ++i)
    f[0][i] = pf[i + n][0] = g[0][i] = pg[i + n][0] = 1;
  for (int i = 1; i <= n; ++i) {
    int s = 0;
    for (int x = 1; x <= min(A - 1, i); ++x)
      Add(s, g[i - x][B]);
    for (int j = 1; j <= B; ++j) {
      f[i][j] = pf[j - i + n][i] = M(s + S(pg[j - i + n], i - j, i - A));
      g[i][j] = pg[j - i + n][i] = S(pf[j - i + n], i - j, i - 1);
    }
    // cerr << "##" << i << endl;
    // for (int j = 1; j <= B; ++j) cerr << f[i][j] << ' ';
    // cerr << endl;
    // for (int j = 1; j <= B; ++j) cerr << g[i][j] << ' ';
    // cerr << endl;

    for (int j = 1; j <= B + n; ++j)
      Add(pf[j][i], pf[j][i - 1]), Add(pg[j][i], pg[j][i - 1]);
  }
  printf("%d\\n", M(res + mod - M(g[n][B] + f[n][B])));
  return 0;
}
Problem p02653 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
using namespace std;
typedef long long LL;
const int N = 5005, P = 1e9 + 7;
int n, A, B, f[N], g[N][2];
int fpow(int k1, int k2) {
  int k3 = 1;
  for (; k2; k2 >>= 1, k1 = 1LL * k1 * k1 % P)
    if (k2 & 1)
      k3 = 1LL * k3 * k1 % P;
  return k3;
}
int main() {
  cin >> n >> A >> B;
  if (A > B)
    swap(A, B);
  f[1] = 1;
  rep(i, 1, B - 1) {
    (f[i + 1] += f[i]) %= P;
    rep(j, i + A + 1, B)(f[j] += f[i]) %= P;
  }
  //	printf(">>> %d %d\\n",A,B);
  //	rep(i,1,B)printf("%d ",f[i]);puts("");
  rep(i, 1, B - 1) g[i][0] = f[i + 1];
  rep(i, 1, A - 1) g[i][1] = 1;
  rep(i, 1, n) {
    rep(j, i + 1, min(n, i + B - 1)) if (j == n)(
        g[j][0] += 1LL * g[i][1] * f[j - i + 1] % P) %= P;
    else(g[j][0] += 1LL * g[i][1] * f[j - i] % P) %= P;
    rep(j, i + 1, min(n, i + A - 1))(g[j][1] += g[i][0]) %= P;
    //		printf("g[%d][0]=%d g[%d][1]=%d\\n",i,g[i][0],i,g[i][1]);
  }
  printf("%lld\\n", ((LL)fpow(2, n) - g[n][0] - g[n][1] + P + P) % P);
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
using namespace std;
typedef long long LL;
const int N = 5005, P = 1e9 + 7;
int n, A, B, f[N], g[N][2];
int fpow(int k1, int k2) {
  int k3 = 1;
  for (; k2; k2 >>= 1, k1 = 1LL * k1 * k1 % P)
    if (k2 & 1)
      k3 = 1LL * k3 * k1 % P;
  return k3;
}
int main() {
  cin >> n >> A >> B;
  if (A > B)
    swap(A, B);
  f[1] = 1;
  rep(i, 1, B - 1) {
    (f[i + 1] += f[i]) %= P;
    rep(j, i + A + 1, B)(f[j] += f[i]) %= P;
  }
  //	printf(">>> %d %d\\n",A,B);
  //	rep(i,1,B)printf("%d ",f[i]);puts("");
  rep(i, 1, B - 1) g[i][0] = f[i + 1];
  rep(i, 1, A - 1) g[i][1] = 1;
  rep(i, 1, n) {
    rep(j, i + 1, i + B - 1) if (j == n)(g[j][0] +=
                                         1LL * g[i][1] * f[j - i + 1] % P) %= P;
    else(g[j][0] += 1LL * g[i][1] * f[j - i] % P) %= P;
    rep(j, i + 1, i + A - 1)(g[j][1] += g[i][0]) %= P;
    //		printf("g[%d][0]=%d g[%d][1]=%d\\n",i,g[i][0],i,g[i][1]);
  }
  printf("%lld\\n", ((LL)fpow(2, n) - g[n][0] - g[n][1] + P + P) % P);
  return 0;
}
Problem p02654 (C++) — buggy submission, verdict: Runtime Error

#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define N 10000100
const int mod = 1e9 + 7;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + c - '0';
    c = getchar();
  }
  return x * f;
}
int n, A, fac[N], inv[N], ans;
int qpow(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1)
      ans = 1LL * ans * a % mod;
    a = 1LL * a * a % mod;
    b >>= 1;
  }
  return ans;
}
void init(int n) {
  fac[0] = 1;
  for (int i = 1; i <= n; ++i) {
    fac[i] = 1LL * fac[i - 1] * i % mod;
  }
  inv[n] = qpow(fac[n], mod - 2);
  for (int i = n - 1; i >= 0; --i) {
    inv[i] = 1LL * inv[i + 1] * (i + 1) % mod;
  }
}
inline int C(int n, int m) {
  return 1LL * fac[n] * inv[m] % mod * inv[n - m] % mod;
}
inline int calc(int a, int b, int c) {
  return !(a + b) ? 0
                  : 1LL * fac[a + b + c] * a % mod * inv[a + b] % mod *
                        fac[a + b - 1] % mod;
}
int main() {
  n = read(), A = read();
  init(n);
  for (int i = 1; i <= A + 1; ++i) {
    for (int j = 0; j < i; ++j) {
      ans = (ans +
             (j & 1 ? -1 : 1) * 1LL * C(i - 1, j) *
                 calc(i - j - 1, n - A, max(0, A - i)) % mod +
             mod) %
            mod;
    }
  }
  printf("%d\\n", ans);
  return 0;
}


Error: 0

Fixed submission:

#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define N 10000100
const int mod = 1e9 + 7;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + c - '0';
    c = getchar();
  }
  return x * f;
}
int n, A, fac[N], inv[N], ans;
int qpow(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1)
      ans = 1LL * ans * a % mod;
    a = 1LL * a * a % mod;
    b >>= 1;
  }
  return ans;
}
int init(int n) {
  fac[0] = 1;
  for (int i = 1; i <= n; ++i) {
    fac[i] = 1LL * fac[i - 1] * i % mod;
  }
  inv[n] = qpow(fac[n], mod - 2);
  for (int i = n - 1; i >= 0; --i) {
    inv[i] = 1LL * inv[i + 1] * (i + 1) % mod;
  }
}
inline int C(int n, int m) {
  return 1LL * fac[n] * inv[m] % mod * inv[n - m] % mod;
}
inline int calc(int a, int b, int c) {
  return !(a + b) ? 0
                  : 1LL * fac[a + b + c] * a % mod * inv[a + b] % mod *
                        fac[a + b - 1] % mod;
}
int main() {
  n = read(), A = read();
  init(n);
  for (int i = 1; i <= A + 1; ++i) {
    for (int j = 0; j < i; ++j) {
      ans = (ans +
             (j & 1 ? -1 : 1) * 1LL * C(i - 1, j) *
                 calc(i - j - 1, n - A, max(0, A - i)) % mod +
             mod) %
            mod;
    }
  }
  printf("%d\\n", ans);
  return 0;
}