prithivMLmods/Coder-Stat huggingface dataset:
Problem p03825 (C++)

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

using namespace std;

const int N = 2345, mod = 1e9 + 7;

void add(int &x, int y) {
  x += y;
  if (x >= mod) {
    x -= mod;
  }
}

int n, m, k, dp[N][N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> k;
  dp[0][0] = 1;
  int answer = 0;
  for (int i = 1; i <= (n + m - 1) / (k - 1); ++i) {
    for (int j = 0; j <= m; ++j) {
      for (int l = 1; l <= min(j, k - 1); ++l) {
        add(dp[i][j], dp[i - 1][j - l]);
      }
      if (j % (k - 1) == m % (k - 1) && (k - 1) * i - j < n &&
          ((k - 1) * i - j) % (k - 1) == (n - 1) % (k - 1)) {
        add(answer, dp[i][j]);
      }
      add(dp[i][j], dp[i - 1][j]);
    }
  }
  cout << answer << '\n';
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

const int N = 2345, mod = 1e9 + 7;

void add(int &x, int y) {
  x += y;
  if (x >= mod) {
    x -= mod;
  }
}

int n, m, k, dp[N << 1][N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> k;
  dp[0][0] = 1;
  int answer = 0;
  for (int i = 1; i <= (n + m - 1) / (k - 1); ++i) {
    for (int j = 0; j <= m; ++j) {
      for (int l = 1; l <= min(j, k - 1); ++l) {
        add(dp[i][j], dp[i - 1][j - l]);
      }
      if (j % (k - 1) == m % (k - 1) && (k - 1) * i - j < n &&
          ((k - 1) * i - j) % (k - 1) == (n - 1) % (k - 1)) {
        add(answer, dp[i][j]);
      }
      add(dp[i][j], dp[i - 1][j]);
    }
  }
  cout << answer << '\n';
  return 0;
}
Problem p03825 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i, x) for (int i = 0; i < x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
#define mod 1000000007
ll dp[5005][2005], ret;
int n, m, k;
int main() {
  cin >> n >> m >> k;
  dp[0][0] = 1;
  for (int i = 0; i < 5005 / (k - 1); i++) {
    for (int j = 0; j <= m; j++) {
      if (dp[i][j] == 0)
        continue;
      for (int w = 0; w < k; w++) {
        if (j + w > m)
          break;
        dp[i + 1][j + w] = (dp[i + 1][j + w] + dp[i][j]) % mod;
        if (w && (k - 1) * (i + 1) + 1 - (j + w) <= n &&
            (j + w) % (k - 1) == m % (k - 1)) {
          ret += dp[i][j];
        }
      }
    }
  }
  cout << ret % mod << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i, x) for (int i = 0; i < x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
#define mod 1000000007
ll dp[5005][2005], ret;
int n, m, k;
int main() {
  cin >> n >> m >> k;
  dp[0][0] = 1;
  for (int i = 0; i < 5004 / (k - 1); i++) {
    for (int j = 0; j <= m; j++) {
      if (dp[i][j] == 0)
        continue;
      for (int w = 0; w < k; w++) {
        if (j + w > m)
          break;
        dp[i + 1][j + w] = (dp[i + 1][j + w] + dp[i][j]) % mod;
        if (w && (k - 1) * (i + 1) + 1 - (j + w) <= n &&
            (j + w) % (k - 1) == m % (k - 1)) {
          ret += dp[i][j];
        }
      }
    }
  }
  cout << ret % mod << endl;
}
Problem p03825 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
using namespace std;
int n, m, k, f[2005][2005], qz[2005][2005];
const int MOD = 1e9 + 7;
int main() {
  cin >> n >> m >> k;
  f[0][0] = 1;
#define qzz(c)                                                                 \
  qz[c][0] = f[c][0];                                                          \
  for (int r = 1; r <= n; ++r)                                                 \
    qz[c][r] = (qz[c][r - 1] + f[c][r]) % MOD;
  qzz(0) int ml = (n + m - 1) / (k - 1), ans = 0;
  for (int i = 1; i <= ml; ++i) {
    for (int j = 0; j <= n; ++j) {
      int l = max(j - (k - 1), 0);
      f[i][j] = qz[i - 1][j];
      if (l)
        f[i][j] -= qz[i - 1][l - 1];
      f[i][j] %= MOD;
    }
    qzz(i) for (int j = 1; j <= n; ++j) {
      int fn = f[i][j] - f[i - 1][j];
      fn %= MOD;
      if (j % (k - 1) == n % (k - 1) && (k - 1) * i - j < m)
        (ans += fn) %= MOD;
    }
  }
  ans = (ans % MOD + MOD) % MOD;
  printf("%d\n", ans);
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
using namespace std;
int n, m, k, f[5005][5005], qz[5005][5005];
const int MOD = 1e9 + 7;
int main() {
  cin >> n >> m >> k;
  f[0][0] = 1;
#define qzz(c)                                                                 \
  qz[c][0] = f[c][0];                                                          \
  for (int r = 1; r <= n; ++r)                                                 \
    qz[c][r] = (qz[c][r - 1] + f[c][r]) % MOD;
  qzz(0) int ml = (n + m - 1) / (k - 1), ans = 0;
  for (int i = 1; i <= ml; ++i) {
    for (int j = 0; j <= n; ++j) {
      int l = max(j - (k - 1), 0);
      f[i][j] = qz[i - 1][j];
      if (l)
        f[i][j] -= qz[i - 1][l - 1];
      f[i][j] %= MOD;
    }
    qzz(i) for (int j = 1; j <= n; ++j) {
      int fn = f[i][j] - f[i - 1][j];
      fn %= MOD;
      if (j % (k - 1) == n % (k - 1) && (k - 1) * i - j < m)
        (ans += fn) %= MOD;
    }
  }
  ans = (ans % MOD + MOD) % MOD;
  printf("%d\n", ans);
}
Problem p03825 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
template <typename T> inline T read() {
  T f = 0, x = 0;
  char c = getchar();
  while (!isdigit(c))
    f = c == '-', c = getchar();
  while (isdigit(c))
    x = x * 10 + c - 48, c = getchar();
  return f ? -x : x;
}
namespace run {
const int N = 2009, mod = 1e9 + 7;
inline int add(int x, int y) { return x + y >= mod ? x - mod + y : x + y; }
inline int sub(int x, int y) { return x >= y ? x - y : x + mod - y; }
inline int qpow(int x, int y) {
  int ret = 1;
  while (y) {
    if (y & 1)
      ret = 1LL * x * ret % mod;
    x = 1LL * x * x % mod, y >>= 1;
  }
  return ret;
}

int f[N][N << 1][2], n, m, k, len;
int main() {
  n = read<int>(), m = read<int>(), k = read<int>();
  if (!n || !m)
    puts("1"), exit(0);
  len = (n + m - 1) / (k - 1), f[0][0][0] = 1;

  int ans = 0;
  for (int i = 1; i <= len; i++) {
    for (int p = 0; p <= min((i - 1) * (k - 1), m); p++) {
      f[i][p][0] = add(f[i][p][0], add(f[i - 1][p][1], f[i - 1][p][0]));
      for (int j = 1; j < k; j++)
        f[i][j + p][1] =
            add(f[i][j + p][1], add(f[i - 1][p][0], f[i - 1][p][1]));
    }

    for (int j = 0; j <= min(m, i * (k - 1)); j++) {
      int tmp = i * (k - 1) - j + 1;
      if (tmp <= n && j % (k - 1) == m % (k - 1) &&
          tmp % (k - 1) == n % (k - 1))
        ans = add(ans, f[i][j][1]);
    }
  }
  printf("%d\n", ans);
  return 0;
}
} // namespace run
int main() {
#ifdef my
  freopen(".in", "r", stdin);
  freopen(".out", "w", stdout);
#endif
  return run::main();
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
template <typename T> inline T read() {
  T f = 0, x = 0;
  char c = getchar();
  while (!isdigit(c))
    f = c == '-', c = getchar();
  while (isdigit(c))
    x = x * 10 + c - 48, c = getchar();
  return f ? -x : x;
}
namespace run {
const int N = 2009, mod = 1e9 + 7;
inline int add(int x, int y) { return x + y >= mod ? x - mod + y : x + y; }
inline int sub(int x, int y) { return x >= y ? x - y : x + mod - y; }
inline int qpow(int x, int y) {
  int ret = 1;
  while (y) {
    if (y & 1)
      ret = 1LL * x * ret % mod;
    x = 1LL * x * x % mod, y >>= 1;
  }
  return ret;
}

int f[N << 1][N << 1][2], n, m, k, len;
int main() {
  n = read<int>(), m = read<int>(), k = read<int>();
  if (!n || !m)
    puts("1"), exit(0);
  len = (n + m - 1) / (k - 1), f[0][0][0] = 1;

  int ans = 0;
  for (int i = 1; i <= len; i++) {
    for (int p = 0; p <= min((i - 1) * (k - 1), m); p++) {
      f[i][p][0] = add(f[i][p][0], add(f[i - 1][p][1], f[i - 1][p][0]));
      for (int j = 1; j < k; j++)
        f[i][j + p][1] =
            add(f[i][j + p][1], add(f[i - 1][p][0], f[i - 1][p][1]));
    }

    for (int j = 0; j <= min(m, i * (k - 1)); j++) {
      int tmp = i * (k - 1) - j + 1;
      if (tmp <= n && j % (k - 1) == m % (k - 1) &&
          tmp % (k - 1) == n % (k - 1))
        ans = add(ans, f[i][j][1]);
    }
  }
  printf("%d\n", ans);
  return 0;
}
} // namespace run
int main() {
#ifdef my
  freopen(".in", "r", stdin);
  freopen(".out", "w", stdout);
#endif
  return run::main();
}
Problem p03825 (C++)

Buggy submission (status: Time Limit Exceeded):
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr << #v << " = " << v << '\n'
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int, int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(), s.end()
template <class T> T smin(T &a, T b) {
  if (a > b)
    a = b;
  return a;
}
template <class T> T smax(T &a, T b) {
  if (a < b)
    a = b;
  return a;
}
const int mod = 1e9 + 7;
int dp[8096][4048];
int s[8096];
void add(int &x, int y) {
  x = x + y;
  if (x >= mod)
    x -= mod;
}
int main(void) {
  int n, m, k;
  cin >> n >> m >> k;
  dp[0][0] = 1;
  for (int i = 1; i <= 4050; ++i) {
    s[0] = dp[i - 1][0];
    for (int j = 1; j <= m; ++j)
      s[j] = (s[j - 1] + dp[i - 1][j]) % mod;
    for (int j = 0; j <= m; ++j) {
      add(dp[i][j], s[j]);
      if (j >= k)
        add(dp[i][j], mod - s[j - k]);
    }
  }
  int ans = 0;
  for (int t = 1; t < k; ++t)
    for (int i = 0; i <= 4050; ++i)
      for (int j = 0; j <= m; ++j) {
        const int a = j + t;
        const int b = i * (k - 1) - j + (k - t);
        if (a >= 0 && a <= m && b >= 0 && b <= n && !((m - a) % (k - 1)) &&
            !((n - b) % (k - 1)))
          add(ans, dp[i][j]);
      }
  cout << ans << '\n';
  return 0;
}


Fixed submission:
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr << #v << " = " << v << '\n'
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int, int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(), s.end()
template <class T> T smin(T &a, T b) {
  if (a > b)
    a = b;
  return a;
}
template <class T> T smax(T &a, T b) {
  if (a < b)
    a = b;
  return a;
}
const int mod = 1e9 + 7;
int dp[8096][4048];
int s[8096];
void add(int &x, int y) {
  x = x + y;
  if (x >= mod)
    x -= mod;
}
int main(void) {
  int n, m, k;
  cin >> n >> m >> k;
  dp[0][0] = 1;
  for (int i = 1; i <= 4050; ++i) {
    s[0] = dp[i - 1][0];
    for (int j = 1; j <= m; ++j)
      s[j] = (s[j - 1] + dp[i - 1][j]) % mod;
    for (int j = 0; j <= m; ++j) {
      add(dp[i][j], s[j]);
      if (j >= k)
        add(dp[i][j], mod - s[j - k]);
    }
  }
  int ans = 0;
  for (int t = 1; t < k; ++t)
    for (int i = 0; i <= 4050 / (k - 1); ++i)
      for (int j = 0; j <= m; ++j) {
        const int a = j + t;
        const int b = i * (k - 1) - j + (k - t);
        if (a >= 0 && a <= m && b >= 0 && b <= n && !((m - a) % (k - 1)) &&
            !((n - b) % (k - 1)))
          add(ans, dp[i][j]);
      }
  cout << ans << '\n';
  return 0;
}
Problem p03825 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
using namespace std;
int gi() {
  int x = 0, w = 1;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-')
    ch = getchar();
  if (ch == '-')
    w = 0, ch = getchar();
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  return w ? x : -x;
}
const int N = 2005;
const int mod = 1000000007;
int n, m, k, f[N][N][2], sum[N], ans;
int main() {
  n = gi();
  m = gi() - 1;
  k = gi() - 1;
  f[0][0][0] = 1;
  for (int i = 1; i <= max(n, m) << 1; ++i) {
    sum[0] = (f[i - 1][0][0] + f[i - 1][0][1]) % mod;
    for (int j = 1; j <= n; ++j)
      sum[j] = (1ll * sum[j - 1] + f[i - 1][j][0] + f[i - 1][j][1]) % mod;
    for (int j = 0; j <= n; ++j) {
      f[i][j][0] = (sum[j] - sum[j - 1] + mod) % mod;
      int x = max(0, j - k);
      f[i][j][1] = (sum[j - 1] - (x ? sum[x - 1] : 0) + mod) % mod;
    }
    for (int j = 0; j <= n; ++j)
      if (j % k == n % k && (i * k - j) % k == m % k && i * k - j <= m)
        ans = (ans + f[i][j][1]) % mod;
  }
  printf("%d\n", ans);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
using namespace std;
int gi() {
  int x = 0, w = 1;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-')
    ch = getchar();
  if (ch == '-')
    w = 0, ch = getchar();
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  return w ? x : -x;
}
const int N = 2005;
const int mod = 1000000007;
int n, m, k, f[N << 1][N][2], sum[N], ans;
int main() {
  n = gi();
  m = gi() - 1;
  k = gi() - 1;
  f[0][0][0] = 1;
  for (int i = 1; i <= max(n, m) << 1; ++i) {
    sum[0] = (f[i - 1][0][0] + f[i - 1][0][1]) % mod;
    for (int j = 1; j <= n; ++j)
      sum[j] = (1ll * sum[j - 1] + f[i - 1][j][0] + f[i - 1][j][1]) % mod;
    for (int j = 0; j <= n; ++j) {
      f[i][j][0] = (sum[j] - sum[j - 1] + mod) % mod;
      int x = max(0, j - k);
      f[i][j][1] = (sum[j - 1] - (x ? sum[x - 1] : 0) + mod) % mod;
    }
    for (int j = 0; j <= n; ++j)
      if (j % k == n % k && (i * k - j) % k == m % k && i * k - j <= m)
        ans = (ans + f[i][j][1]) % mod;
  }
  printf("%d\n", ans);
  return 0;
}
Problem p03825 (C++)

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

const int M = 2005;
const ll p = 1e9 + 7;

ll n, m, k;
ll ans = 0;
ll dp[2005][2005];
ll part[2005][2005];

int main() {
  cin >> n >> m >> k;
  int l = (n + m - 1) / (k - 1);
  dp[0][0] = 1;
  for (int i = 1; i < 2005; ++i)
    part[0][i] = 1;

  for (int i = 1; i <= l; ++i) {
    for (int j = 0; j <= m; ++j) {
      dp[i][j] =
          (p + part[i - 1][j + 1] - part[i - 1][max(0LL, j + 1 - k)]) % p;
    }

    for (int j = 0; j <= m + 1; ++j)
      part[i][j] = (j == 0) ? 0 : part[i][j - 1] + dp[i][j - 1];
  }

  for (int i = 1; i <= l; ++i)
    ans = (ans + dp[i][m - 1]) % p;
  if (m >= k && m % (k - 1) == 1 % (k - 1)) {
    ans = (ans + p - 1) % p;
  }

  cout << ans << endl;
}

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

const int M = 2005;
const ll p = 1e9 + 7;

ll n, m, k;
ll ans = 0;
ll dp[4005][2005];
ll part[4005][2005];

int main() {
  cin >> n >> m >> k;
  int l = (n + m - 1) / (k - 1);
  dp[0][0] = 1;
  for (int i = 1; i < 2005; ++i)
    part[0][i] = 1;

  for (int i = 1; i <= l; ++i) {
    for (int j = 0; j <= m; ++j) {
      dp[i][j] =
          (p + part[i - 1][j + 1] - part[i - 1][max(0LL, j + 1 - k)]) % p;
    }

    for (int j = 0; j <= m + 1; ++j)
      part[i][j] = (j == 0) ? 0 : part[i][j - 1] + dp[i][j - 1];
  }

  for (int i = 1; i <= l; ++i)
    ans = (ans + dp[i][m - 1]) % p;
  if (m >= k && m % (k - 1) == 1 % (k - 1)) {
    ans = (ans + p - 1) % p;
  }

  cout << ans << endl;
}
Problem p03825 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <vector>

#define Rep(i, n) for (int i = 1; i <= n; i++)
#define Rep0(i, n) for (int i = 0; i <= n; i++)
#define RepG(i, x) for (int i = head[x]; i; i = edge[i].next)
#define v edge[i].to
#define mp(a, b) make_pair(a, b)

using namespace std;

typedef long long LL;
const int N = 4010;
const int mod = 1e9 + 7;
LL f[N][N][2], s[N][N];

int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  f[0][0][0] = 1;
  Rep0(i, n) s[0][i] = 1;
  LL ans = 0;
  Rep(i, max(n, m) * 2) {
    Rep0(j, n) {
      f[i][j][0] = (f[i - 1][j][0] + f[i - 1][j][1]) % mod;
      if (j) {
        if (j - k >= 0)
          f[i][j][1] = (s[i - 1][j - 1] - s[i - 1][j - k] + mod) % mod;
        else
          f[i][j][1] = s[i - 1][j - 1];
      }
      s[i][j] = (f[i][j][0] + f[i][j][1]) % mod;
      if (j)
        s[i][j] = (s[i][j] + s[i][j - 1]) % mod;
    }
    Rep(j, n) if (j % (k - 1) == n % (k - 1) && ((k - 1) * i - j + 1) <= m &&
                  ((k - 1) * i - j + 1) % (k - 1) == m % (k - 1)) {
      ans = (ans + f[i][j][1]) % mod;
    }
  }
  printf("%lld\n", ans);

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <vector>

#define Rep(i, n) for (int i = 1; i <= n; i++)
#define Rep0(i, n) for (int i = 0; i <= n; i++)
#define RepG(i, x) for (int i = head[x]; i; i = edge[i].next)
#define v edge[i].to
#define mp(a, b) make_pair(a, b)

using namespace std;

typedef long long LL;
const int N = 4010;
const int mod = 1e9 + 7;
int f[N][N][2], s[N][N];

int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  f[0][0][0] = 1;
  Rep0(i, n) s[0][i] = 1;
  LL ans = 0;
  Rep(i, max(n, m) * 2) {
    Rep0(j, n) {
      f[i][j][0] = (f[i - 1][j][0] + f[i - 1][j][1]) % mod;
      if (j) {
        if (j - k >= 0)
          f[i][j][1] = (s[i - 1][j - 1] - s[i - 1][j - k] + mod) % mod;
        else
          f[i][j][1] = s[i - 1][j - 1];
      }
      s[i][j] = (f[i][j][0] + f[i][j][1]) % mod;
      if (j)
        s[i][j] = (s[i][j] + s[i][j - 1]) % mod;
    }
    Rep(j, n) if (j % (k - 1) == n % (k - 1) && ((k - 1) * i - j + 1) <= m &&
                  ((k - 1) * i - j + 1) % (k - 1) == m % (k - 1)) {
      ans = (ans + f[i][j][1]) % mod;
    }
  }
  printf("%lld\n", ans);

  return 0;
}
Problem p03825 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>

#define fo(i, a, b) for (int i = a; i <= b; i++)
#define fd(i, a, b) for (int i = a; i >= b; i--)

using namespace std;

typedef long long LL;
typedef double db;

int get() {
  char ch;
  while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-')
    ;
  if (ch == '-') {
    int s = 0;
    while (ch = getchar(), ch >= '0' && ch <= '9')
      s = s * 10 + ch - '0';
    return -s;
  }
  int s = ch - '0';
  while (ch = getchar(), ch >= '0' && ch <= '9')
    s = s * 10 + ch - '0';
  return s;
}

const int N = 2005;
const int mo = 1e9 + 7;

int n, m, k;
int f0[N][N], f1[N][N];

int add(int x, int y) { return x + y >= mo ? x + y - mo : x + y; }

int main() {
  n = get();
  m = get();
  k = get();
  f0[1][0] = 1;
  fo(i, 1, k - 1) f1[1][i] = 1;
  int ans = 0;
  fo(i, 2, (n + m - 1) / (k - 1)) {
    fo(j, 0, m) f0[i][j] = add(f0[i - 1][j], f1[i - 1][j]);
    int pre = f0[i][0];
    fo(j, 1, m) {
      if (j >= k && f0[i][j - k])
        pre = add(pre, mo - f0[i][j - k]);
      f1[i][j] = pre;
      pre = add(pre, f0[i][j]);
    }
  }
  fo(i, 1, (n + m - 1) / (k - 1))
      fo(j, 0, m) if ((k - 1) * i - j < n && j % (k - 1) == m % (k - 1) &&
                      ((k - 1) * i - j) % (k - 1) == (n - 1) % (k - 1)) ans =
          add(ans, f1[i][j]);
  printf("%d\n", ans);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>

#define fo(i, a, b) for (int i = a; i <= b; i++)
#define fd(i, a, b) for (int i = a; i >= b; i--)

using namespace std;

typedef long long LL;
typedef double db;

int get() {
  char ch;
  while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-')
    ;
  if (ch == '-') {
    int s = 0;
    while (ch = getchar(), ch >= '0' && ch <= '9')
      s = s * 10 + ch - '0';
    return -s;
  }
  int s = ch - '0';
  while (ch = getchar(), ch >= '0' && ch <= '9')
    s = s * 10 + ch - '0';
  return s;
}

const int N = 4005;
const int mo = 1e9 + 7;

int n, m, k;
int f0[N][N], f1[N][N];

int add(int x, int y) { return x + y >= mo ? x + y - mo : x + y; }

int main() {
  n = get();
  m = get();
  k = get();
  f0[1][0] = 1;
  fo(i, 1, k - 1) f1[1][i] = 1;
  int ans = 0;
  fo(i, 2, (n + m - 1) / (k - 1)) {
    fo(j, 0, m) f0[i][j] = add(f0[i - 1][j], f1[i - 1][j]);
    int pre = f0[i][0];
    fo(j, 1, m) {
      if (j >= k && f0[i][j - k])
        pre = add(pre, mo - f0[i][j - k]);
      f1[i][j] = pre;
      pre = add(pre, f0[i][j]);
    }
  }
  fo(i, 1, (n + m - 1) / (k - 1))
      fo(j, 0, m) if ((k - 1) * i - j < n && j % (k - 1) == m % (k - 1) &&
                      ((k - 1) * i - j) % (k - 1) == (n - 1) % (k - 1)) ans =
          add(ans, f1[i][j]);
  printf("%d\n", ans);
  return 0;
}
Problem p03825 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
using namespace std;
#define MOD 1000000007
#define MAX 2020
int f[MAX][MAX][2], s[MAX], n, m, K, ans;
void add(int &x, int y) {
  x += y;
  if (x >= MOD)
    x -= MOD;
}
int main() {
  cin >> n >> m >> K;
  m -= 1;
  K -= 1;
  f[0][0][0] = 1;
  for (int i = 1; i <= max(n, m) << 1; ++i) {
    for (int j = 0; j <= n; ++j)
      s[j + 1] = ((s[j] + f[i - 1][j][0]) % MOD + f[i - 1][j][1]) % MOD;
    for (int j = 0; j <= n; ++j) {
      f[i][j][0] = (s[j + 1] - s[j] + MOD) % MOD;
      int k = max(0, j - K);
      f[i][j][1] = (s[j] - s[k] + MOD) % MOD;
    }
    for (int j = 0; j <= n; ++j)
      if (j % K == n % K && (i * K - j) % K == m % K && i * K - j <= m)
        add(ans, f[i][j][1]);
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <cstdio>
#include <iostream>
using namespace std;
#define MOD 1000000007
#define MAX 2020
int f[MAX << 1][MAX][2], s[MAX], n, m, K, ans;
void add(int &x, int y) {
  x += y;
  if (x >= MOD)
    x -= MOD;
}
int main() {
  cin >> n >> m >> K;
  m -= 1;
  K -= 1;
  f[0][0][0] = 1;
  for (int i = 1; i <= max(n, m) << 1; ++i) {
    for (int j = 0; j <= n; ++j)
      s[j + 1] = ((s[j] + f[i - 1][j][0]) % MOD + f[i - 1][j][1]) % MOD;
    for (int j = 0; j <= n; ++j) {
      f[i][j][0] = (s[j + 1] - s[j] + MOD) % MOD;
      int k = max(0, j - K);
      f[i][j][1] = (s[j] - s[k] + MOD) % MOD;
    }
    for (int j = 0; j <= n; ++j)
      if (j % K == n % K && (i * K - j) % K == m % K && i * K - j <= m)
        add(ans, f[i][j][1]);
  }
  cout << ans << endl;
  return 0;
}
Problem p03825 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2020, mod = 1e9 + 7;
int n, m, k, dp[maxn][maxn], C[maxn][maxn];
void add(int &a, int b) {
  a += b;
  if (a >= mod)
    a -= mod;
}
void pre() {
  for (int i = 0; i < maxn; i++)
    for (int j = 0; j <= i; j++)
      if (!j)
        C[i][j] = 1;
      else {
        add(C[i][j], C[i - 1][j - 1]);
        add(C[i][j], C[i - 1][j]);
      }
}
int nck(int i, int j) {
  if (i < j || j < 0)
    return 0;
  return C[i][j];
}

int solve(int n, int m, int k) {
  int ans = 0, l = (n + m - 1) / (k - 1);
  for (int i = 0; i <= l && m >= i * k; i++) {
    int t = nck(m + l - 1 - i * k, l - 1);
    t = t * 1ll * nck(l, i) % mod;
    if (i & 1)
      add(ans, mod - t);
    else
      add(ans, t);
  }
  return ans;
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin >> n >> m >> k;
  pre();
  int ans = 0;
  while (true) {
    add(ans, solve(n, m, k));
    if (m >= k)
      m -= k - 1;
    else
      break;
  }
  cout << ans;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 6020, mod = 1e9 + 7;
int n, m, k, dp[maxn][maxn], C[maxn][maxn];
void add(int &a, int b) {
  a += b;
  if (a >= mod)
    a -= mod;
}
void pre() {
  for (int i = 0; i < maxn; i++)
    for (int j = 0; j <= i; j++)
      if (!j)
        C[i][j] = 1;
      else {
        add(C[i][j], C[i - 1][j - 1]);
        add(C[i][j], C[i - 1][j]);
      }
}
int nck(int i, int j) {
  if (i < j || j < 0)
    return 0;
  return C[i][j];
}

int solve(int n, int m, int k) {
  int ans = 0, l = (n + m - 1) / (k - 1);
  for (int i = 0; i <= l && m >= i * k; i++) {
    int t = nck(m + l - 1 - i * k, l - 1);
    t = t * 1ll * nck(l, i) % mod;
    if (i & 1)
      add(ans, mod - t);
    else
      add(ans, t);
  }
  return ans;
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin >> n >> m >> k;
  pre();
  int ans = 0;
  while (true) {
    add(ans, solve(n, m, k));
    if (m >= k)
      m -= k - 1;
    else
      break;
  }
  cout << ans;
  return 0;
}
Problem p03825 (C++)

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

int n, m, p, dp[N][N], s[N];
int main() {
  scanf("%d%d%d", &n, &m, &p);
  int i, j, k, l, ans = 0, len = (m + n) / (p - 1);
  dp[0][0] = 1;
  for (i = 1; i <= len; i++) {
    for (j = 1, s[0] = dp[i - 1][0]; j <= n; j++)
      s[j] = (s[j - 1] + dp[i - 1][j]) % mod;
    for (j = 0; j <= n; j++) {
      dp[i][j] = s[j];
      if (j >= p)
        dp[i][j] = (dp[i][j] - s[j - p] + mod) % mod;
    }
    for (j = 0; j <= n; j++) {
      k = i * (p - 1) - j + 1;
      if (k < 0 || k > m)
        continue;
      if ((n - j) % (p - 1) || (m - k) % (p - 1))
        continue;
      for (l = 1; l < p && l <= j; l++)
        ans = (ans + dp[i - 1][j - l]) % mod;
    }
  }
  printf("%d\n", ans);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define mod 1000000007
#define N 4009
using namespace std;

int n, m, p, dp[N][N], s[N];
int main() {
  scanf("%d%d%d", &n, &m, &p);
  int i, j, k, l, ans = 0, len = (m + n) / (p - 1);
  dp[0][0] = 1;
  for (i = 1; i <= len; i++) {
    for (j = 1, s[0] = dp[i - 1][0]; j <= n; j++)
      s[j] = (s[j - 1] + dp[i - 1][j]) % mod;
    for (j = 0; j <= n; j++) {
      dp[i][j] = s[j];
      if (j >= p)
        dp[i][j] = (dp[i][j] - s[j - p] + mod) % mod;
    }
    for (j = 0; j <= n; j++) {
      k = i * (p - 1) - j + 1;
      if (k < 0 || k > m)
        continue;
      if ((n - j) % (p - 1) || (m - k) % (p - 1))
        continue;
      for (l = 1; l < p && l <= j; l++)
        ans = (ans + dp[i - 1][j - l]) % mod;
    }
  }
  printf("%d\n", ans);
  return 0;
}
Problem p03826 (C++)

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

#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x)                                                                   \
  int x;                                                                       \
  cin >> x;                                                                    \
  while (x--)
#define pw(b, p) pow(b, p) + 0.1
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

int32_t main() {
  c_p_c();
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if ((a * b) > (c * d)) {
    cout << (a * b);
  } else if ((a * b) < (c * d)) {
    cout << (c * d);
  } else {
    cout << (a * b);
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if ((a * b) > (c * d)) {
    cout << (a * b);
  } else if ((a * b) < (c * d)) {
    cout << (c * d);
  } else {
    cout << (a * b);
  }
  return 0;
}
Problem p03826 (C++)

Buggy submission (status: Runtime Error):
//
// Created by 今村秀明 on 2017/01/20.
//

#include <stdio.h>

int main() {
  int a, b, c, d;
  int s, t;
  scanf("%d %d %d %d", a, b, c, d);
  s = a * b;
  t = c * d;
  if (s == t) {
    printf("%d", s);
  } else if (s > t) {
    printf("%d", s);
  } else {
    printf("%d", t);
  }
  return 0;
}

Fixed submission:
//
// Created by 今村秀明 on 2017/01/20.
//

#include <stdio.h>

int main() {
  int a, b, c, d;
  int s, t;
  scanf("%d %d %d %d", &a, &b, &c, &d);
  s = a * b;
  t = c * d;
  if (s == t) {
    printf("%d", s);
  } else if (s > t) {
    printf("%d", s);
  } else {
    printf("%d", t);
  }
  return 0;
}
Problem p03826 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
int main() {
  int A, B, C, D, area1, area2;
  scanf("%d %d %d %d", A, B, C, D);
  area1 = A * B;
  area2 = C * D;
  if (area1 == area2) {
    printf("%d\n", area1);
  }
  if (area1 > area2) {
    printf("%d\n", area1);
  }
  if (area1 < area2) {
    printf("%d\n", area2);
  }
  return 0;
}

Fixed submission:
#include <stdio.h>
int main() {
  long long a, b, c, d, x, y;
  scanf("%ld %ld %ld %ld", &a, &b, &c, &d);
  x = a * b;
  y = c * d;
  if (x >= y) {
    printf("%ld\n", x);
  } else {
    printf("%ld\n", y);
  }
  return 0;
}
Problem p03826 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, d;
  int sum1, sum2;
  scanf("%d %d %d %d", a, b, c, d);
  sum1 = a * b;
  sum2 = c * d;
  if (sum1 >= sum2)
    cout << sum1;
  if (sum1 < sum2)
    cout << sum2;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, d;
  scanf("%d %d %d %d", &a, &b, &c, &d);
  if (a * b > c * d) {
    printf("%d", a * b);
  } else if (a * b < c * d) {
    printf("%d", c * d);
  } else {
    printf("%d", a * b);
  }
}
Problem p03827 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"

using namespace std;

int main() {
  int N;
  cin >> N;
  char S[10];
  cin >> S;
  int x = 0;
  int ans = 0;

  for (int i = 0; i < N; i++) {
    if (S[i] == 'I') {
      x++;
      ans = max(x, ans);
    } else {
      x--;
      ans = max(x, ans);
    }
  }

  cout << ans << endl;
  return 0;
}

Fixed submission:
#include "bits/stdc++.h"

using namespace std;

int main() {
  int N;
  cin >> N;
  char S[100];
  cin >> S;
  int x = 0;
  int ans = 0;

  for (int i = 0; i < N; i++) {
    if (S[i] == 'I') {
      x++;
      ans = max(x, ans);
    } else {
      x--;
      ans = max(x, ans);
    }
  }

  cout << ans << endl;
  return 0;
}
Problem p03827 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>

int main() {
  printf(" ");
  int total = 0, total_max = 0, n;
  char s[1000];
  scanf("%s", &n);
  scanf("%s", s);
  for (int i = 0; i < n; i++) {
    if (s[i] == 'I') {
      total++;
    } else if (s[i] == 'D') {
      total--;
    }
    if (total_max < total) {
      total_max = total;
    }
  }
  printf("%d\n", total_max);
}


Fixed submission:
#include <stdio.h>

int main() {
  printf(" ");
  int total = 0, total_max = 0, n;
  char s[10000];
  scanf("%d", &n);
  scanf("%s", s);
  for (int i = 0; i < n; i++) {
    if (s[i] == 'I') {
      total++;
    } else if (s[i] == 'D') {
      total--;
    }
    if (total_max < total) {
      total_max = total;
    }
  }
  printf("%d\n", total_max);
}
Problem p03827 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  vector<int> sum_list;
  int n;
  int prevnum = 0;
  string str;
  cin >> n >> str;
  for (auto i = str.begin(); i != str.end(); i++) {
    if (*i == 'I') {
      prevnum++;
      sum_list.push_back(prevnum);
    } else {
      prevnum--;
    }
  }
  int max = *max_element(sum_list.begin(), sum_list.end());
  cout << max << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  vector<int> sum_list;
  int n;
  int prevnum = 0;
  string str;
  cin >> n >> str;
  sum_list.push_back(0);
  for (auto i = str.begin(); i != str.end(); i++) {
    if (*i == 'I') {
      prevnum++;
      sum_list.push_back(prevnum);
    } else {
      prevnum--;
    }
  }
  int max = *max_element(sum_list.begin(), sum_list.end());
  cout << max << endl;
}
Problem p03827 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define fi first
#define se second
#define all(vc) vc.begin(), vc.end()
#define speed                                                                  \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)
#define DEBUG

using namespace std;

const int N = 1e5 + 7;
const int mod = 1e9 + 7;

int n, x, mx;
string s;

int main() {
  speed;
/// Author: Dilshod--Imomov
#ifdef DEBUG
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif // DEBUG
  cin >> n >> s;
  for (int i = 0; s[i]; i++) {
    if (s[i] == 'I')
      x++;
    else
      x--;
    mx = max(mx, x);
  }
  cout << mx;
}


Fixed submission:
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define fi first
#define se second
#define all(vc) vc.begin(), vc.end()
#define speed                                                                  \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)
#define DEBUG

using namespace std;

const int N = 1e5 + 7;
const int mod = 1e9 + 7;

int n, x, mx;
string s;

int main() {
  speed;
/// Author: Dilshod--Imomov
#ifdef DEBUGd
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif // DEBUG
  cin >> n >> s;
  for (int i = 0; s[i]; i++) {
    if (s[i] == 'I')
      x++;
    else
      x--;
    mx = max(mx, x);
  }
  cout << mx;
}
Problem p03827 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
S = int(input())

max = 0
x = 0

for i in range(N):
    if S[i] == "I":
        x += 1
    else:
        x -= 1
    if x > max:
        max = x

print(max)


Fixed submission:
N = int(input())
S = str(input())

max = 0
x = 0

for i in range(N):
    if S[i] == "I":
        x += 1
    else:
        x -= 1
    if x > max:
        max = x

print(max)
Problem p03827 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstring>
#include <iostream>

using namespace std;

int n;
char s[105];
int ans = 0, temp;

int main() {
  cin >> n >> s;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'I') {
      temp++;
    } else {
      temp--;
    }
    ans = max(ans, temp);
  }
  cout << ans << endl;

  while (1)
    ;

  return 0;
}


Fixed submission:
#include <cstring>
#include <iostream>

using namespace std;

int n;
char s[105];
int ans = 0, temp;

int main() {
  cin >> n >> s;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'I') {
      temp++;
    } else {
      temp--;
    }
    ans = max(ans, temp);
  }
  cout << ans << endl;

  return 0;
}
Problem p03827 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  int x = 0;
  int n;
  string s;
  cin >> n >> s;
  int counter = 0;
  int max = 0;
  for (int i = 0; i < n; i++) {
    if (s.at(n) == 'I') {
      counter++;
    } else {
      counter--;
    }
    if (max < counter)
      max = counter;
  }
  cout << max << endl;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  int x = 0;
  int n;
  string s;
  cin >> n >> s;
  int counter = 0;
  int max = 0;
  for (int i = 0; i < n; i++) {
    if (s.at(i) == 'I') {
      counter++;
    } else {
      counter--;
    }
    if (max < counter)
      max = counter;
  }
  cout << max << endl;
}
Problem p03828 (Python)

Buggy submission (status: Time Limit Exceeded):
import math

N = int(input())
d = math.factorial(N)

k, ans = 1, 1
for i in range(1, N + 1):
    while d % i == 0:
        d //= i
        k += 1
    ans *= k
    k = 1
print(ans % (10**9 + 7))


Fixed submission:
import math

N = int(input())
d = math.factorial(N)

k, ans = 1, 1
for i in range(2, N + 1):
    while d % i == 0:
        d //= i
        k += 1
    ans *= k
    k = 1
print(ans % (10**9 + 7))
Problem p03828 (C++)

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

using namespace std;

using ll = long long;

vector<ll> counts(1001);

// 約数をcountsに入れる
void helper(int n) {
  for (ll i = 2; i * i <= n; i++) {
    if (n % i != 0) {
      continue;
    }
    ll count = 0;
    while (n % i == 0) {
      count++;
      n /= i;
    }
    counts[i] += count;
  }
  if (n > 1) {
    counts[n]++;
  }
}

int main() {
  ll mod = pow(10, 9) + 7;
  ll n;
  cin >> n;
  if (n <= 1) {
    return 1;
  }
  for (ll i = 2; i <= n; i++) {
    helper(i);
  }
  ll v = 1;
  for (ll i = 2; i <= n; i++) {
    v *= (counts[i] + 1);
    v %= mod;
  }
  cout << v << endl;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

vector<ll> counts(1001);

// 約数をcountsに入れる
void helper(int n) {
  for (ll i = 2; i * i <= n; i++) {
    if (n % i != 0) {
      continue;
    }
    ll count = 0;
    while (n % i == 0) {
      count++;
      n /= i;
    }
    counts[i] += count;
  }
  if (n > 1) {
    counts[n]++;
  }
}

int main() {
  ll mod = pow(10, 9) + 7;
  ll n;
  cin >> n;
  for (ll i = 2; i <= n; i++) {
    helper(i);
  }
  ll v = 1;
  for (ll i = 2; i <= n; i++) {
    v *= (counts[i] + 1);
    v %= mod;
  }
  cout << v << endl;
}
Problem p03828 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

const ll MOD = 1e9 + 7;

int main() {
  int N;
  cin >> N;
  ll ans = 1;

  vector<ll> mp(N + 10, 0);

  vector<ll> prime;

  for (ll i = 1; i <= N; i++) { // N以下の素数を列挙する
    bool flag = true;
    ll c = (ll)sqrt((double)i);
    for (ll j = 2; j <= c; j++) {
      if (i % j == 0) {
        flag = false;
      }
    }
    // iが√iまでのいずれかの数字で割り切れたら、iは素数ではない
    if (flag) {
      prime.push_back(i);
    }
  }

  int s = prime.size();
  for (ll i = 1; i <= N; i++) { // N以下の数を全て素因数分解
    for (int j = 0; j < s; j++) {
      ll Quote = prime
          [j]; // iがQuoteで何回割れるのか調べる(Quoteは列挙した全ての素数を動く)
      ll k = i;
      while (k % Quote == 0) {
        k /= Quote;
        mp[Quote]++;
      }
    } // i の素因数分解終了
  }

  for (int k = 0; k <= N; k++) {
    ans *= (mp[k] + 1);
    ans %= MOD;
  }

  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

const ll MOD = 1e9 + 7;

int main() {
  int N;
  cin >> N;
  ll ans = 1;

  vector<ll> mp(N + 10, 0);

  vector<ll> prime;

  for (ll i = 2; i <= N; i++) { // N以下の素数を列挙する
    bool flag = true;
    ll c = (ll)sqrt((double)i);
    for (ll j = 2; j <= c; j++) {
      if (i % j == 0) {
        flag = false;
      }
    }
    // iが√iまでのいずれかの数字で割り切れたら、iは素数ではない
    if (flag) {
      prime.push_back(i);
    }
  }

  int s = prime.size();
  for (ll i = 1; i <= N; i++) { // N以下の数を全て素因数分解
    for (int j = 0; j < s; j++) {
      ll Quote = prime
          [j]; // iがQuoteで何回割れるのか調べる(Quoteは列挙した全ての素数を動く)
      ll k = i;
      while (k % Quote == 0) {
        k /= Quote;
        mp[Quote]++;
      }
    } // i の素因数分解終了
  }

  for (int k = 0; k <= N; k++) {
    ans *= (mp[k] + 1);
    ans %= MOD;
  }

  cout << ans << endl;
  return 0;
}
Problem p03828 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for (ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

void print(const std::vector<int> &v) {
  std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
  std::cout << std::endl;
}

vector<pair<long long, long long>> prime_factorize(long long n) {
  vector<pair<long long, long long>> res;
  for (long long p = 2; p * p <= n; ++p) {
    if (n % p != 0)
      continue; // 因数じゃない
    int num = 0;
    while (n % p == 0) {
      ++num;
      n /= p;
    }
    res.push_back(make_pair(p, num));
  }
  if (n != 1)
    res.push_back(make_pair(n, 1)); // nが素数だった場合
  return res;
}

int main() {
  long long N;
  cin >> N;
  vector<long long> cum(N, 0);

  for (int i = 1; i <= N; i++) {
    auto res = prime_factorize(i);
    // cout << i << endl;
    REP(j, res.size()) { cum[res[j].first - 1] += res[j].second; }
  }
  long long ans = 1;
  for (int i = 1; i <= N; i++) {
    ans *= (cum[i - 1] + 1);
    // cout << cum[i] << endl;
    ans %= MOD;
  }
  cout << ans << endl;
  return 1;
}

Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for (ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

void print(const std::vector<int> &v) {
  std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
  std::cout << std::endl;
}

vector<pair<long long, long long>> prime_factorize(long long n) {
  vector<pair<long long, long long>> res;
  for (long long p = 2; p * p <= n; ++p) {
    if (n % p != 0)
      continue; // 因数じゃない
    int num = 0;
    while (n % p == 0) {
      ++num;
      n /= p;
    }
    res.push_back(make_pair(p, num));
  }
  if (n != 1)
    res.push_back(make_pair(n, 1)); // nが素数だった場合
  return res;
}

int main() {
  long long N;
  cin >> N;
  vector<long long> cum(N, 0);

  for (int i = 1; i <= N; i++) {
    auto res = prime_factorize(i);
    // cout << i << endl;
    REP(j, res.size()) { cum[res[j].first - 1] += res[j].second; }
  }
  long long ans = 1;
  for (int i = 1; i <= N; i++) {
    ans *= (cum[i - 1] + 1);
    // cout << cum[i] << endl;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}
Problem p03828 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  map<int, int> mp;
  for (int i = 2; i <= n; i++) {
    int j = 2;
    while (i > 1) {
      if (i % j == 0) {
        i /= j;
        mp[j]++;
      } else {
        j++;
      }
    }
  }
  long long ans = 1;
  for (auto c : mp) {
    ans *= (c.second + 1);
    ans %= 1000000007;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  map<int, int> mp;
  for (int i = 2; i <= n; i++) {
    int j = 2, k = i;
    while (k > 1) {
      if (k % j == 0) {
        k /= j;
        mp[j]++;
      } else {
        j++;
      }
    }
  }
  long long ans = 1;
  for (auto c : mp) {
    ans *= (c.second + 1);
    ans %= 1000000007;
  }
  cout << ans << endl;
}
Problem p03828 (C++)

Buggy submission (status: Runtime Error):
//-fexec-charset=CP932
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 100
#define THOU 1000
#define FIVEMAX 100000
#define NINEMAX 1000000000
#define TWEMAX 1000000000000
#define rep(i, n) for (int i = 0; i < n; i++)
#define drep(i, n) for (int i = n - 1; i >= 0; i--)
#define arep(i, a, n) for (int i = a; i < n; i++)
#define darep(i, a, n) for (int i = n, i >= a; i--)

vector<pair<ll, ll>> prime_factorize(ll n) {
  vector<pair<ll, ll>> res;
  for (ll a = 2; a * a <= n; a++) {
    if (n % a != 0)
      continue;
    ll ex = 0;
    while (n % a == 0) {
      ex++;
      n /= a;
    }
    res.push_back({a, ex});
  }
  if (n != 1)
    res.push_back({n, 1});
  return res;
}

int main() {
  ll n;
  cin >> n;
  if (n == 1) {
    cout << 1;
    exit(1);
  }
  cin.tie(0);
  ios::sync_with_stdio(false);
  string str;
  vector<int> v(n);
  map<string, int> m;
  pair<int, int> p;
  vector<ll> ex(n + 1, 0);

  for (ll i = 2; i <= n; i++) {
    const auto &res = prime_factorize(i);
    for (auto p : res)
      ex[p.first] += p.second;
  }

  ll res = 1;
  const int MOD = 1000000007;
  arep(i, 2, n + 1) {
    res *= ex[i] + 1;
    res %= MOD;
  }

  cout << res << endl;
  return 0;
}


Fixed submission:
//-fexec-charset=CP932
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 100
#define THOU 1000
#define FIVEMAX 100000
#define NINEMAX 1000000000
#define TWEMAX 1000000000000
#define rep(i, n) for (int i = 0; i < n; i++)
#define drep(i, n) for (int i = n - 1; i >= 0; i--)
#define arep(i, a, n) for (int i = a; i < n; i++)
#define darep(i, a, n) for (int i = n, i >= a; i--)

vector<pair<ll, ll>> prime_factorize(ll n) {
  vector<pair<ll, ll>> res;
  for (ll a = 2; a * a <= n; a++) {
    if (n % a != 0)
      continue;
    ll ex = 0;
    while (n % a == 0) {
      ex++;
      n /= a;
    }
    res.push_back({a, ex});
  }
  if (n != 1)
    res.push_back({n, 1});
  return res;
}

int main() {
  ll n;
  cin >> n;

  cin.tie(0);
  ios::sync_with_stdio(false);
  string str;
  vector<int> v(n);
  map<string, int> m;
  pair<int, int> p;
  vector<ll> ex(n + 1, 0);

  for (ll i = 2; i <= n; i++) {
    const auto &res = prime_factorize(i);
    for (auto p : res)
      ex[p.first] += p.second;
  }

  ll res = 1;
  const int MOD = 1000000007;
  arep(i, 2, n + 1) {
    res *= ex[i] + 1;
    res %= MOD;
  }

  cout << res << endl;
  return 0;
}
Problem p03828 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>
using namespace std;
const static long long MOD = 1e9 + 7;
int main() {
  int n;
  cin >> n;

  vector<int> IsPrime(n + 1, 1);
  IsPrime[0] = 0;
  IsPrime[1] = 0;
  for (int i = 2; i * i <= n; i++)
    if (IsPrime[i])
      for (int j = i * 2; j <= n; j += i)
        IsPrime[j] = 0;
  vector<long long> e;
  long long tmp = 0;

  for (int i = 2; i <= n; i++, tmp = 0) {
    if (IsPrime[i]) {
      for (int j = i; j <= n; j *= i)
        tmp += (long long)n / j;
      e.push_back(tmp);
    }
  }

  long long ans = e.back() + 1;
  e.pop_back();

  for (; !e.empty(); e.pop_back())
    ans = (ans * (e.back() + 1) % MOD) % MOD;
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <iostream>
#include <vector>
using namespace std;
const static long long MOD = 1e9 + 7;
int main() {
  int n;
  cin >> n;

  vector<int> IsPrime(n + 1, 1);
  IsPrime[0] = 0;
  IsPrime[1] = 0;
  for (int i = 2; i * i <= n; i++)
    if (IsPrime[i])
      for (int j = i * 2; j <= n; j += i)
        IsPrime[j] = 0;
  vector<long long> e;
  long long tmp = 0;

  for (int i = 2; i <= n; i++, tmp = 0) {
    if (IsPrime[i]) {
      for (int j = i; j <= n; j *= i)
        tmp += (long long)n / j;
      e.push_back(tmp);
    }
  }

  long long ans;
  if (e.empty())
    ans = 1;
  else {
    ans = e.back() + 1;
    e.pop_back();
  }

  for (; !e.empty(); e.pop_back())
    ans = (ans * (e.back() + 1) % MOD) % MOD;
  cout << ans << endl;
  return 0;
}