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

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

int main() {
  long long n, x, ans = 1;
  cin >> n;
  map<int, int> cnt;
  for (int i = 2; i <= n; i++) {
    x = i;
    for (int j = 2; j <= i * i; j++) {
      while (x % j == 0) {
        if (cnt.count(j))
          cnt[j]++;
        else
          cnt[j] = 1;
        x /= j;
      }
    }
    if (x != 1)
      cnt[x] = 1;
  }
  for (int i = 2; i <= n; i++) {
    if (cnt.count(i)) {
      ans *= (cnt[i] + 1);
    }
    ans %= 1000000007;
  }
  cout << ans;
}

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

int main() {
  long long n, x, ans = 1;
  cin >> n;
  map<int, int> cnt;
  for (int i = 2; i <= n; i++) {
    x = i;
    for (int j = 2; j <= i * i; j++) {
      while (x % j == 0) {
        if (cnt.count(j))
          cnt[j]++;
        else
          cnt[j] = 1;
        x /= j;
      }
      if (x == 1)
        break;
    }
    if (x != 1)
      cnt[x] = 1;
  }
  for (int i = 2; i <= n; i++) {
    if (cnt.count(i)) {
      ans *= (cnt[i] + 1);
    }
    ans %= 1000000007;
  }
  cout << ans;
}
Problem p03828 (C++)

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

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

  vector<int> prime(n + 1, 1);

  prime.at(0) = 0;
  prime.at(1) = 0;
  prime.at(2) = 1;

  for (int i = 2; i <= n; i++) {
    if (prime.at(i) == 1) {
      for (int j = 2 * i; j <= n; j += i) {
        prime.at(j) = 0;
      }
    }
  }

  int64_t answer = 1;

  for (int i = 1; i <= n; i++) {
    int x = n;
    if (prime.at(i) == 1) {
      int64_t tmp = 0;
      while (x > 0) {
        tmp += x / i;
        x /= i;
      }

      answer *= (tmp + 1) % (1000000007);
      answer = answer % 1000000007;
    }
  }

  cout << answer << endl;
}


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

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

  vector<int> prime(n + 1, 1);

  prime.at(0) = 0;
  prime.at(1) = 0;

  for (int i = 2; i <= n; i++) {
    if (prime.at(i) == 1) {
      for (int j = 2 * i; j <= n; j += i) {
        prime.at(j) = 0;
      }
    }
  }

  int64_t answer = 1;

  for (int i = 1; i <= n; i++) {
    int x = n;
    if (prime.at(i) == 1) {
      int64_t tmp = 0;
      while (x > 0) {
        tmp += x / i;
        x /= i;
      }

      answer *= (tmp + 1) % (1000000007);
      answer = answer % 1000000007;
    }
  }

  cout << answer << endl;
}
Problem p03829 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n, a, b, x[n], sum = 0;
  scanf("%d %d %d", &n, &a, &b);
  rep(i, n) scanf("%d", x[i]);
  rep(i, n - 1) sum += min(b, a * (x[i + 1] - x[i]));
  printf("%d", sum);
  return 0;
}

Fixed submission:
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  ll x[n], sum = 0;

  rep(i, n) { cin >> x[i]; }
  rep(i, n - 1) { sum += min(b, a * (x[i + 1] - x[i])); }
  cout << sum << endl;
  return 0;
}
Problem p03829 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
int a[10005];
signed main() {
  int n, s, d;
  cin >> n >> s >> d;
  rep(i, n) cin >> a[i];
  int ans = 0;
  rep(i, n - 1) {
    if ((a[i + 1] - a[i]) * s > d)
      ans += d;
    else
      ans += (a[i + 1] - a[i]) * s;
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
int a[100010];
signed main() {
  int n, s, d;
  cin >> n >> s >> d;
  rep(i, n) cin >> a[i];
  int ans = 0;
  rep(i, n - 1) {
    if ((a[i + 1] - a[i]) * s > d)
      ans += d;
    else
      ans += (a[i + 1] - a[i]) * s;
  }
  cout << ans << endl;
}
Problem p03829 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
long long x[10010];
int main() {
  long long a, b, c, i, n, m = 0;
  cin >> n;
  cin >> a >> b;
  for (i = 1; i <= n; i++) {
    cin >> x[i];
  }
  for (i = 1; i < n; i++) {
    c = (x[i + 1] - x[i]) * a;
    if (c < b)
      m += c;
    else
      m += b;
  }
  cout << m << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
long long x[100010];
int main() {
  long long a, b, c, i, n, m = 0;
  cin >> n;
  cin >> a >> b;
  for (i = 1; i <= n; i++) {
    cin >> x[i];
  }
  for (i = 1; i < n; i++) {
    c = (x[i + 1] - x[i]) * a;
    if (c < b)
      m += c;
    else
      m += b;
  }
  cout << m << endl;
  return 0;
}
Problem p03829 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <string.h>
#include <vector>
using namespace std;
const long long INF = 10000000000000LL;
typedef long long ll;
typedef pair<ll, ll> P;
ll N, Ma, Mb, K = 0, C[45];
ll A, B;
ll T, a, b, c, d;
ll ans = 0;
bool h, o;
// bool D[100005];
string str, str2[55][55];
map<string, int> m;
vector<int> v[10];
ll X[10005];
int main() {
  cin >> N >> A >> B;
  cin >> X[0];
  for (int i = 1; i < N; ++i) {
    cin >> X[i];
    ans += min(B, (X[i] - X[i - 1]) * A);
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <string.h>
#include <vector>
using namespace std;
const long long INF = 10000000000000LL;
typedef long long ll;
typedef pair<ll, ll> P;
ll N, Ma, Mb, K = 0, C[45];
ll A, B;
ll T, a, b, c, d;
ll ans = 0;
bool h, o;
// bool D[100005];
string str, str2[55][55];
map<string, int> m;
vector<int> v[10];
ll X[100005];
int main() {
  cin >> N >> A >> B;
  cin >> X[0];
  for (int i = 1; i < N; ++i) {
    cin >> X[i];
    ans += min(B, (X[i] - X[i - 1]) * A);
  }
  cout << ans << endl;
  return 0;
}
Problem p03829 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
#define rep(i, s, n) for (ll i = s; i < n; i++)
#define repe(i, s, n) for (ll i = s; i <= n; i++)
static const ll LL_MAX = (ll)1 << 55;

int main() {
  ll n, a, b;
  scanf("%lld%lld%lld", &n, &a, &b);

  ll ans = 0;
  ll x[100001] = {};
  repe(i, 1, n) {
    scanf("%lld", x[i]);
    if (i >= 2)
      ans += min((x[i] - x[i - 1]) * a, b);
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
#define rep(i, s, n) for (ll i = s; i < n; i++)
#define repe(i, s, n) for (ll i = s; i <= n; i++)
static const ll LL_MAX = (ll)1 << 55;

int main() {
  ll n, a, b;
  scanf("%lld%lld%lld", &n, &a, &b);

  ll ans = 0;
  ll x[100001] = {};
  repe(i, 1, n) {
    scanf("%lld", &x[i]);
    if (i >= 2)
      ans += min((x[i] - x[i - 1]) * a, b);
  }
  cout << ans << endl;
  return 0;
}
Problem p03829 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using ll = long long;

#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define reps(i, x) for (ll i = 1; i <= (int)(x); i++)
#define rrep(i, x) for (ll i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (ll i = (int)(x); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define m0(x) memset(x, 0, sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll, ll>>
#define vpi vector<pair<int, int>>
#define mod 1000000007
using namespace std;
ll n, m;
string s;
ll x[10000];
int main() {
  ll a, b;
  cin >> n >> a >> b;
  rep(i, n) { cin >> x[i]; }
  ll ans = 0;
  rep(i, n - 1) { ans += min((x[i + 1] - x[i]) * a, b); }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using ll = long long;

#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define reps(i, x) for (ll i = 1; i <= (int)(x); i++)
#define rrep(i, x) for (ll i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (ll i = (int)(x); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define m0(x) memset(x, 0, sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll, ll>>
#define vpi vector<pair<int, int>>
#define mod 1000000007
using namespace std;
ll n, m;
string s;
ll x[100000];
int main() {
  ll a, b;
  cin >> n >> a >> b;
  rep(i, n) { cin >> x[i]; }
  ll ans = 0;
  rep(i, n - 1) { ans += min((x[i + 1] - x[i]) * a, b); }
  cout << ans << endl;
  return 0;
}
Problem p03829 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define popcnt(a) __builtin_popcount(a)
#define gcd(a, b) __gcd(a, b)
#define IO()                                                                   \
  assert(freopen("in.in", "rt", stdin)),                                       \
      assert(freopen("out.out", "wt", stdout))
#define FastIO() ios::sync_with_stdio(false), cin.tie(0);
#define debug(x) cout << __LINE__ << ": " << #x << " = " << (x) << endl
#warning do not forget to change size of N and M  and -01 to -02
typedef long long ll;
const ll MOD = 1e9 + 7;
const int N = 1e4 + 9, M = 1e5 + 9, OO = 0x3f3f3f3f;
const double EPS = 1e-10;
inline bool dCMP(const long double &a, const long double &b) {
  return fabsl(a - b) < EPS;
}
ll arr[N];
int main() {

  int n;
  ll a, b, ans = 0;
  scanf("%d%lld%lld", &n, &a, &b);
  for (int i = 0; i < n; ++i)
    scanf("%lld", arr + i);
  for (int i = 1; i < n; ++i) {
    ll A = (arr[i] - arr[i - 1]) * a;
    if (A <= b)
      ans += A;
    else
      ans += b;
  }
  printf("%lld", ans);

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define popcnt(a) __builtin_popcount(a)
#define gcd(a, b) __gcd(a, b)
#define IO()                                                                   \
  assert(freopen("in.in", "rt", stdin)),                                       \
      assert(freopen("out.out", "wt", stdout))
#define FastIO() ios::sync_with_stdio(false), cin.tie(0);
#define debug(x) cout << __LINE__ << ": " << #x << " = " << (x) << endl
#warning do not forget to change size of N and M  and -01 to -02
typedef long long ll;
const ll MOD = 1e9 + 7;
const int N = 1e7 + 9, M = 1e5 + 9, OO = 0x3f3f3f3f;
const double EPS = 1e-10;
inline bool dCMP(const long double &a, const long double &b) {
  return fabsl(a - b) < EPS;
}
ll arr[N];
int main() {

  int n;
  ll a, b, ans = 0;
  scanf("%d%lld%lld", &n, &a, &b);
  for (int i = 0; i < n; ++i)
    scanf("%lld", arr + i);
  for (int i = 1; i < n; ++i) {
    ll A = (arr[i] - arr[i - 1]) * a;
    if (A <= b)
      ans += A;
    else
      ans += b;
  }
  printf("%lld", ans);

  return 0;
}
Problem p03829 (C++)

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

#define int long long

int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int N, A, B;
int X[10000];

signed main() {
  cin >> N >> A >> B;
  for (int i = 0; i < N; i++) {
    cin >> X[i];
  }
  int ans = 0;
  for (int i = 1; i < N; i++) {
    ans += min((X[i] - X[i - 1]) * A, B);
  }
  cout << ans << endl;
  return 0;
}


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

#define int long long

int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int N, A, B;
int X[100000];

signed main() {
  cin >> N >> A >> B;
  for (int i = 0; i < N; i++) {
    cin >> X[i];
  }
  int ans = 0;
  for (int i = 1; i < N; i++) {
    ans += min((X[i] - X[i - 1]) * A, B);
  }
  cout << ans << endl;
  return 0;
}
Problem p03829 (C++)

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

long long n, a, b, x[10001], ans = 0;

int main() {
  cin >> n >> a >> b;

  for (int i = 0; i < n; i++) {
    cin >> x[i];

    if (i >= 1) {
      if ((x[i] - x[i - 1]) * a >= b) {
        ans += b;
      } else {
        ans += (x[i] - x[i - 1]) * a;
      }
    }
  }

  cout << ans;
}

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

long long n, a, b, x[100001], ans = 0;

int main() {
  cin >> n >> a >> b;

  for (int i = 0; i < n; i++) {
    cin >> x[i];

    if (i >= 1) {
      if ((x[i] - x[i - 1]) * a >= b) {
        ans += b;
      } else {
        ans += (x[i] - x[i - 1]) * a;
      }
    }
  }

  cout << ans;
}
Problem p03830 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007

map<long long int, long long int> prime_factor(long long int n) {
  map<long long int, long long int> ret;
  for (long long int i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1)
    ret[n] = 1;
  return ret;
}

int main() {
  long long int ans = 0;
  int n;
  cin >> n;
  map<long long int, long long int> mp;
  for (int i = 1; i <= n; ++i) {
    auto prime_n = prime_factor(i);
    auto begin = prime_n.begin(), end = prime_n.end();
    for (auto iter = begin; iter != end; iter++) {
      mp[iter->first] += iter->second;
    }
  }

  auto begin = mp.begin(), end = mp.end();
  for (auto iter = begin; iter != end; iter++)
    iter->second++;
  ans = begin->second % MOD;
  begin++;
  for (auto iter = begin; iter != end; iter++) {
    ans *= iter->second % MOD;
    ans %= MOD;
  }

  cout << ans << '\n';

  return 0;
}


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

map<long long int, long long int> prime_factor(long long int n) {
  map<long long int, long long int> ret;
  for (long long int i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1)
    ret[n] = 1;
  return ret;
}

int main() {
  long long int ans = 0;
  int n;
  cin >> n;
  if (n == 1) {
    cout << 1 << '\n';
    return 0;
  }
  map<long long int, long long int> mp;
  for (int i = 1; i <= n; ++i) {
    auto prime_n = prime_factor(i);
    auto begin = prime_n.begin(), end = prime_n.end();
    for (auto iter = begin; iter != end; iter++) {
      mp[iter->first] += iter->second;
    }
  }

  auto begin = mp.begin(), end = mp.end();
  for (auto iter = begin; iter != end; iter++)
    iter->second++;
  ans = begin->second % MOD;
  begin++;
  for (auto iter = begin; iter != end; iter++) {
    ans *= iter->second % MOD;
    ans %= MOD;
  }

  cout << ans << '\n';

  return 0;
}
Problem p03830 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
#define N 59
using namespace std;
const int INF = 0x3f3f3f3f;
const long long mod = 1e9 + 7;

int fun(int n) {
  int f[N];
  memset(f, 0, sizeof(f));
  long long ans = 1;
  for (int i = 2; i <= n; i++) {
    int k = i;
    for (int j = 2; j <= k; j++) {
      while (k % j == 0) {
        f[j]++;
        k /= j;
      }
    }
    if (k)
      f[k]++;
  }
  for (int i = 2; i <= n; i++)
    if (f[i])
      ans = ans * (f[i] + 1) % mod;
  return ans % mod;
}

int main() {
  int n;
  scanf("%d", &n);
  cout << fun(n) << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
#define N 1009
using namespace std;
const int INF = 0x3f3f3f3f;
const long long mod = 1e9 + 7;

int fun(int n) {
  int f[N];
  memset(f, 0, sizeof(f));
  long long ans = 1;
  for (int i = 2; i <= n; i++) {
    int k = i;
    for (int j = 2; j <= k; j++) {
      while (k % j == 0) {
        f[j]++;
        k /= j;
      }
    }
    if (k)
      f[k]++;
  }
  for (int i = 2; i <= n; i++)
    if (f[i])
      ans = ans * (f[i] + 1) % mod;
  return ans % mod;
}

int main() {
  int n;
  scanf("%d", &n);
  cout << fun(n) << endl;
  return 0;
}
Problem p03830 (C++)

Buggy submission (status: Runtime Error):
#define _CRT_SECURE_NO_WARNINGS
#define INF 1e10

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int prim[1230] = {2, 3};

void prime(void) {
  int tally = 2;
  int i, j, flag;
  for (i = 5; i < 1010; i += 2) {
    for (j = 0, flag = 1; prim[j] * prim[j] <= i; j++)
      if (i % prim[j] == 0)
        flag = 0;
    if (flag) {
      prim[tally] = i;
      tally++;
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  freopen("input1.txt", "r", stdin);
  freopen("output1.txt", "w", stdout);

  prime();

  int n;
  while (cin >> n) {
    int so[1010];
    for (int a = 0; a <= n; a++)
      so[a] = 1;
    for (int a = 2; a <= n; a++) {
      int tmp = a;
      int b = 0;
      while (prim[b] <= a) {
        if (tmp % prim[b] == 0) {
          so[prim[b]]++;
          tmp /= prim[b];
          b = 0;
        } else
          b++;
      }
    }
    long long res = 1;
    for (int a = 2; a <= n; a++) {
      res *= so[a];
      res %= 1000000007;
    }
    cout << res << endl;
  }

  return 0;
}

Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#define INF 1e10

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int prim[1230] = {2, 3};

void prime(void) {
  int tally = 2;
  int i, j, flag;
  for (i = 5; i < 1010; i += 2) {
    for (j = 0, flag = 1; prim[j] * prim[j] <= i; j++)
      if (i % prim[j] == 0)
        flag = 0;
    if (flag) {
      prim[tally] = i;
      tally++;
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // freopen("input1.txt", "r", stdin);
  // freopen("output1.txt", "w", stdout);

  prime();

  int n;
  while (cin >> n) {
    int so[1010];
    for (int a = 0; a <= n; a++)
      so[a] = 1;
    for (int a = 2; a <= n; a++) {
      int tmp = a;
      int b = 0;
      while (prim[b] <= a) {
        if (tmp % prim[b] == 0) {
          so[prim[b]]++;
          tmp /= prim[b];
          b = 0;
        } else
          b++;
      }
    }
    long long res = 1;
    for (int a = 2; a <= n; a++) {
      res *= so[a];
      res %= 1000000007;
    }
    cout << res << endl;
  }

  return 0;
}
Problem p03830 (C++)

Buggy submission (status: Runtime Error):
// #define LOCAL

#include <algorithm>
#include <climits>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)

#define int long long

using namespace std;

int prime[200];
bool is_prime[201];

int sieve(int n) {
  int p = 0;
  for (int i = 0; i <= n; i++)
    is_prime[i] = true;
  for (int i = 2; i <= n; i++) {
    if (is_prime[i]) {
      prime[p++] = i;
      for (int j = 2 * i; j <= n; j += i)
        is_prime[j] = false;
    }
  }
}

vector<int> primeFactorization(int n) {
  vector<int> ret;
  int p = 0;
  while (n > 1) {
    while (n % prime[p] == 0) {
      ret.push_back(prime[p]);
      n /= prime[p];
    }
    p++;
  }
  return ret;
}

void printV(vector<int> vi) {
  rep(i, vi.size()) { cout << vi[i] << " "; }
  cout << endl;
}

signed main() {
#ifdef LOCAL
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
#endif

  int N;
  map<int, int> cnt;

  cin >> N;

  sieve(1000);

  if (N == 1) {
    cout << 1 << endl;
    return 0;
  }

  for (int i = 2; i <= N; i++) {
    vector<int> factors = primeFactorization(i);
    rep(j, factors.size()) { cnt[factors[j]]++; }
  }

  int ans = 1;
  for (map<int, int>::iterator it = cnt.begin(); it != cnt.end(); it++) {
    ans *= (it->second + 1);
    ans %= 1000000007;
  }

  cout << ans << endl;
}


Fixed submission:
// #define LOCAL

#include <algorithm>
#include <climits>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)

#define int long long

using namespace std;

int prime[200];
bool is_prime[1010];

int sieve(int n) {
  int p = 0;
  for (int i = 0; i <= n; i++)
    is_prime[i] = true;
  for (int i = 2; i <= n; i++) {
    if (is_prime[i]) {
      prime[p++] = i;
      for (int j = 2 * i; j <= n; j += i)
        is_prime[j] = false;
    }
  }
}

vector<int> primeFactorization(int n) {
  vector<int> ret;
  int p = 0;
  while (n > 1) {
    while (n % prime[p] == 0) {
      ret.push_back(prime[p]);
      n /= prime[p];
    }
    p++;
  }
  return ret;
}

void printV(vector<int> vi) {
  rep(i, vi.size()) { cout << vi[i] << " "; }
  cout << endl;
}

signed main() {
#ifdef LOCAL
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
#endif

  int N;
  map<int, int> cnt;

  cin >> N;

  sieve(1000);

  if (N == 1) {
    cout << 1 << endl;
    return 0;
  }

  for (int i = 2; i <= N; i++) {
    vector<int> factors = primeFactorization(i);
    rep(j, factors.size()) { cnt[factors[j]]++; }
  }

  int ans = 1;
  for (map<int, int>::iterator it = cnt.begin(); it != cnt.end(); it++) {
    ans *= (it->second + 1);
    ans %= 1000000007;
  }

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int m[106];
int n, a, b, s = 0;
void print() { cout << s; }
void search(int t) {
  if ((m[t] - m[t - 1]) * a < b)
    s += (m[t] - m[t - 1]) * a;
  else
    s += b;
  if (t == n)
    print();
  else
    search(t + 1);
}
int main() {
  cin >> n >> a >> b;
  for (int i = 1; i <= n; i++) {
    cin >> m[i];
  }
  m[0] = m[1];
  search(1);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int m[100001];
long long n, a, b, s = 0;
void print() { cout << s; }
void search(int t) {
  if ((m[t] - m[t - 1]) * a < b)
    s += (m[t] - m[t - 1]) * a;
  else
    s += b;
  if (t == n)
    print();
  else
    search(t + 1);
}
int main() {
  cin >> n >> a >> b;
  for (int i = 1; i <= n; i++) {
    cin >> m[i];
  }
  m[0] = m[1];
  search(1);
}
Problem p03831 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <string>
#include <vector>

#define ll long long int

using namespace std;

int to_int(string s) { return atoi(s.c_str()); }

ll x[10001];

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }

  ll result = 0;
  for (int i = 0; i < n - 1; i++) {
    if (a * (x[i + 1] - x[i]) > b) {
      result += b;
    } else {
      result += a * (x[i + 1] - x[i]);
    }
  }

  cout << result << endl;
}


Fixed submission:
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <string>
#include <vector>

#define ll long long int

using namespace std;

int to_int(string s) { return atoi(s.c_str()); }

ll x[100001];

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }

  ll result = 0;
  for (int i = 0; i < n - 1; i++) {
    if (a * (x[i + 1] - x[i]) > b) {
      result += b;
    } else {
      result += a * (x[i + 1] - x[i]);
    }
  }

  cout << result << endl;
}
Problem p03831 (C++)

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

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int iy[] = {0, 0, 1, -1};
int ix[] = {1, -1, 0, 0};

int n, x[10010], a, b;
unsigned long long int ans;

int main() {
  cin >> n >> a >> b;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  for (int i = 0; i < n - 1; i++) {
    ans += min((x[i + 1] - x[i]) * a, b);
  }
  cout << ans << endl;
  return 0;
}

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

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int iy[] = {0, 0, 1, -1};
int ix[] = {1, -1, 0, 0};

int n;
unsigned long long int ans, x[100010], a, b;

int main() {
  cin >> n >> a >> b;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  for (int i = 0; i < n - 1; i++) {
    ans += min((x[i + 1] - x[i]) * a, b);
  }
  cout << ans << endl;
  return 0;
}
Problem p03831 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
using namespace std;
int main() {
  long long n, a, b, x[10000] = {}, ans = 0;
  cin >> n >> a >> b;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  for (int i = 0; i < n - 1; i++) {
    ans += min((x[i + 1] - x[i]) * a, b);
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
using namespace std;
int main() {
  long long n, a, b, x[100005] = {}, ans = 0;
  cin >> n >> a >> b;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  for (int i = 0; i < n - 1; i++) {
    ans += min((x[i + 1] - x[i]) * a, b);
  }
  cout << ans << endl;
}
Problem p03831 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
using namespace std;
using LL = long long;
int main() {
  LL n, a, b;
  cin >> n >> a >> b;
  LL ans = 0;
  LL x[10001];
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  for (int i = 0; i < n - 1; i++) {
    ans += min((x[i + 1] - x[i]) * a, b);
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
using namespace std;
using LL = long long;
int main() {
  LL n, a, b;
  cin >> n >> a >> b;
  LL ans = 0;
  LL x[100001];
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  for (int i = 0; i < n - 1; i++) {
    ans += min((x[i + 1] - x[i]) * a, b);
  }
  cout << ans << endl;
}
Problem p03831 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define out(a) cout << a << " "
#define all(a) (a).begin(), (a).end()
#define upper_index(v, a)                                                      \
  (int)distance(v.begin(), upper_bound((v).begin(), (v).end(), a))
#define lower_index(v, a)                                                      \
  (int)distance(v.begin(), lower_bound((v).begin(), (v).end(), a))
typedef long long ll;
const long long INF = 1e17;

int main() {
  ll n, a, b, cnt = 0;
  vector<ll> x(n);
  cin >> n >> a >> b;
  rep(i, n) cin >> x[i];
  rep(i, n - 1) { cnt += min(a * (x[i + 1] - x[i]), b); }
  cout << cnt << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define out(a) cout << a << " "
#define all(a) (a).begin(), (a).end()
#define upper_index(v, a)                                                      \
  (int)distance(v.begin(), upper_bound((v).begin(), (v).end(), a))
#define lower_index(v, a)                                                      \
  (int)distance(v.begin(), lower_bound((v).begin(), (v).end(), a))
typedef long long ll;
const long long INF = 1e17;

int main() {
  ll n, a, b, cnt = 0, x, y;
  cin >> n >> a >> b >> y;
  rep(i, n - 1) {
    x = y;
    cin >> y;
    cnt += min(a * (y - x), b);
  }
  cout << cnt << endl;
}
Problem p03831 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>

using namespace std;
long long X[10005];
int main() {
  long long N, A, B;
  cin >> N >> A >> B;
  for (int i = 0; i < N; ++i)
    cin >> X[i];
  long long res = 0;
  for (int i = 0; i < N - 1; ++i)
    res += min(B, A * (X[i + 1] - X[i]));
  cout << res << endl;
  return 0;
}

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

using namespace std;
long long X[100005];
int main() {
  long long N, A, B;
  cin >> N >> A >> B;
  for (int i = 0; i < N; ++i)
    cin >> X[i];
  long long res = 0;
  for (int i = 0; i < N - 1; ++i)
    res += min(B, A * (X[i + 1] - X[i]));
  cout << res << endl;
  return 0;
}
Problem p03832 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;

ll dp[1024][1024];
ll comb[1024][1024];
ll dv[1024];

ll modpow(ll a, ll b) {
  ll ret = 1;
  while (b) {
    if (b & 1)
      ret = ret * a % mod;
    b /= 2;
    a = a * a % mod;
  }
  return ret;
}

int main() {
  ll n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;

  comb[0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= i; j++) {
      comb[i + 1][j] += comb[i][j];
      comb[i + 1][j] %= mod;
      comb[i + 1][j + 1] += comb[i][j];
      comb[i + 1][j + 1] %= mod;
    }
  }
  dv[1] = 1;
  for (int i = 2; i <= n; i++)
    dv[i] = modpow(i, mod - 2);

  dp[a - 1][n] = 1;
  for (int i = a; i <= b; i++) {
    for (int j = 0; j <= n; j++) {
      if (dp[i - 1][j] == 0)
        continue;
      dp[i][j] += dp[i - 1][j];
      dp[i][j] %= mod;
      ll multi = 1;
      for (int k = 1; k < c; k++) {
        multi = (multi * comb[j - i * (k - 1)][i]) % mod;
        multi = (multi * dv[k]) % mod;
      }
      for (int k = c; k <= d; k++) {
        if (j - k * i < 0)
          break;
        multi = (multi * comb[j - i * (k - 1)][i]) % mod;
        multi = (multi * dv[k]) % mod;
        dp[i][j - k * i] += (multi * dp[i - 1][j]) % mod;
        dp[i][j - k * i] %= mod;
      }
    }
  }
  cout << dp[b][0] << endl;
  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;

ll dp[1024][1024];
ll comb[1024][1024];
ll dv[1024];

ll modpow(ll a, ll b) {
  ll ret = 1;
  while (b) {
    if (b & 1)
      ret = ret * a % mod;
    b /= 2;
    a = a * a % mod;
  }
  return ret;
}

int main() {
  ll n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;

  comb[0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= i; j++) {
      comb[i + 1][j] += comb[i][j];
      comb[i + 1][j] %= mod;
      comb[i + 1][j + 1] += comb[i][j];
      comb[i + 1][j + 1] %= mod;
    }
  }
  dv[1] = 1;
  for (int i = 2; i <= n; i++)
    dv[i] = modpow(i, mod - 2);

  dp[a - 1][n] = 1;
  for (int i = a; i <= b; i++) {
    for (int j = 0; j <= n; j++) {
      if (dp[i - 1][j] == 0)
        continue;
      dp[i][j] += dp[i - 1][j];
      dp[i][j] %= mod;
      if (j - i * c < 0)
        continue;
      ll multi = 1;
      for (int k = 1; k < c; k++) {
        multi = (multi * comb[j - i * (k - 1)][i]) % mod;
        multi = (multi * dv[k]) % mod;
      }
      for (int k = c; k <= d; k++) {
        if (j - k * i < 0)
          break;
        multi = (multi * comb[j - i * (k - 1)][i]) % mod;
        multi = (multi * dv[k]) % mod;
        dp[i][j - k * i] += (multi * dp[i - 1][j]) % mod;
        dp[i][j - k * i] %= mod;
      }
    }
  }
  cout << dp[b][0] << endl;
  return 0;
}
Problem p03832 (C++)

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

const int mod = 1e9 + 7;

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

template <class... T> int add(int x, T... y) { return add(x, add(y...)); }

int mul(int x, int y) { return 1LL * x * y % mod; }

template <class... T> int mul(int x, T... y) { return mul(x, mul(y...)); }

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

int main() {
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;

  static int inv[1001];

  inv[1] = 1;
  for (int i = 2; i <= 1000; i++) {
    inv[i] = mul(inv[mod % i], mod - mod / i);
  }

  static int F[1000001];
  static int invF[1000001];
  F[0] = 1;
  invF[0] = 1;
  for (int i = 1; i <= 1000000; i++) {
    F[i] = mul(F[i - 1], i);
    invF[i] = mul(invF[i - 1], inv[i]);
  }

  auto C = [&](int n, int r) {
    if (n < 0 || r < 0 || n < r)
      return 0;
    return mul(F[n], invF[r], invF[n - r]);
  };

  static int dp0[1001];
  static int dp1[1001];
  dp0[0] = 1;

  for (int i = a; i <= b; i++) {
    memcpy(dp1, dp0, sizeof(dp1));

    for (int j = 0; j < n; j++) {
      int f = 1;
      for (int k = 0; k <= d && j + i * k <= n; k++) {
        // j + i * k <= n
        if (k >= c) {
          upd(dp0[j + i * k],
              mul(dp1[j], C(n - j, i * k), F[i * k], f, invF[k]));
        }
        f = mul(f, invF[i]);
      }
    }
  }

  cout << dp0[n] << endl;
}


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

const int mod = 1e9 + 7;

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

template <class... T> int add(int x, T... y) { return add(x, add(y...)); }

int mul(int x, int y) { return 1LL * x * y % mod; }

template <class... T> int mul(int x, T... y) { return mul(x, mul(y...)); }

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

int main() {
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;

  static int inv[1000001];

  inv[1] = 1;
  for (int i = 2; i <= 1000; i++) {
    inv[i] = mul(inv[mod % i], mod - mod / i);
  }

  static int F[1000001];
  static int invF[1000001];
  F[0] = 1;
  invF[0] = 1;
  for (int i = 1; i <= 1000000; i++) {
    F[i] = mul(F[i - 1], i);
    invF[i] = mul(invF[i - 1], inv[i]);
  }

  auto C = [&](int n, int r) {
    if (n < 0 || r < 0 || n < r)
      return 0;
    return mul(F[n], invF[r], invF[n - r]);
  };

  static int dp0[1001];
  static int dp1[1001];
  dp0[0] = 1;

  for (int i = a; i <= b; i++) {
    memcpy(dp1, dp0, sizeof(dp1));

    for (int j = 0; j < n; j++) {
      int f = 1;
      for (int k = 0; k <= d && j + i * k <= n; k++) {
        // j + i * k <= n
        if (k >= c) {
          upd(dp0[j + i * k],
              mul(dp1[j], C(n - j, i * k), F[i * k], f, invF[k]));
        }
        f = mul(f, invF[i]);
      }
    }
  }

  cout << dp0[n] << endl;
}
Problem p03832 (C++)

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

using ll = long long;
const ll MOD = 1e9 + 7;

vector<ll> fact;

ll powm(ll x, ll k) {
  ll res = 1;
  while (k) {
    if (k & 1)
      res = res * x % MOD;
    k >>= 1;
    x = x * x % MOD;
  }
  return res;
}
ll inv(ll x) { return powm(x, MOD - 2); }
void init(int n) {
  fact.resize(n + 1);
  fact[0] = 1;
  for (int i = 0; i < n; i++) {
    fact[i + 1] = fact[i] * (i + 1) % MOD;
  }
}
int main() {
  int n;
  cin >> n;
  init(n);
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  vector<vector<ll>> dp(n + 1, vector<ll>(n + 1));
  dp[0][n] = 1;
  auto comb = [](int n, int k) {
    return fact[n] * inv(fact[k]) % MOD * inv(fact[n - k]) % MOD;
  };
  auto calc = [comb](int i, int j, int f) {
    return comb(j, f * i) * fact[f * i] % MOD * inv(fact[f]) % MOD *
           inv(powm(fact[i], f)) % MOD;
  };

  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= n; j++) {
      if (a <= i + 1 && i + 1 <= b) {
        for (int f = c; f <= d; f++) {
          if (j - f * (i + 1) < 0)
            break;
          (dp[i + 1][j - f * (i + 1)] += calc(i + 1, j, f) * dp[i][j]) %= MOD;
        }
      }
      (dp[i + 1][j] += dp[i][j]) %= MOD;
    }
  }

  cout << dp[n][0] << endl;
  return 0;
}

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

using ll = long long;
const ll MOD = 1e9 + 7;

vector<ll> fact;

ll powm(ll x, ll k) {
  ll res = 1;
  while (k) {
    if (k & 1)
      res = res * x % MOD;
    k >>= 1;
    x = x * x % MOD;
  }
  return res;
}
ll inv(ll x) { return powm(x, MOD - 2); }
void init(int n) {
  fact.resize(n + 1);
  fact[0] = 1;
  for (int i = 0; i < n; i++) {
    fact[i + 1] = fact[i] * (i + 1) % MOD;
  }
}
int main() {
  int n;
  cin >> n;
  init(n);
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  vector<vector<ll>> dp(n + 1, vector<ll>(n + 1));
  dp[0][n] = 1;
  auto comb = [](int n, int k) {
    return fact[n] * inv(fact[k]) % MOD * inv(fact[n - k]) % MOD;
  };
  auto calc = [comb](int i, int j, int f) {
    return comb(j, f * i) * fact[f * i] % MOD * inv(fact[f]) % MOD *
           inv(powm(fact[i], f)) % MOD;
  };

  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= n; j++) {
      if (a <= i + 1 && i + 1 <= b) {
        for (int f = c; f <= d; f++) {
          if (j - f * (i + 1) < 0)
            break;
          (dp[i + 1][j - f * (i + 1)] += calc(i + 1, j, f) * dp[i][j]) %= MOD;
        }
      }
      (dp[i + 1][j] += dp[i][j]) %= MOD;
    }
  }

  cout << dp[n][0] << endl;
  return 0;
}
Problem p03832 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 1, M = 1e9 + 7;
int dp[N][N], n, a, b, c, d, fact[N] = {1}, inv[N];
void add(int &a, int b) {
  a += b;
  if (a >= M)
    a -= M;
}
int power(int base, int to) {
  int ret = 1;
  while (to) {
    if (to & 1)
      ret = ret * 1LL * base % M;
    to >>= 1;
    base = base * 1LL * base % M;
  }
  return ret;
}
int main() {
  // freopen("readin.txt","r",stdin);
  for (int i = 1; i < N; i++)
    fact[i] = fact[i - 1] * 1LL * i % M;
  for (int i = 0; i < N; i++)
    inv[i] = power(fact[i], M - 2);
  scanf("%d%d%d%d%d", &n, &a, &b, &c, &d);
  dp[a][0] = 1;
  for (int i = a; i <= b; i++)
    for (int j = 0; j <= n; j++) {
      add(dp[i + 1][j], dp[i][j]);
      for (int k = c; k <= d; k++) {
        if (j + i * k > n)
          break;
        int x = fact[n - j] * 1LL * inv[n - j - i * k] % M;
        x = x * 1LL * power(inv[i], k) % M;
        x = x * 1LL * inv[k] % M;
        add(dp[i + 1][j + k * i], dp[i][j] * 1LL * x % M);
      }
    }
  printf("%d\n", dp[b + 1][n]);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 2, M = 1e9 + 7;
int dp[N][N], n, a, b, c, d, fact[N] = {1}, inv[N];
void add(int &a, int b) {
  a += b;
  if (a >= M)
    a -= M;
}
int power(int base, int to) {
  int ret = 1;
  while (to) {
    if (to & 1)
      ret = ret * 1LL * base % M;
    to >>= 1;
    base = base * 1LL * base % M;
  }
  return ret;
}
int main() {
  // freopen("readin.txt","r",stdin);
  for (int i = 1; i < N; i++)
    fact[i] = fact[i - 1] * 1LL * i % M;
  for (int i = 0; i < N; i++)
    inv[i] = power(fact[i], M - 2);
  scanf("%d%d%d%d%d", &n, &a, &b, &c, &d);
  dp[a][0] = 1;
  for (int i = a; i <= b; i++)
    for (int j = 0; j <= n; j++) {
      add(dp[i + 1][j], dp[i][j]);
      for (int k = c; k <= d; k++) {
        if (j + i * k > n)
          break;
        int x = fact[n - j] * 1LL * inv[n - j - i * k] % M;
        x = x * 1LL * power(inv[i], k) % M;
        x = x * 1LL * inv[k] % M;
        add(dp[i + 1][j + k * i], dp[i][j] * 1LL * x % M);
      }
    }
  printf("%d\n", dp[b + 1][n]);
}
Problem p03832 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx,popcnt")
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
const int maxn = 1020, mod = 1e9 + 7, i2 = (mod + 1) / 2;
ll n, a, b, c, d, dp[maxn][maxn], C[maxn][maxn];
ll bp(ll a, ll p) {
  ll r = 1;
  while (p) {
    if (p & 1)
      r = r * a % mod;
    a = a * a % mod, p >>= 1;
  }
  return r;
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin >> n >> a >> b >> c >> d;
  dp[0][a] = 1;
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= i; j++) {
      if (!j)
        C[i][j] = 1;
      else
        C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;
    }
  for (int i = 0; i <= n; i++) {
    for (int j = a; j <= b; j++) {
      // cout << i << " " << j << " " << dp[i][j] << '\n';;
      (dp[i][j + 1] += dp[i][j]) %= mod;
      ll t = 1;
      for (int k = 0; k < c; k++) {
        t = t * C[n - i - k * j][j] % mod;
        t = t * bp(k + 1, mod - 2) % mod;
      }
      for (int k = j * c; i + k <= n && k <= j * d; k += j) {
        (dp[i + k][j + 1] += dp[i][j] * t) %= mod;
        t = t * C[n - i - k][j] % mod;
        t = t * bp((k / j) + 1, mod - 2) % mod;
      }
    }
  }
  cout << dp[n][b + 1];
  return 0;
}


Fixed submission:
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx,popcnt")
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
const int maxn = 1020, mod = 1e9 + 7, i2 = (mod + 1) / 2;
ll n, a, b, c, d, dp[maxn][maxn], C[maxn][maxn];
ll bp(ll a, ll p) {
  ll r = 1;
  while (p) {
    if (p & 1)
      r = r * a % mod;
    a = a * a % mod, p >>= 1;
  }
  return r;
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin >> n >> a >> b >> c >> d;
  dp[0][a] = 1;
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= i; j++) {
      if (!j)
        C[i][j] = 1;
      else
        C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;
    }
  for (int i = 0; i <= n; i++) {
    for (int j = a; j <= b; j++) {
      // cout << i << " " << j << " " << dp[i][j] << '\n';;
      (dp[i][j + 1] += dp[i][j]) %= mod;
      ll t = 1;
      for (int k = 0; k < c && n - i - k * j >= 0; k++) {
        t = t * C[n - i - k * j][j] % mod;
        t = t * bp(k + 1, mod - 2) % mod;
      }
      for (int k = j * c; i + k <= n && k <= j * d; k += j) {
        (dp[i + k][j + 1] += dp[i][j] * t) %= mod;
        t = t * C[n - i - k][j] % mod;
        t = t * bp((k / j) + 1, mod - 2) % mod;
      }
    }
  }
  cout << dp[n][b + 1];
  return 0;
}
Problem p03832 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1e9 + 7;

const int MAX = 1100;
ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

ll COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll modpow(ll a, ll n, ll MOD) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return res;
}

int main() {
  ll n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;

  vector<ll> dp(n + 1, 0);
  dp[0] = 1;

  COMinit();

  for (int i = a; i <= b; i++) {
    for (int j = n; j >= 0; j++) {
      for (int k = c; i * k <= j && k <= d; k++) {
        dp[j] += dp[j - i * k] * fac[n - (j - i * k)] % MOD * finv[n - j] %
                 MOD * finv[k] % MOD * modpow(finv[i], k, MOD) % MOD;
        dp[j] %= MOD;
      }
    }
  }

  cout << dp[n] << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1e9 + 7;

const int MAX = 1100;
ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

ll COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll modpow(ll a, ll n, ll MOD) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return res;
}

int main() {
  ll n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;

  vector<ll> dp(n + 1, 0);
  dp[0] = 1;

  COMinit();

  for (int i = a; i <= b; i++) {
    for (int j = n; j >= 0; j--) {
      for (int k = c; i * k <= j && k <= d; k++) {
        dp[j] += dp[j - i * k] * fac[n - (j - i * k)] % MOD * finv[n - j] %
                 MOD * finv[k] % MOD * modpow(finv[i], k, MOD) % MOD;
        dp[j] %= MOD;
      }
    }
  }

  cout << dp[n] << endl;

  return 0;
}
Problem p03832 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
#define EPS (1e-10)
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

ll dp[1001][1001];
ll fact[1001];
ll ppow(ll a, ll b) {
  ll res = 1;
  while (b) {
    if (b & 1)
      res = (res * a) % MOD;
    a = (a * a) % MOD;
    b >>= 1;
  }
  return res;
}
ll comb(ll a, ll b) {
  return (((fact[a] * ppow(fact[a - b], MOD - 2)) % MOD) *
          ppow(fact[b], MOD - 2)) %
         MOD;
}
int main() {
  fact[0] = 1;
  int n, a, b, c, d;
  scanf("%d%d%d%d%d", &n, &a, &b, &c, &d);
  for (int i = 1; i <= n; i++)
    fact[i] = (fact[i - 1] * i) % MOD;
  rep(i, n) dp[i][0] = 1;
  for (int i = a - 1; i < b; i++) {
    for (int j = 0; j <= n; j++) {
      if (j)
        (dp[i + 1][j] += dp[i][j]) %= MOD;
      ll y = 1, t = n - j;
      rep(p, c - 1) {
        (y *= comb(t + i + 1, t)) %= MOD;
        t += i + 1;
      }
      for (int k = c; j - k * (i + 1) >= 0 && k <= d; k++) {
        (y *= comb(t + i + 1, t)) %= MOD;
        ll o = y;
        (o *= ppow(fact[k], MOD - 2)) %= MOD;
        (dp[i + 1][j] += ((dp[i][j - k * (i + 1)] * o) % MOD)) %= MOD;
        t += i + 1;
      }
    }
  }
  cout << dp[b][n] << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
#define EPS (1e-10)
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

ll dp[1001][1001];
ll fact[1001];
ll ppow(ll a, ll b) {
  ll res = 1;
  while (b) {
    if (b & 1)
      res = (res * a) % MOD;
    a = (a * a) % MOD;
    b >>= 1;
  }
  return res;
}
ll comb(ll a, ll b) {
  return (((fact[a] * ppow(fact[a - b], MOD - 2)) % MOD) *
          ppow(fact[b], MOD - 2)) %
         MOD;
}
int main() {
  fact[0] = 1;
  int n, a, b, c, d;
  scanf("%d%d%d%d%d", &n, &a, &b, &c, &d);
  for (int i = 1; i <= n; i++)
    fact[i] = (fact[i - 1] * i) % MOD;
  rep(i, n) dp[i][0] = 1;
  for (int i = a - 1; i < b; i++) {
    for (int j = 0; j <= n; j++) {
      if (j)
        (dp[i + 1][j] += dp[i][j]) %= MOD;
      if (j - c * (i + 1) < 0)
        continue;
      ll y = 1, t = n - j;
      rep(p, c - 1) {
        (y *= comb(t + i + 1, t)) %= MOD;
        t += i + 1;
      }
      for (int k = c; j - k * (i + 1) >= 0 && k <= d; k++) {
        (y *= comb(t + i + 1, t)) %= MOD;
        ll o = y;
        (o *= ppow(fact[k], MOD - 2)) %= MOD;
        (dp[i + 1][j] += ((dp[i][j - k * (i + 1)] * o) % MOD)) %= MOD;
        t += i + 1;
      }
    }
  }
  cout << dp[b][n] << endl;
}