alexjercan/bugnet huggingface dataset:
Problem p02685 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for (int i = a; i < (int)b; ++i)
#define rrep(i, n) for (int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 998244353;

const int MAX = 1e6;

long long 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;
  }
}

long long 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;
}

template <typename T> T modpower(T a, T n, T mod) {
  T res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(0);
  COMinit();
  int n, m, k;
  cin >> n >> m >> k;
  ll res = 0;
  rep(i, k + 1) {
    ll tmp = 1;
    tmp = m * modpower((ll)m - 1, (ll)n - 1 - i, MOD);
    tmp %= MOD;
    tmp *= COM(n - 1, i);
    tmp %= MOD;
    res += tmp;
    res %= MOD;
  }
  cout << res << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for (int i = a; i < (int)b; ++i)
#define rrep(i, n) for (int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 998244353;

ll modpower(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;
}

ll modinv(ll a, ll mod) { return modpower(a, mod - 2, mod); }

ll largeCOM(ll n, ll r, ll mod) {
  ll u = 1, d = 1;
  rep(i, r) {
    u = (u * (n - i)) % mod;
    d = (d * (r - i)) % mod;
  }
  return u * modinv(d, mod) % mod;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(0);
  int n, m, k;
  cin >> n >> m >> k;
  ll res = 0;
  rep(i, k + 1) {
    ll tmp = 1;
    tmp = m * modpower((ll)m - 1, (ll)n - 1 - i, MOD);
    tmp %= MOD;
    tmp *= largeCOM((ll)n - 1, (ll)i, MOD);
    tmp %= MOD;
    res += tmp;
    res %= MOD;
  }
  cout << res << endl;

  return 0;
}
Problem p02685 (C++) — buggy submission, verdict: Runtime Error

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

#include <iostream>
using namespace std;

const long long MAX = 200005;
const long long MOD = 998244353;

long long 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;
  }
}

// 二項係数計算
long long 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;
}

int main() {
  COMinit();
  int N, M, K;
  cin >> N >> M >> K;

  long long cur = M;
  long long ans = 0;
  for (int x = N - 1; x >= 0; --x) {
    if (x <= K) {
      long long now = cur;
      now *= COM(N - 1, x);
      ans = (ans + now) % MOD;
    }
    cur = cur * (M - 1) % MOD;
  }

  cout << ans << endl;
}


Error: 0

Fixed submission:

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

int main() {
  long long int N, M, K;
  cin >> N >> M >> K;
  vector<vector<long long int>> dp(N + 1, vector<long long int>(K + 1));
  dp[0][0] = M;

  for (int i = 1; i < N; ++i)
    dp[i][0] = dp[i - 1][0] * (M - 1) % 998244353;

  for (int k = 0; k < K; ++k) {
    for (int i = 0; i < N; ++i) {
      dp[i + 1][k + 1] = (dp[i][k] + dp[i + 1][k] * (M - 1)) % 998244353;
    }
  }

  long long int ans = 0;
  for (int i = 0; i <= K; ++i) {
    ans = (ans + dp[N - 1][i]) % 998244353;
  }
  cout << ans << endl;
}
Problem p02685 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define int long long
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
using namespace std;

int mod = 998244353;

int expo(int num, int p) {
  if (num == 0) {
    if (p == 0)
      return 1;
    return 0;
  }
  num = num % mod;
  int ret = 1;
  while (p) {
    if (p & 1)
      ret = (ret * num) % mod;
    num = (num * num) % mod;
    p /= 2;
  }
  return ret;
}

signed main() {
  IOS;
  int fact[200005], inv[200005];
  fact[0] = 1;
  for (int i = 1; i < 200005; ++i)
    fact[i] = (fact[i - 1] * i) % mod;
  for (int i = 0; i < 200005; ++i)
    inv[i] = expo(fact[i], mod - 2);
  int n, m, k;
  cin >> n >> m >> k;
  int ans = 0;
  // if(m == 1) {
  //     if(k == n - 1) cout << 1;
  //     else cout << 0;
  //     return 0;
  // }
  for (int i = 0; i <= k; ++i) {
    int cur = (m * expo(m - 1, n - i - 1)) % mod;
    cur = (cur * fact[n - 1]) % mod;
    cur = (cur * inv[i]) % mod;
    cur = (cur * inv[n - i - 1]) % mod;
    ans = (ans + cur) % mod;
  }
  cout << ans << "\\n";

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define int long long
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
using namespace std;

int mod = 998244353;

int expo(int num, int p) {
  if (num == 0) {
    if (p == 0)
      assert(false);
    return 0;
  }
  num = num % mod;
  int ret = 1;
  while (p) {
    if (p & 1)
      ret = (ret * num) % mod;
    num = (num * num) % mod;
    p /= 2;
  }
  return ret;
}

signed main() {
  IOS;
  int fact[200005], inv[200005];
  fact[0] = 1;
  for (int i = 1; i < 200005; ++i)
    fact[i] = (fact[i - 1] * i) % mod;
  for (int i = 0; i < 200005; ++i)
    inv[i] = expo(fact[i], mod - 2);
  int n, m, k;
  cin >> n >> m >> k;
  int ans = 0;
  // if(m == 1) {
  //     if(k == n - 1) cout << 1;
  //     else cout << 0;
  //     return 0;
  // }
  for (int i = 0; i <= k; ++i) {
    int cur = (m * expo(m - 1, n - i - 1)) % mod;
    cur = (cur * fact[n - 1]) % mod;
    cur = (cur * inv[i]) % mod;
    cur = (cur * inv[n - i - 1]) % mod;
    ans = (ans + cur) % mod;
  }
  cout << ans << "\\n";

  return 0;
}
Problem p02685 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 998244353;
const long double PI = 3.14159265358979;
const ll MAX = 200020;

long long modpow(long long x, long long y) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) {
      ans *= x % MOD;
    }
    x *= x % MOD;
    x %= MOD;
    ans %= MOD;
    y >>= 1;
  }
  return ans;
}

ll fac[MAX];
ll faci[MAX];

void modCf() {
  fac[0] = 1;
  faci[0] = 1;
  for (int i = 1; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    faci[i] = modpow(fac[i], MOD - 2);
  }
  return;
}

ll modC(ll x, ll y) {
  ll ans = fac[x];
  ans = ans * faci[y] % MOD;
  ans = ans * faci[x - y] % MOD;
  return ans;
}

int main() {
  ll M, N, K;
  cin >> N >> M >> K;
  modCf();
  ll ans = 0;
  ll c = 0;
  ll m[N];
  m[0] = 1;
  for (int i = 1; i < N; i++) {
    m[i] = m[i - 1] * (M - 1);
    m[i] %= MOD;
  }

  for (ll i = 0; i <= K; i++) {
    ll cnt = M;
    // cout<<cnt;
    cnt *= modC(N - 1, i);
    // cout<<cnt;
    cnt %= MOD;
    // cout<<cnt;
    cnt *= m[N - 1 - i];
    cnt %= MOD;
    // cout<<cnt;
    ans += cnt;
    ans %= MOD;
    // cout<<ans<<cnt;
  }
  cout << ans;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 998244353;
const long double PI = 3.14159265358979;

long long modpow(long long x, long long y, long long z) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) {
      ans *= x % z;
    }
    x *= x % z;
    x %= z;
    ans %= z;
    y >>= 1;
  }
  return ans;
}

long long modC(long long x, long long y, long long z) {
  long long X = 1, Y = 1;
  for (long long i = x; i >= (x - y + 1); i--) {
    X *= i;
    X %= z;
  }
  for (long long i = 1; i <= y; i++) {
    Y *= i;
    Y %= z;
  }
  Y = modpow(Y, z - 2, z);
  X *= Y;
  X %= z;
  return X;
}

int main() {
  ll M, N, K;
  cin >> N >> M >> K;
  ll ans = 0;
  ll c = 0;
  ll m[N];
  m[0] = 1;
  for (int i = 1; i < N; i++) {
    m[i] = m[i - 1] * (M - 1);
    m[i] %= MOD;
  }

  for (ll i = 0; i <= K; i++) {
    ll cnt = M;
    cnt *= modC(N - 1, i, MOD);
    cnt %= MOD;
    cnt *= m[N - 1 - i];
    cnt %= MOD;
    ans += cnt;
    ans %= MOD;
    //
  }

  ll all = modpow(M, N, MOD);
  if (all < ans) {
    all += MOD;
  }
  if (c) {
    cout << all - ans;
  } else {
    cout << ans;
  }
}
Problem p02685 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 998244353;

int power(ll a, ll b = mod - 2) {
  ll res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return res;
}

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> num(n);
  num[0] = m;
  for (int i = 1; i < n; i++) {
    num[i] = (m - 1) * num[i - 1];
    num[i] %= mod;
  }
  reverse(num.begin(), num.end());
  // cout << num[0] << endl;

  vector<ll> c(k + 1);
  ll ans = 0;
  ll bunsi = 1;

  for (ll i = 1; i <= n - 1; i++) {
    bunsi *= i;
    bunsi %= mod;
  }

  // cout << bunsi << endl;
  c[0] = bunsi;
  for (int i = 1; i <= k; i++) {
    c[i] = c[i - 1];
    c[i] *= i;
    c[i] %= mod;
    // cout << c[i] << " ";
    c[i] *= power(n - i, mod - 2);
    c[i] %= mod;
    // cout << c[i] << endl;
  }

  for (int i = 0; i <= k; i++) {
    ll x = bunsi;
    x *= power(c[i], mod - 2);
    x %= mod;
    // cout << power(c[i],mod-2) << " ";
    x *= num[i];
    x %= mod;
    ans += x;
    ans %= mod;
    // cout << num[i] << " " << ans << endl;
  }

  cout << ans << endl;

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 998244353;

int power(ll a, ll b = mod - 2) {
  ll res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return res;
}

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> num(n + 1);
  num[0] = m;
  for (int i = 1; i <= n; i++) {
    num[i] = (m - 1) * num[i - 1];
    num[i] %= mod;
  }
  reverse(num.begin(), num.end());

  vector<ll> c(k);
  ll ans = 0;
  ll bunsi = 1;

  for (ll i = 1; i <= n - 1; i++) {
    bunsi *= i;
    bunsi %= mod;
  }
  // cout << bunsi << endl;
  c[0] = bunsi;
  for (int i = 1; i <= k; i++) {
    c[i] = c[i - 1];
    c[i] *= i;
    c[i] %= mod;
    // cout << c[i] << " ";
    c[i] *= power(m - i, mod - 2);
    c[i] %= mod;
    // cout << c[i] << endl;
  }

  for (int i = 0; i < k; i++) {
    ll x = bunsi * c[i];
    x %= mod;
    x *= num[i];
    x %= mod;
    ans += x;
  }

  cout << ans << endl;

  return 0;
}
Problem p02685 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 998244353;
using Graph = vector<vector<int>>;
const int MAX = 510000;
long long 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;
  }
}

// 二項係数計算
long long 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;
}

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

  COMinit();
  int N, M, K;
  cin >> N >> M >> K;
  int ans = 0;
  int sum = M;
  rep(i, N - K - 1) {
    sum *= M - 1;
    sum %= MOD;
  }
  for (int i = K; i >= 0; i--) {

    int c = COM(N - 1, i);
    c %= MOD;
    ans += (sum * c) % MOD;
    ans %= MOD;
    sum *= M - 1;
    sum %= MOD;
  }

  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 998244353;
using Graph = vector<vector<int>>;
const int MAX = 510000;
long long 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;
  }
}

// 二項係数計算
long long 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;
}

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

  COMinit();
  int N, M, K;
  cin >> N >> M >> K;
  int ans = 0;
  rep(i, K + 1) {
    int sum = M;
    rep(j, N - 1 - i) {
      sum *= M - 1;
      sum %= MOD;
    }
    sum *= COM(N - 1, i);
    sum %= MOD;
    ans += sum;
    ans %= MOD;
  }
  cout << ans << endl;
}
Problem p02685 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define rep(i, l, r) for (int i = l, i##end = r; i <= i##end; ++i)
#define per(i, l, r) for (int i = l, i##end = r; i >= i##end; --i)
#define repo(i, l, r) for (int i = l, i##end = r; i < i##end; ++i)
#define pero(i, l, r) for (int i = l, i##end = r; i > i##end; --i)
#define debug(x) cerr << "debug(" << #x << ')' << ": " << x << " " << endl
typedef long long ll;
using namespace std;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int MAXN = 2 * 1e5 + 5;
const int mod = 998244353;
const double PI = acos(-1);
inline int read() {
  int s = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    s = s * 10 + ch - '0', ch = getchar();
  return s * w;
}
// int cmpfunc (const void * a, const void * b){return ( *(int*)a - *(int*)b );}
// rise; qsort (a, n, sizeof(int), cmpfunc);

/*struct cmp{bool operator( ) (int x, int y) const {return a[x] + b[x] > a[y] +
 * b[y];}};*/

ll inv[MAXN];
ll f[MAXN];

ll ksm(ll ans, ll p) {
  ll res = 1;
  while (p) {
    if (p & 1)
      res = res * ans % mod;
    p >>= 1;
    ans = ans * ans % mod;
  }
  return res;
}
ll c(ll a, ll b) { return f[a] * inv[a - b] % mod * inv[b] % mod; }

void solve() {
  ll n, m, k;
  cin >> n >> m >> k;

  int maxn = max(n, m);
  f[0] = 1;
  for (ll i = 1; i <= maxn; i++)
    f[i] = f[i - 1] * i % mod; // 求i!
  inv[maxn] = ksm(f[maxn], mod - 2);
  for (ll i = maxn - 1; i >= 0; i--)
    inv[i] = inv[i + 1] * (i + 1) % mod; // 求逆元

  ll ans = 0; // C(n-1,n-1-i)*m*(m-1)^(n-1-i) //n-1-i为隔板数
  ll tem = ksm(m - 1, n - 1 - k);
  for (int i = n - 1 - k; i <= n - 1; i++) {
    ans = ans + c(n - 1, i) % mod * m % mod * tem % mod;
    ans = ans % mod;
    tem = tem * (m - 1) % mod;
  }
  cout << ans;
}

int main() {
#ifdef ACM_LOCAL
  freopen("in.txt", "r", stdin);
#endif
  //	int T; cin >> T;
  //	while(T--)
  solve();
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
long long data[2000000];
int n, m, k;
long long p(int n) {
  if (data[n])
    return data[n];
  long long out = 0;
  for (int i = 1; i <= k + 1; i++)
    out += p(n - i);
  out *= (m - 1);
  return data[n] = (out % 998244353);
}
int main() {

  scanf("%d%d%d", &n, &m, &k);
  data[0] = 1;
  for (int i = 1; i <= k + 1; i++)
    data[i] = data[i - 1] * m;
  printf("%lld", p(n));
}
Problem p02685 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <vector>

using namespace std;

#define MOD 998244353
#define MAX_N 200010

typedef long long ll;

int N, M, K;

ll f[MAX_N], rf[MAX_N];
ll inv(ll x) {
  ll res = 1;
  ll k = MOD - 2;
  ll y = x;
  while (k) {
    if (k & 1)
      res = (res * y) % MOD;
    y = (y * y) % MOD;
    k /= 2;
  }
  return res;
}
void init() {
  f[0] = 1;
  for (int i = 1; i < MAX_N; i++)
    f[i] = (f[i - 1] * i) % MOD;
  for (int i = 0; i < MAX_N; i++)
    rf[i] = inv(f[i]);
}
ll comb(int n, int k) {
  ll a = f[n];      // = n!
  ll b = rf[n - k]; // = (n-k)!
  ll c = rf[k];     // = k!

  ll bc = (b * c) % MOD;

  return (a * bc) % MOD;
}

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

ll modinv(ll a) { return modpow(a, MOD - 2); }

void solve() {
  ll ans = 0;

  for (int k = 0; k <= K; k++) {
    ll n = modpow(M - 1, N - k - 1);
    n = (n * M) % MOD;
    ans = ans + (n * comb(N - 1, k)) % MOD;
  }

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

int main() {
  scanf("%d %d %d", &N, &M, &K);

  init();

  solve();
}


Error: 0

Fixed submission:

#include <cstdio>
#include <vector>

using namespace std;

#define MOD 998244353

typedef long long ll;

vector<ll> ifac(300001); // k!^{M-2} (mod M)
vector<ll> fac(300001);  // n!(mod M)

int N, M, K;

ll f[101010], rf[101010];
ll inv(ll x) {
  ll res = 1;
  ll k = MOD - 2;
  ll y = x;
  while (k) {
    if (k & 1)
      res = (res * y) % MOD;
    y = (y * y) % MOD;
    k /= 2;
  }
  return res;
}
void init() {
  f[0] = 1;
  for (int i = 1; i < 101010; i++)
    f[i] = (f[i - 1] * i) % MOD;
  for (int i = 0; i < 101010; i++)
    rf[i] = inv(f[i]);
}
ll comb(int n, int k) {
  ll a = f[n];      // = n!
  ll b = rf[n - k]; // = (n-k)!
  ll c = rf[k];     // = k!

  ll bc = (b * c) % MOD;

  return (a * bc) % MOD;
}

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

ll modinv(ll a) { return modpow(a, MOD - 2); }

void solve() {
  ll ans = 0;

  for (int k = 0; k <= K; k++) {
    ll n = modpow(M - 1, N - k - 1);
    n = (n * M) % MOD;
    ans = ans + (n * comb(N - 1, k)) % MOD;
  }

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

int main() {
  scanf("%d %d %d", &N, &M, &K);

  init();

  solve();
}
Problem p02685 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 998244353;

ll modPow(ll a, ll n, ll p) {
  if (n == 0)
    return 1;
  if (n == 1)
    return a % p;
  if (n % 2 == 1)
    return (a * modPow(a, n - 1, p)) % p;
  ll t = modPow(a, n / 2, p);
  return (t * t) % p;
}

ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}
ll fact[200003];
ll ifact[200003];
ll Combination(ll a, ll b) {
  ll s = (fact[a] * ifact[b]) % Mod;
  return (s * ifact[a - b]) % Mod;
}

int main() {
  fact[0] = 1;
  ifact[0] = 1;
  for (int i = 1; i <= 200003; i++) {
    fact[i] = fact[i - 1] * i;
    fact[i] %= Mod;
    ifact[i] = modinv(fact[i], Mod);
  }
  ll N, M, K;
  cin >> N >> M >> K;
  if (M == 1) {
    if (N - 1 == K) {
      cout << 1 << endl;
      return 0;
    } else {
      cout << 0 << endl;
      return 0;
    }
  }
  ll ans = 0;
  for (int i = 0; i <= K; i++) {
    ll res = 1;
    res *= M;
    res *= modPow(max(1ll, M - 1), N - 1 - i, Mod);
    res %= Mod;
    res *= Combination(max(1ll, N - 1), i);
    res %= Mod;
    ans += res;
    ans %= Mod;
  }
  if (ans < 0) {
    ans += Mod;
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 998244353;

ll modPow(ll a, ll n, ll p) {
  if (n == 1)
    return a % p;
  if (n % 2 == 1)
    return (a * modPow(a, n - 1, p)) % p;
  ll t = modPow(a, n / 2, p);
  return (t * t) % p;
}

ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}
ll fact[200003];
ll ifact[200003];
ll Combination(ll a, ll b) {
  ll s = (fact[a] * ifact[b]) % Mod;
  return (s * ifact[a - b]) % Mod;
}

int main() {
  fact[0] = 1;
  ifact[0] = 1;
  for (int i = 1; i <= 200003; i++) {
    fact[i] = fact[i - 1] * i;
    fact[i] %= Mod;
    ifact[i] = modinv(fact[i], Mod);
  }
  ll N, M, K;
  cin >> N >> M >> K;
  ll ans = 0;
  for (int i = 0; i <= K; i++) {
    ll res = 1;
    res *= M;
    res *= modPow(M - 1, N - 1 - i, Mod);
    res %= Mod;
    res *= Combination(N - 1, i);
    res %= Mod;
    ans += res;
    ans %= Mod;
  }
  if (ans < 0) {
    ans += Mod;
  }
  cout << ans << endl;
  return 0;
}
Problem p02685 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long
constexpr int MOD = 998244353;
constexpr int N = 200000 + 100;

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

class Combination {
private:
  vector<int> fact, rev_fact;

public:
  Combination(int n) { setFact(n); }
  void setFact(int n) {
    fact.resize(n + 1);
    rev_fact.resize(n + 1);
    fact[0] = 1;
    for (int i = 1; i <= n; i++) {
      fact[i] = fact[i - 1] * i;
      fact[i] %= MOD;
    }
    rev_fact[n] = modpow(fact[n], MOD - 2);
    for (int i = n - 1; i >= 0; i--) {
      rev_fact[i] = rev_fact[i + 1] * (i + 1);
      rev_fact[i] %= MOD;
    }
  }
  int c(int n, int k) {
    if (k > n)
      return 0;
    return (((fact[n] * rev_fact[k]) % MOD) * rev_fact[n - k]) % MOD;
  }
  int h(int n, int k) { return c(n + k - 1, k); }
};

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

  int n, m, k;
  cin >> n >> m >> k;

  Combination combi(N);

  int ans = 0;

  for (int i = 0; i <= k; i++) {
    const int add =
        combi.c(n - 1, i) * m % MOD * modpow(m - 1, n - 1 - i) % MOD;
    ans = (ans + add) % MOD;
  }

  cout << ans % MOD << endl;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long
constexpr int MOD = 998244353;
constexpr int N = 400000 + 100;

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

class Combination {
private:
  vector<int> fact, rev_fact;

public:
  Combination(int n) { setFact(n); }
  void setFact(int n) {
    fact.resize(n + 1);
    rev_fact.resize(n + 1);
    fact[0] = 1;
    for (int i = 1; i <= n; i++) {
      fact[i] = fact[i - 1] * i;
      fact[i] %= MOD;
    }
    rev_fact[n] = modpow(fact[n], MOD - 2);
    for (int i = n - 1; i >= 0; i--) {
      rev_fact[i] = rev_fact[i + 1] * (i + 1);
      rev_fact[i] %= MOD;
    }
  }
  int c(int n, int k) {
    return (((fact[n] * rev_fact[k]) % MOD) * rev_fact[n - k]) % MOD;
  }
  int h(int n, int k) { return c(n + k - 1, k); }
};

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

  int n, m, k;
  cin >> n >> m >> k;

  Combination combi(N);

  int ans = 0;

  for (int i = 0; i <= k; i++) {
    ans += ((combi.c(n - i, i) % MOD) * m % MOD) % MOD *
           modpow(m - 1, n - 1 - i) % MOD;
    ans %= MOD;
  }

  cout << ans << endl;
}