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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e6 + 5;
const int INF = 0x3f3f3f3f;
const ll p = 1e9 + 7;
#define DEBUG(x) cout << x << '\n'

int F[MAXN], Finv[MAXN], inv[MAXN];
void init() {
  F[0] = Finv[0] = inv[1] = 1;
  for (int i = 2; i < MAXN; i++)
    inv[i] = (p - p / i) * 1ll * inv[p % i] % p;
  for (int i = 1; i < MAXN; i++) {
    F[i] = F[i - 1] * 1ll * i % p;
    Finv[i] = Finv[i - 1] * 1ll * inv[i] % p;
  }
}
int C(int n, int m) { return F[n] * 1ll * Finv[n - m] % p * Finv[m] % p; }
ll f_pow(ll a, ll b) {
  ll res = 1;
  for (; b; b >>= 1, a = a * a % p)
    if (b & 1)
      res = res * a % p;
  return res;
}
void run() {
  int n, k;
  string s;
  cin >> k >> s;
  init();
  n = s.size();
  int ans = 0;
  for (int i = n; i <= n + k; i++) {
    ans += C(i - 1, n - 1) * f_pow(26, n + k - i) % p * f_pow(25, i - n) % p;
    ans %= p;
  }
  cout << ans;
}
int main() {
#ifdef Irene
  freopen("in.txt", "r", stdin);
#endif // Irene
  ios::sync_with_stdio(false);

  run();
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 2e6 + 5;
const int INF = 0x3f3f3f3f;
const ll p = 1e9 + 7;
#define DEBUG(x) cout << x << '\n'

int F[MAXN], Finv[MAXN], inv[MAXN];
void init() {
  F[0] = Finv[0] = inv[1] = 1;
  for (int i = 2; i < MAXN; i++)
    inv[i] = (p - p / i) * 1ll * inv[p % i] % p;
  for (int i = 1; i < MAXN; i++) {
    F[i] = F[i - 1] * 1ll * i % p;
    Finv[i] = Finv[i - 1] * 1ll * inv[i] % p;
  }
}
int C(int n, int m) { return F[n] * 1ll * Finv[n - m] % p * Finv[m] % p; }
ll f_pow(ll a, ll b) {
  ll res = 1;
  for (; b; b >>= 1, a = a * a % p)
    if (b & 1)
      res = res * a % p;
  return res;
}
void run() {
  int n, k;
  string s;
  cin >> k >> s;
  init();
  n = s.size();
  int ans = 0;
  for (int i = n; i <= n + k; i++) {
    ans += C(i - 1, n - 1) * f_pow(26, n + k - i) % p * f_pow(25, i - n) % p;
    ans %= p;
  }
  cout << ans;
}
int main() {
#ifdef Irene
  freopen("in.txt", "r", stdin);
#endif // Irene
  ios::sync_with_stdio(false);

  run();
}
Problem p02632 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>

#define ULL unsigned long long

#define MOD 1000000007
#define MAX 30000000

ULL RepSq(ULL n, ULL m, ULL mod);
void nCk_init(int mod);
ULL nCk(int n, int k, int mod);

ULL fac[MAX], finv[MAX], inv[MAX];

int main() {
  nCk_init(MOD);

  int K, a, iCnt = 0;
  scanf("%d", &K);

  getchar();
  while ((a = getchar()) != '\n')
    iCnt++;
  ULL ans = 0;

  for (int i = 0; i <= K; i++) {
    // inserted place patterns
    ULL tmpChairs4OtherLetters = iCnt + K - i - 1;
    ULL insPlacePatterns = nCk((int)tmpChairs4OtherLetters, iCnt - 1, MOD);

    // inserted letter patterns
    ULL insLetsBeforeLastLet = K - i;
    ULL insLetPatterns = RepSq((ULL)26, (ULL)i, (ULL)MOD);
    insLetPatterns *= RepSq((ULL)25, insLetsBeforeLastLet, (ULL)MOD);
    insLetPatterns %= MOD;

    ans += (insPlacePatterns * insLetPatterns % MOD);
    ans %= MOD;
  }

  printf("%lld\n", ans);

  return 0;
}

ULL RepSq(ULL x, ULL n, ULL mod) {
  if (n == 0)
    return 1;

  ULL ret = 1;
  while (0 < n) {
    if (n & 1)
      ret = ret * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return ret;
}

void nCk_init(int mod) {
  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;
  }
}

ULL nCk(int n, int k, int mod) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  // Fermat's little theorem
  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}


Fixed submission:
#include <stdio.h>

#define ULL unsigned long long

#define MOD 1000000007
#define MAX 10000000

ULL RepSq(ULL n, ULL m, ULL mod);
void nCk_init(int mod);
ULL nCk(int n, int k, int mod);

ULL fac[MAX], finv[MAX], inv[MAX];

int main() {
  nCk_init(MOD);

  int K, a, iCnt = 0;
  scanf("%d", &K);

  getchar();
  while ((a = getchar()) != '\n')
    iCnt++;
  ULL ans = 0;

  for (int i = 0; i <= K; i++) {
    // inserted place patterns
    ULL tmpChairs4OtherLetters = iCnt + K - i - 1;
    ULL insPlacePatterns = nCk((int)tmpChairs4OtherLetters, iCnt - 1, MOD);

    // inserted letter patterns
    ULL insLetsBeforeLastLet = K - i;
    ULL insLetPatterns = RepSq((ULL)26, (ULL)i, (ULL)MOD);
    insLetPatterns *= RepSq((ULL)25, insLetsBeforeLastLet, (ULL)MOD);
    insLetPatterns %= MOD;

    ans += (insPlacePatterns * insLetPatterns % MOD);
    ans %= MOD;
  }

  printf("%lld\n", ans);

  return 0;
}

ULL RepSq(ULL x, ULL n, ULL mod) {
  if (n == 0)
    return 1;

  ULL ret = 1;
  while (0 < n) {
    if (n & 1)
      ret = ret * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return ret;
}

void nCk_init(int mod) {
  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;
  }
}

ULL nCk(int n, int k, int mod) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  // Fermat's little theorem
  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long
#define inf 0x3f3f3f3f
#define fast                                                                   \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
const int N = 1e6 + 5;
const ll mod = 1e9 + 7;
int k, n;
ll ans;
string s;
int fac[N], inv[N];
int po(int x, int y) {
  int res = 1;
  while (y) {
    if (y & 1)
      res = 1ll * res * x % mod;
    y >>= 1;
    x = 1ll * x * x % mod;
  }
  return res % mod;
}
int ncr(int n, int r) {
  if (r > n)
    return 0;
  return 1ll * fac[n] * inv[r] % mod * inv[n - r] % mod;
}
int main() {
  fast cin >> k >> s;
  fac[0] = 1;
  for (int i = 1; i < N; i++)
    fac[i] = 1ll * i * fac[i - 1] % mod;
  inv[N - 1] = po(fac[N - 1], mod - 2);
  for (int i = N - 2; i >= 0; i--)
    inv[i] = 1ll * (i + 1) * (inv[i + 1]) % mod;
  n = s.size();
  for (int i = 0; i <= k; i++) {
    ans = (ans +
           1ll * po(25, k - i) * po(26, i) % mod * ncr(n - 1 + k - i, n - 1)) %
          mod;
  }
  cout << ans;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long
#define inf 0x3f3f3f3f
#define fast                                                                   \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
const int N = 2e6 + 5;
const ll mod = 1e9 + 7;
int k, n;
ll ans;
string s;
int fac[N], inv[N];
int po(int x, int y) {
  int res = 1;
  while (y) {
    if (y & 1)
      res = 1ll * res * x % mod;
    y >>= 1;
    x = 1ll * x * x % mod;
  }
  return res % mod;
}
int ncr(int n, int r) {
  if (r > n)
    return 0;
  return 1ll * fac[n] * inv[r] % mod * inv[n - r] % mod;
}
int main() {
  fast cin >> k >> s;
  fac[0] = 1;
  for (int i = 1; i < N; i++)
    fac[i] = 1ll * i * fac[i - 1] % mod;
  inv[N - 1] = po(fac[N - 1], mod - 2);
  for (int i = N - 2; i >= 0; i--)
    inv[i] = 1ll * (i + 1) * (inv[i + 1]) % mod;
  n = s.size();
  for (int i = 0; i <= k; i++) {
    ans = (ans +
           1ll * po(25, k - i) * po(26, i) % mod * ncr(n - 1 + k - i, n - 1)) %
          mod;
  }
  cout << ans;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define DEBUG(x) cout << #x << "=" << x << endl
#define DEBUG2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
typedef long long ll;
// #define LOCAL
const int MAXN = 1e6 + 10;
const ll MOD = 1e9 + 7;
ll _gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return _gcd(b, a % b);
}
ll gcd(ll a, ll b) {
  a = abs(a), b = abs(b);
  if (a < b)
    swap(a, b);
  return _gcd(a, b);
}
ll qpow(ll a, ll n) {
  ll rt = 1;
  while (n) {
    if (n & 1)
      rt = (rt * a) % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return rt;
}
ll factor[MAXN];
void cal_factor() {
  factor[0] = 1;
  for (int u = 1; u < MAXN; u++) {
    factor[u] = (factor[u - 1] * u) % MOD;
  }
}
ll C(ll n, ll k) {
  return factor[n] * qpow(factor[n - k], MOD - 2) % MOD *
         qpow(factor[k], MOD - 2) % MOD;
}
void solve() {
  cal_factor();
  ll K, N;
  string s;
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> K >> s;
  N = K + s.size();
  ll ans = qpow(26, N);
  for (ll k = 0; k < s.size(); k++) {
    ans = (ans - C(N, k) * qpow(25, N - k) % MOD + MOD) % MOD;
  }
  cout << ans;
}
int main() {
#ifdef LOCAL
  freopen("in.txt", "r", stdin);
#endif
  solve();
}

Fixed submission:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define DEBUG(x) cout << #x << "=" << x << endl
#define DEBUG2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
typedef long long ll;
// #define LOCAL
const int MAXN = 2e6 + 10;
const ll MOD = 1e9 + 7;
ll _gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return _gcd(b, a % b);
}
ll gcd(ll a, ll b) {
  a = abs(a), b = abs(b);
  if (a < b)
    swap(a, b);
  return _gcd(a, b);
}
ll qpow(ll a, ll n) {
  ll rt = 1;
  while (n) {
    if (n & 1)
      rt = (rt * a) % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return rt;
}
ll factor[MAXN];
void cal_factor() {
  factor[0] = 1;
  for (int u = 1; u < MAXN; u++) {
    factor[u] = (factor[u - 1] * u) % MOD;
  }
}
ll C(ll n, ll k) {
  return factor[n] * qpow(factor[n - k], MOD - 2) % MOD *
         qpow(factor[k], MOD - 2) % MOD;
}
void solve() {
  cal_factor();
  ll K, N;
  string s;
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> K >> s;
  N = K + s.size();
  ll ans = qpow(26, N);
  for (ll k = 0; k < s.size(); k++) {
    ans = (ans - C(N, k) * qpow(25, N - k) % MOD + MOD) % MOD;
  }
  cout << ans;
}
int main() {
#ifdef LOCAL
  freopen("in.txt", "r", stdin);
#endif
  solve();
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int N = 1e6 + 5;
bool cnt[30] = {};
long long fac[N] = {};
long long inv(long long x) {
  if (x == 1)
    return 1;
  return (mod - mod / x) * inv(mod % x) % mod;
}
void init() {
  fac[0] = 1;
  for (long long i = 1; i < N; i++)
    fac[i] = fac[i - 1] * i % mod;
}
long long ksm(long long a, long long b) {
  if (b == 0)
    return 1;
  if (b & 1)
    return a * ksm(a * a % mod, b >> 1) % mod;
  return ksm(a * a % mod, b >> 1);
}
long long C(long long a, long long b) {
  return fac[a] * inv(fac[b] * fac[a - b] % mod) % mod;
}
int main() {
  string str;
  init();
  long long k, len;
  cin >> k >> str;
  len = str.size();
  long long ans = 0;
  for (long long i = len; i <= k + len; i++)
    ans = (ans + (C(i - 1, len - 1) * ksm(26, len + k - i) % mod) *
                     ksm(25, i - len)) %
          mod;
  cout << ans << '\n';
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int N = 2e6 + 5;
long long fac[N] = {};
long long inv(long long x) {
  if (x == 1)
    return 1;
  return (mod - mod / x) * inv(mod % x) % mod;
}
void init() {
  fac[0] = 1;
  for (long long i = 1; i < N; i++)
    fac[i] = fac[i - 1] * i % mod;
}
long long ksm(long long a, long long b) {
  if (b == 0)
    return 1;
  if (b & 1)
    return a * ksm(a * a % mod, b >> 1) % mod;
  return ksm(a * a % mod, b >> 1);
}
long long C(long long a, long long b) {
  return fac[a] * inv(fac[b] * fac[a - b] % mod) % mod;
}
int main() {
  string str;
  init();
  long long k, len;
  cin >> k >> str;
  len = str.size();
  long long ans = 0;
  for (long long i = len; i <= k + len; i++)
    ans = (ans + (C(i - 1, len - 1) * ksm(26, len + k - i) % mod) *
                     ksm(25, i - len)) %
          mod;
  cout << ans << '\n';
  return 0;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define IOS                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0)
/* start */

const int mod = 1e9 + 7; // CHANGE THIS
const int N = 1e6 + 9;   // CHANGE THIS

int fat[N], inv[N];

int fastexp(int b, int e) {
  if (e == 0)
    return 1;
  int ans = fastexp(b, e / 2);
  ans = (ans * ans) % mod;
  if (e % 2 == 1)
    ans = (ans * b) % mod;
  return ans;
}

void init() {
  fat[0] = fat[1] = 1;
  inv[0] = inv[1] = 1;
  for (int i = 2; i < N; i++) {
    fat[i] = (i * fat[i - 1]) % mod;
    inv[i] = fastexp(fat[i], mod - 2);
  }
}

int comb(int a, int b) { return fat[a] * inv[b] % mod * inv[a - b] % mod; }

signed main() {
  IOS;
  init();
  int k;
  cin >> k;
  string s;
  cin >> s;
  int n = s.size();
  int ans = 0;
  for (int i = 0; i <= k; i++) {
    ans = (ans + fastexp(25, i) * fastexp(26, k - i) % mod *
                     comb(i + n - 1, n - 1) % mod) %
          mod;
  }
  cout << ans << "\n";
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define IOS                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0)
/* start */

const int mod = 1e9 + 7;
const int N = 2e6 + 9;

int fat[N], inv[N];

int fastexp(int b, int e) {
  if (e == 0)
    return 1;
  int ans = fastexp(b, e / 2);
  ans = (ans * ans) % mod;
  if (e % 2 == 1)
    ans = (ans * b) % mod;
  return ans;
}

void init() {
  fat[0] = fat[1] = 1;
  inv[0] = inv[1] = 1;
  for (int i = 2; i < N; i++) {
    fat[i] = (i * fat[i - 1]) % mod;
    inv[i] = fastexp(fat[i], mod - 2);
  }
}

int comb(int a, int b) { return fat[a] * inv[b] % mod * inv[a - b] % mod; }

signed main() {
  IOS;
  init();
  int k;
  cin >> k;
  string s;
  cin >> s;
  int n = s.size();
  int ans = 0;
  for (int i = 0; i <= k; i++) {
    ans = (ans + fastexp(25, i) * fastexp(26, k - i) % mod *
                     comb(i + n - 1, n - 1) % mod) %
          mod;
  }
  cout << ans << "\n";
}
Problem p02633 (C++)

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

using namespace std;
/*
void calculate(float X) {
  float deg = X;
  float T = 3.14159265/180;
  int t = 0;
  float x = 0, y = 0;
  float e = 0.001;
  while (true) {
    t++;
    x -= sin(deg*T);
    y -= cos(deg*T);
    deg += X;
    //cout << X << endl;
    //cout << x << " " << y << endl;
    if (-1*e <= x && x <= e && -1*e <= y && y <= e) {
      break;
    }
  }
  cout << t << endl;
}
*/

int main() {
  int ans[179] = {
      360, 180, 120, 90,  72, 60,  360, 45,  40,  36, 360, 30,  360, 180, 24,
      45,  360, 20,  360, 18, 120, 180, 360, 15,  72, 180, 40,  90,  360, 12,
      360, 45,  120, 180, 72, 10,  360, 180, 120, 9,  360, 60,  360, 90,  8,
      180, 360, 15,  360, 36, 120, 90,  360, 20,  72, 45,  120, 180, 360, 6,
      360, 180, 40,  45,  72, 60,  360, 90,  120, 36, 360, 5,   360, 180, 24,
      90,  360, 60,  360, 9,  40,  180, 360, 30,  72, 180, 120, 45,  360, 4,
      360, 90,  120, 180, 72, 15,  360, 180, 40,  18, 360, 60,  360, 45,  24,
      180, 360, 10,  360, 36, 120, 45,  360, 60,  72, 90,  40,  180, 360, 3,
      360, 180, 120, 90,  72, 20,  360, 45,  120, 36, 360, 30,  360, 180, 8,
      45,  360, 60,  360, 18, 120, 180, 360, 5,   72, 180, 120, 90,  360, 12,
      360, 45,  40,  180, 72, 30,  360, 180, 120, 9,  360, 20,  360, 90,  24,
      180, 360, 15,  360, 36, 40,  90,  360, 60,  72, 45,  120, 180, 360,
  };
  int X;
  cin >> X;
  return ans[X - 1];
}


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

using namespace std;
/*
void calculate(float X) {
  float deg = X;
  float T = 3.14159265/180;
  int t = 0;
  float x = 0, y = 0;
  float e = 0.001;
  while (true) {
    t++;
    x -= sin(deg*T);
    y -= cos(deg*T);
    deg += X;
    //cout << X << endl;
    //cout << x << " " << y << endl;
    if (-1*e <= x && x <= e && -1*e <= y && y <= e) {
      break;
    }
  }
  cout << t << endl;
}
*/

int main() {
  int ans[179] = {
      360, 180, 120, 90,  72, 60,  360, 45,  40,  36, 360, 30,  360, 180, 24,
      45,  360, 20,  360, 18, 120, 180, 360, 15,  72, 180, 40,  90,  360, 12,
      360, 45,  120, 180, 72, 10,  360, 180, 120, 9,  360, 60,  360, 90,  8,
      180, 360, 15,  360, 36, 120, 90,  360, 20,  72, 45,  120, 180, 360, 6,
      360, 180, 40,  45,  72, 60,  360, 90,  120, 36, 360, 5,   360, 180, 24,
      90,  360, 60,  360, 9,  40,  180, 360, 30,  72, 180, 120, 45,  360, 4,
      360, 90,  120, 180, 72, 15,  360, 180, 40,  18, 360, 60,  360, 45,  24,
      180, 360, 10,  360, 36, 120, 45,  360, 60,  72, 90,  40,  180, 360, 3,
      360, 180, 120, 90,  72, 20,  360, 45,  120, 36, 360, 30,  360, 180, 8,
      45,  360, 60,  360, 18, 120, 180, 360, 5,   72, 180, 120, 90,  360, 12,
      360, 45,  40,  180, 72, 30,  360, 180, 120, 9,  360, 20,  360, 90,  24,
      180, 360, 15,  360, 36, 40,  90,  360, 60,  72, 45,  120, 180, 360,
  };
  int X;
  cin >> X;
  cout << ans[X - 1] << endl;
}
Problem p02633 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

int main() {
  int n;
  int sum = 0;
  int cnt = 0;
  while (sum == 0 || sum % 360 != 0) {
    sum += n;
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  int sum = 0;
  int cnt = 0;
  while (sum == 0 || sum % 360 != 0) {
    sum += n;
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}
Problem p02633 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define debug(a) cout << #a ": " << a << endl
#define IOS ios::sync_with_stdio(false), cin.tie(0)
using namespace std;
typedef long long ll;

int main(void) {
  IOS;
  int x;
  cin >> x;
  if (360 % x == 0)
    cout << 360 / x << endl;
  else
    while (1)
      ;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define debug(a) cout << #a ": " << a << endl
#define IOS ios::sync_with_stdio(false), cin.tie(0)
using namespace std;
typedef long long ll;

int main(void) {
  IOS;
  int x;
  cin >> x;
  int y = 360;
  int g = __gcd(x, y);
  x /= g, y /= g;
  cout << y << endl;
  return 0;
}
Problem p02633 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define puts(i) cout << i << endl
#define pi 3.14159265358979323846264338
#define pb push_back
#define mp make_pair
#define inf 10000
using ll = long long;
using P = pair<int, int>;
using Pll = pair<ll, ll>;

ll divisor = 1000000007;

int main() {
  int x;
  cin >> x;
  int i = 1;
  while (true) {
    if ((i * x) % 360 == 0) {
      puts(i);
      return 0;
    }
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define puts(i) cout << i << endl
#define pi 3.14159265358979323846264338
#define pb push_back
#define mp make_pair
#define inf 10000
using ll = long long;
using P = pair<int, int>;
using Pll = pair<ll, ll>;

ll divisor = 1000000007;

int main() {
  int x;
  cin >> x;
  int i = 1;
  while (true) {
    if ((i * x) % 360 == 0) {
      puts(i);
      return 0;
    }
    i++;
  }
}
Problem p02633 (C++)

Buggy submission (status: Time Limit Exceeded):
/*
        Name:
        Author: xiaruize
        Date:
*/
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD 1000000007
#define ALL(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ll long long
#define form(i, j, n) for (int i = int(j); i <= int(n); i++)
#define pb push_back
#define mk make_pair
#define pii pair<int, int>
#define pis pair<int, string>
#define sec second
#define sz(a) int((a).size())

inline int read() {
  char ch = getchar();
  int x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = x * 10 + (ch ^ 48), ch = getchar();
  return x * f;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // freopen(".in","r",stdin);
  // freopen(".out","w",stdout);
  int x;
  cin >> x;
  int i = 1;
  while (1) {
    if (i * 360 % x == 0) {
      cout << i * 360 / x << endl;
      return 0;
    }
  }
  return 0;
}


Fixed submission:
/*
        Name:
        Author: xiaruize
        Date:
*/
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD 1000000007
#define ALL(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ll long long
#define form(i, j, n) for (int i = int(j); i <= int(n); i++)
#define pb push_back
#define mk make_pair
#define pii pair<int, int>
#define pis pair<int, string>
#define sec second
#define sz(a) int((a).size())

inline int read() {
  char ch = getchar();
  int x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = x * 10 + (ch ^ 48), ch = getchar();
  return x * f;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // freopen(".in","r",stdin);
  // freopen(".out","w",stdout);
  int x;
  cin >> x;
  cout << 360 / __gcd(360, x) << endl;
  return 0;
}
Problem p02633 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int X, A;
  int counter = 1;
  cin >> X;
  int K = 360 / X;
  if (360 % X == 0)
    cout << K << endl;
  else {
    while (true) {
      counter++;
      if ((counter * 360) % X == 0) {
        cout << counter * K << endl;
      }
    }
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int X, A;
  int counter = 1;
  cin >> X;
  int K = 360 / X;
  if (360 % X == 0)
    cout << K << endl;
  else {
    while (true) {
      counter++;
      if ((counter * 360) % X == 0) {
        cout << (counter * 360) / X << endl;
        break;
      }
    }
  }
}
Problem p02633 (C++)

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

int main() {
  int x;
  int y = 360;
  while (true) {
    if (y % x == 0) {
      cout << y / x << endl;
      return 0;
    }
    y += 360;
  }
}

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

int main() {
  int x;
  cin >> x;
  int y = 360;
  while (true) {
    if (y % x == 0) {
      cout << y / x << endl;
      return 0;
    }
    y += 360;
  }
}
Problem p02633 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main(void) {
  // Your code here!
  int X;
  int K;
  cin >> X;
  cout << 360 / K << endl;
}


Fixed submission:
#include <iostream>
using namespace std;
int main(void) {
  // Your code here!
  int X;
  int K;
  cin >> X;
  // Xto360nosaishoukoubasisu
  int ans;
  for (int i = 1; i <= 180; i++) {
    ans = i * 360;
    if (ans % X == 0) {
      break;
    }
  }
  cout << ans / X << endl;
}
Problem p02633 (C++)

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

int main() {
  int x;
  scanf("%d", &x);
  for (int i = 1; i <= 10000000; ++i)
    if (x * i % 360 == 0)
      return printf("%d\n", i);
  return 0;
}

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

int main() {
  int x;
  scanf("%d", &x);
  for (int i = 1; i <= 10000000; ++i)
    if (x * i % 360 == 0)
      return printf("%d\n", i), 0;
  return 0;
}
Problem p02633 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"
#include <bits/stdc++.h>
#include <unordered_map>
#define M 1000000007
#define T 998244353
#define pi 3.14159265
#define N 100003
#define inf 1000000002
#define ll long long
#define fo(i, a, b) for (i = a; i <= b; i++)
#define ro(i, b, a) for (i = b; i >= a; i--)
#define foe(it, x) for (auto it = x.begin(); it != x.end(); it++)
#define ff first
#define ss second
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define fil(x, y) memset(x, y, sizeof(x))
#define deb(x) cout << #x << " " << x << "\n"

using namespace std;

int gcd(int a, int b) {
  if (a == 0)
    return b;
  return gcd(b % a, a);
}
int lcm(int a, int b) { return (a * b) / gcd(a, b); }
void solve() {
  int x;
  cin >> x;
  cout << lcm(360, x) / x << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

#ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif

  int _t;
  cin >> _t;
  while (_t--)
    solve();
  return 0;
}


Fixed submission:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"
#include <bits/stdc++.h>
#include <unordered_map>
#define M 1000000007
#define T 998244353
#define pi 3.14159265
#define N 100003
#define inf 1000000002
#define ll long long
#define fo(i, a, b) for (i = a; i <= b; i++)
#define ro(i, b, a) for (i = b; i >= a; i--)
#define foe(it, x) for (auto it = x.begin(); it != x.end(); it++)
#define ff first
#define ss second
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define fil(x, y) memset(x, y, sizeof(x))
#define deb(x) cout << #x << " " << x << "\n"

using namespace std;

int gcd(int a, int b) {
  if (a == 0)
    return b;
  return gcd(b % a, a);
}
int lcm(int a, int b) { return (a * b) / gcd(a, b); }
void solve() {
  int x;
  cin >> x;
  cout << lcm(360, x) / x << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

#ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif

  // int _t;cin >> _t; while(_t--)
  solve();
  return 0;
}
Problem p02633 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep1(i, n) for (int i = 1; i <= (int)n; i++)
#define sp(n) cout << fixed << setprecision(n)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
typedef long long ll;
using namespace std;
int main(void) {
  int x;
  cin >> x;
  int y = 1;
  while (true) {
    if (360 * y % x == 0) {
      cout << 360 * y / x << endl;
      return 0;
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep1(i, n) for (int i = 1; i <= (int)n; i++)
#define sp(n) cout << fixed << setprecision(n)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
typedef long long ll;
using namespace std;
int main(void) {
  int x;
  cin >> x;
  int y = 1;
  while (true) {
    if (360 * y % x == 0) {
      cout << 360 * y / x << endl;
      return 0;
    }
    y++;
  }
}
Problem p02633 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#include <iomanip>
#include <math.h>
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const int INF = 1001001001;
vector<pair<int64_t, int64_t>> pppp(int64_t x) {
  vector<pair<int64_t, int64_t>> p;
  for (int64_t i = 2; i * i <= x; i++) {
    int cnt = 0;
    if (x % i == 0) {
      while (x % i == 0) {
        cnt++;
        x /= i;
      }
      p.push_back(make_pair(i, cnt));
    }
  }
  if (x != 1) {
    p.push_back(make_pair(x, 1));
  }
  return p;
}

int main() {
  int X;
  cout << 360 / X << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#include <iomanip>
#include <math.h>
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const int INF = 1001001001;
vector<pair<int64_t, int64_t>> pppp(int64_t x) {
  vector<pair<int64_t, int64_t>> p;
  for (int64_t i = 2; i * i <= x; i++) {
    int cnt = 0;
    if (x % i == 0) {
      while (x % i == 0) {
        cnt++;
        x /= i;
      }
      p.push_back(make_pair(i, cnt));
    }
  }
  if (x != 1) {
    p.push_back(make_pair(x, 1));
  }
  return p;
}

int main() {
  int X;
  cin >> X;
  cout << X * 360 / __gcd(X, 360) / X << endl;
  return 0;
}
Problem p02633 (C++)

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

typedef long long ll;
const int maxn = 1e6 + 7;
const int inf = INT_MAX;
const ll inff = 1e18;
const ll mod = 1e9 + 7;
#define pii pair<int, int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
// #define int ll

#ifdef HNO2
#define IOS
#else
#define endl '\n'
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);
#endif // HNO2

int32_t main() {
  IOS int x;
  cin >> x;
  multiset<int> s;
  int now = 0;
  for (int i = 1;; i++) {
    int tmp = (now >= 180 ? now - 180 : now + 180);
    if (s.find(tmp) != s.end())
      s.erase(s.find(tmp));
    else
      s.insert(now);
    if (sz(s) == 0) {
      cout << i << endl;
      return 0;
    }
    now = (now + x) % 360;
  }
}


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

typedef long long ll;
const int maxn = 1e6 + 7;
const int inf = INT_MAX;
const ll inff = 1e18;
const ll mod = 1e9 + 7;
#define pii pair<int, int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
// #define int ll

#ifdef HNO2
#define IOS
#else
#define endl '\n'
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);
#endif // HNO2

int32_t main() {
  IOS int x;
  cin >> x;
  cout << 360 / __gcd(x, 360) << endl;
}
Problem p02633 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
typedef long long ll;
#define forn(i, start, end) for (ll i = start; i < ll(end); i++)
#define input(arr, n) forn(i, 0, n) cin >> arr[i];
#define MOD 1000000007
#define vll vector<ll>
#define vpll vector<pair<ll, ll>>
#define vvll vector<vector<ll>>
#define mll map<ll, ll>
#define mcl map<char, ll>
#define sc set<char>
#define sll set<ll>
#define ssll stack<ll>
#define CHK(param) cout << #param << " is : " << param << "\n";
#define pb push_back
#define ppb pop_back
#define mk make_pair
#define f first
#define s second
#define all(x) (x).begin(), (x).end()
#define LAUV                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);
#define TC                                                                     \
  ll TTTT;                                                                     \
  cin >> TTTT;                                                                 \
  while (TTTT--)
using namespace std;

int32_t main() {
  LAUV;
  // TC
  {
    ll x;
    cin >> x;
    ll k = 1;
    while (k * x != 360) {
      k++;
    }
    cout << k << '\n';
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
typedef long long ll;
#define forn(i, start, end) for (ll i = start; i < ll(end); i++)
#define input(arr, n) forn(i, 0, n) cin >> arr[i];
#define MOD 1000000007
#define vll vector<ll>
#define vpll vector<pair<ll, ll>>
#define vvll vector<vector<ll>>
#define mll map<ll, ll>
#define mcl map<char, ll>
#define sc set<char>
#define sll set<ll>
#define ssll stack<ll>
#define CHK(param) cout << #param << " is : " << param << "\n";
#define pb push_back
#define ppb pop_back
#define mk make_pair
#define f first
#define s second
#define all(x) (x).begin(), (x).end()
#define LAUV                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);
#define TC                                                                     \
  ll TTTT;                                                                     \
  cin >> TTTT;                                                                 \
  while (TTTT--)
using namespace std;

int32_t main() {
  LAUV;
  // TC
  {
    ll x;
    cin >> x;
    ll k = 1;
    while ((k * x) % 360 != 0) {
      k++;
    }
    cout << k << '\n';
  }
  return 0;
}
Problem p02633 (C++)

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

int main(void) {
  int X, K = 2;
  static const double pi = 3.141592653589793;
  cin >> X;

  float x = 0.0, y = 1.0, theta;
  while (true) {
    theta = float(X * (K - 1) * pi) / 180.0;
    x += sin(theta);
    y += cos(theta);
    if (x < 0.0001 && x > -0.0001 && y < 0.0001 && y > -0.0001) {
      break;
    }
    K++;
  }
  cout << K;
}

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

int main(void) {
  int X, K = 2;
  static const double pi = 3.141592653589793;
  cin >> X;

  float x = 0.0, y = 1.0, theta;
  while (true) {
    theta = float(X * (K - 1) * pi) / 180.0;
    x += sin(theta);
    y += cos(theta);
    if (x < 0.001 && x > -0.001 && y < 0.001 && y > -0.001) {
      break;
    }
    K++;
  }
  cout << K;
}
Problem p02634 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<vi> vvi;
#define INF (1e9)
ll MOD = 998244353;

int main() {
  ll A, B, C, D;
  cin >> A >> B >> C >> D;

  vvi DP(C + 1, vi(D + 1));
  DP[A][B] = 1;
  for (int i = A + 1; i <= C; i++) {
    DP[i][B] = (DP[i - 1][B] * B) % MOD;
  }
  for (int j = B + 1; j <= D; j++) {
    DP[A][j] = (DP[A][j - 1] * A) % MOD;
  }

  for (int i = A + 1; i <= C; i++) {
    for (int j = B + 1; j <= D; j++) {
      DP[i][j] = DP[i - 1][j] * j + DP[i][j - 1] * i -
                 DP[i - 1][j - 1] * (i - 1) * (j - 1);
      while (DP[i][j] < 0)
        DP[i][j] += MOD;
      DP[i][j] %= MOD;
    }
  }

  ll ans = DP[C][D];
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<vi> vvi;
#define INF (1e9)
ll MOD = 998244353;

int main() {
  ll A, B, C, D;
  cin >> A >> B >> C >> D;

  vvi DP(C + 1, vi(D + 1));
  DP[A][B] = 1;
  for (int i = A + 1; i <= C; i++) {
    DP[i][B] = (DP[i - 1][B] * B) % MOD;
  }
  for (int j = B + 1; j <= D; j++) {
    DP[A][j] = (DP[A][j - 1] * A) % MOD;
  }

  for (int i = A + 1; i <= C; i++) {
    for (int j = B + 1; j <= D; j++) {
      DP[i][j] = DP[i - 1][j] * j + DP[i][j - 1] * i +
                 (MOD - DP[i - 1][j - 1]) * (i - 1) * (j - 1);
      DP[i][j] %= MOD;
    }
  }

  ll ans = DP[C][D];
  cout << ans << endl;
}
Problem p02634 (C++)

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

int main(void) {
  ios::sync_with_stdio(false);
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  const int MAX = 3001;
  const int64_t MOD = 998244353;
  vector<vector<int64_t>> DP(MAX, vector<int64_t>(MAX, 0));
  DP[A][B] = 1;
  for (int h = A; h <= C; ++h) {
    for (int w = B; w <= D; ++w) {
      DP[h + 1][w] = (DP[h + 1][w] + (DP[h][w] * w) % MOD) % MOD;
      DP[h][w + 1] = (DP[h][w + 1] + (DP[h][w] * h) % MOD) % MOD;
      int64_t sub = (DP[h][w] * h * w) % MOD;
      DP[h + 1][w + 1] = ((DP[h + 1][w + 1] - sub) + MOD) % MOD;
    }
  }
  cout << DP[C][D] << endl;
  return 0;
}

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

int main(void) {
  ios::sync_with_stdio(false);
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  const int MAX = 3002;
  const int64_t MOD = 998244353;
  vector<vector<int64_t>> DP(MAX, vector<int64_t>(MAX, 0));
  DP[A][B] = 1;
  for (int h = A; h <= C; ++h) {
    for (int w = B; w <= D; ++w) {
      DP[h + 1][w] = (DP[h + 1][w] + (DP[h][w] * w) % MOD) % MOD;
      DP[h][w + 1] = (DP[h][w + 1] + (DP[h][w] * h) % MOD) % MOD;
      int64_t sub = (DP[h][w] * h * w) % MOD;
      DP[h + 1][w + 1] = ((DP[h + 1][w + 1] - sub) + MOD) % MOD;
    }
  }
  cout << DP[C][D] << endl;
  return 0;
}
Problem p02634 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mod = 998244353;
int read() {
  int x = 0, f = 1;
  char ch = ' ';
  while (!isdigit(ch)) {
    ch = getchar();
    if (ch == '-')
      f = -1;
  }
  while (isdigit(ch))
    x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
  return x * f;
}
ll f[2005][2005];
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  f[a][b] = 1;
  for (int i = a; i <= c; i++) {
    for (int j = b; j <= d; j++) {
      if (i > a)
        f[i][j] += f[i - 1][j] * j;
      if (j > b)
        f[i][j] += f[i][j - 1] * i;
      if (i > a && j > b)
        f[i][j] -= (ll)(i - 1) * (j - 1) * f[i - 1][j - 1];
      f[i][j] %= mod;
    }
  }
  cout << (f[c][d] % mod + mod) % mod;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mod = 998244353;
int read() {
  int x = 0, f = 1;
  char ch = ' ';
  while (!isdigit(ch)) {
    ch = getchar();
    if (ch == '-')
      f = -1;
  }
  while (isdigit(ch))
    x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
  return x * f;
}
ll f[3005][3005];
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  f[a][b] = 1;
  for (int i = a; i <= c; i++) {
    for (int j = b; j <= d; j++) {
      if (i > a)
        f[i][j] += f[i - 1][j] * j;
      if (j > b)
        f[i][j] += f[i][j - 1] * i;
      if (i > a && j > b)
        f[i][j] -= (ll)(i - 1) * (j - 1) * f[i - 1][j - 1];
      f[i][j] %= mod;
    }
  }
  cout << (f[c][d] % mod + mod) % mod;
}
Problem p02634 (Python)

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

sys.setrecursionlimit(10**8)

input = sys.stdin.readline


def main():
    A, B, C, D = [int(x) for x in input().split()]

    MOD = 998244353

    dp = [[0] * (D - B + 1) for j in range(C - A + 1)]

    for j in range(C - A + 1):
        if j == 0:
            dp[j][0] = 1
        else:
            dp[j][0] = B**j % MOD
        for i in range(1, D - B + 1):
            if j == 0:
                dp[j][i] = dp[j][i - 1] * (A + j) % MOD
            else:
                dp[j][i] = (
                    dp[j][i - 1] * (A + j)
                    + (B + i) * dp[j - 1][i]
                    - dp[j - 1][i - 1] * ((A + j - 1) * (B + i - 1))
                ) % MOD

    print(dp[-1][-1] % MOD)


if __name__ == "__main__":
    main()


Fixed submission:
import sys

sys.setrecursionlimit(10**8)

input = sys.stdin.readline


def main():
    A, B, C, D = [int(x) for x in input().split()]

    MOD = 998244353

    dp = [[0] * (D - B + 1) for j in range(C - A + 1)]

    for j in range(C - A + 1):
        if j == 0:
            dp[j][0] = 1
        else:
            dp[j][0] = pow(B, j, MOD)
        for i in range(1, D - B + 1):
            if j == 0:
                dp[j][i] = dp[j][i - 1] * (A + j) % MOD
            else:
                dp[j][i] = (
                    dp[j][i - 1] * (A + j)
                    + (B + i) * dp[j - 1][i]
                    - dp[j - 1][i - 1] * ((A + j - 1) * (B + i - 1))
                ) % MOD

    print(dp[-1][-1] % MOD)


if __name__ == "__main__":
    main()
Problem p02634 (C++)

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

#define int long long
const int MOD = 998244353;
int dp[4000][4000];
int f(int a, int b) {
  if (~dp[a][b])
    return dp[a][b];
  return dp[a][b] = (f(a - 1, b) * b % MOD + f(a, b - 1) * a % MOD + MOD -
                     f(a - 1, b - 1) * (a - 1) % MOD * (b - 1) % MOD) %
                    MOD;
}

signed main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i <= 4000; i++)
    for (int j = 0; j <= 4000; j++)
      if (i < a || j < b)
        dp[i][j] = 0;
  dp[a][b] = 1;
  // for(int i=0;i<10;i++)for(int j=0;j<10;j++)cout<<i<<" "<<j<<"
  // "<<f(i,j)<<endl;
  cout << f(c, d) << endl;
}


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

#define int long long
const int MOD = 998244353;
int dp[4001][4001];
int f(int a, int b) {
  if (~dp[a][b])
    return dp[a][b];
  return dp[a][b] = (f(a - 1, b) * b % MOD + f(a, b - 1) * a % MOD + MOD -
                     f(a - 1, b - 1) * (a - 1) % MOD * (b - 1) % MOD) %
                    MOD;
}

signed main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i <= 4000; i++)
    for (int j = 0; j <= 4000; j++)
      if (i < a || j < b)
        dp[i][j] = 0;
  dp[a][b] = 1;
  // for(int i=0;i<10;i++)for(int j=0;j<10;j++)cout<<i<<" "<<j<<"
  // "<<f(i,j)<<endl;
  cout << f(c, d) << endl;
}
Problem p02634 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 998244353;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long double PI = acos(-1.0);
// cout << fixed << setprecision(14);

int dp[3010][3010];

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int A, B, C, D;
  cin >> A >> B >> C >> D;
  dp[A][B] = 1;
  for (int i = A; i <= C; i++) {
    for (int j = B; j <= D; j++) {
      if (i == A && j == B)
        continue;
      if (i == A) {
        dp[i][j] += dp[i][j - 1] * A;
      } else if (j == B) {
        dp[i][j] += dp[i - 1][j] * B;
      } else {
        dp[i][j] += dp[i][j - 1] * i + dp[i - 1][j] * j -
                    dp[i - 1][j - 1] * (i - 1) * (j - 1);
      }
      while (dp[i][j] <= 0)
        dp[i][j] += MOD;
      dp[i][j] %= MOD;
    }
  }
  cout << dp[C][D] << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 998244353;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long double PI = acos(-1.0);
// cout << fixed << setprecision(14);

int dp[3010][3010];

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int A, B, C, D;
  cin >> A >> B >> C >> D;
  dp[A][B] = 1;
  for (int i = A; i <= C; i++) {
    for (int j = B; j <= D; j++) {
      if (i == A && j == B)
        continue;
      if (i == A) {
        dp[i][j] += dp[i][j - 1] * A;
      } else if (j == B) {
        dp[i][j] += dp[i - 1][j] * B;
      } else {
        dp[i][j] += dp[i][j - 1] * i + dp[i - 1][j] * j -
                    dp[i - 1][j - 1] * (i - 1) * (j - 1);
      }
      dp[i][j] += MOD * MOD;
      dp[i][j] %= MOD;
    }
  }
  cout << dp[C][D] << endl;
}
Problem p02634 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
typedef long long ll;
const ll mod = 998244353;
const int N = 1e3 + 5;
using namespace std;
int dp[N][N][2];
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if (C > A)
    dp[C][D][0] = 1;
  if (D > B)
    dp[C][D][1] = 1;

  ll ans = 0;
  for (int i = C; i >= A; i--)
    for (int j = D; j >= B; j--) {
      dp[i][j - 1][0] = (dp[i][j - 1][0] + (ll)dp[i][j][1] * i) % mod;
      dp[i][j - 1][1] = (dp[i][j - 1][1] + (ll)dp[i][j][1] * i) % mod;
      dp[i - 1][j][0] = (dp[i - 1][j][0] + (ll)dp[i][j][0] * j) % mod;
      dp[i - 1][j][1] = (dp[i - 1][j][1] + (ll)dp[i][j][0]) % mod;

      if (i == A && j - 1 == B)
        ans = (ans + (ll)dp[i][j][1] * i) % mod;
      if (i - 1 == A && j == B)
        ans = (ans + (ll)dp[i][j][0] * j) % mod;
    }
  if (A == C && B == D)
    ans = 1;
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
typedef long long ll;
const ll mod = 998244353;
const int N = 3e3 + 5;
using namespace std;
int dp[N][N][2];
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if (C > A)
    dp[C][D][0] = 1;
  if (D > B)
    dp[C][D][1] = 1;

  ll ans = 0;
  for (int i = C; i >= A; i--)
    for (int j = D; j >= B; j--) {
      dp[i][j - 1][0] = (dp[i][j - 1][0] + (ll)dp[i][j][1] * i) % mod;
      dp[i][j - 1][1] = (dp[i][j - 1][1] + (ll)dp[i][j][1] * i) % mod;
      dp[i - 1][j][0] = (dp[i - 1][j][0] + (ll)dp[i][j][0] * j) % mod;
      dp[i - 1][j][1] = (dp[i - 1][j][1] + (ll)dp[i][j][0]) % mod;

      if (i == A && j - 1 == B)
        ans = (ans + (ll)dp[i][j][1] * i) % mod;
      if (i - 1 == A && j == B)
        ans = (ans + (ll)dp[i][j][0] * j) % mod;
    }
  if (A == C && B == D)
    ans = 1;
  cout << ans << endl;
  return 0;
}
Problem p02634 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 998244353;
typedef long long LL;

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  vector<vector<LL>> dp(C + 1, vector<LL>(D + 1, 0));
  dp[C][D] = 1;
  for (int c = D - 1; c >= B; --c) {
    dp[C][c] = C * dp[C][c + 1];
    dp[C][c] %= kMod;
  }
  for (LL r = C - 1; r >= A; --r) {
    for (LL c = B; c <= D; ++c) {
      dp[r][c] = c * dp[r + 1][c];
      dp[r][c] %= kMod;
      LL k = 1;
      for (int i = c + 1; i <= D; ++i) {
        k = (k * r) % kMod;
        dp[r][c] += k * dp[r + 1][i];
        dp[r][c] %= kMod;
      }
      //      cout << "dp[" << r << "][" << c << "] = " << dp[r][c] << endl;
    }
  }
  cout << dp[A][B] << endl;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 998244353;
typedef long long LL;

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  vector<vector<LL>> dp(C + 1, vector<LL>(D + 1, 0));
  dp[C][D] = 1;
  for (int c = D - 1; c >= B; --c) {
    dp[C][c] = C * dp[C][c + 1];
    dp[C][c] %= kMod;
  }
  for (LL r = C - 1; r >= A; --r) {
    LL S = 0;
    dp[r][D] = (D * dp[r + 1][D]) % kMod;
    for (LL c = D - 1; c >= B; --c) {
      S = (r * (S + dp[r + 1][c + 1])) % kMod;
      dp[r][c] = (c * dp[r + 1][c] + S) % kMod;
    }
  }
  cout << dp[A][B] << endl;
}