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

#include <iostream>
#include <vector>

const static int M = 998244353;
const static int MAX = 300000;
std::vector<long long> kai(MAX), pkai(MAX);

// int combination(int n, int k){
//     int ans;
//     return ans;
// }

long long pow(long long a, long long b) {
  long long tmp = 1;
  if (a == 0 && b == 0) {
    return 1;
  }
  if (a == 0) {
    return 0;
  }
  if (b == 0) {
    return 1;
  } else if (b % 2 == 0) {
    tmp = pow(a, b / 2) % M;
    tmp = (tmp * tmp) % M;
    return tmp;
  } else {
    tmp = pow(a, b / 2) % M;
    tmp = (tmp * tmp) % M;
    tmp = (tmp * a) % M;
    return tmp;
  }
}

long long combination(int n, int k) {
  return ((kai[n] * pkai[k] % M) * pkai[(n - k)]) % M;
}

int main(void) {
  int n, m, k;
  std::cin >> n >> m >> k;

  kai[0] = 1;
  pkai[0] = 1;
  for (int i = 1; i < MAX; i++) {
    kai[i] = (i * kai[i - 1]) % M;
    pkai[i] = pow(kai[i], M - 2);
    // std::cout << pkai[i] << " ";
  }
  // std::cout << std::endl;
  long long ans = 0;
  long long tmp = pow((m - 1), n - k - 1);
  for (int i = k; i >= 0; i--) {
    ans = (ans + ((combination(n - 1, i) * m) % M * tmp) % M) % M;
    tmp = tmp * (m - 1) % M;
  }
  std::cout << ans << std::endl;

  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
#include <vector>

const static int M = 998244353;
const static int MAX = 1000;
std::vector<long long> kai(MAX), pkai(MAX);

// int combination(int n, int k){
//     int ans;
//     return ans;
// }

long long pow(long long a, long long b) {
  long long tmp = 1;
  if (b == 0) {
    return 1;
  } else if (b % 2 == 0) {
    tmp = pow(a, b / 2) % M;
    tmp *= tmp % M;
    return tmp;
  } else {
    tmp = pow(a, b / 2) % M;
    tmp = (tmp * tmp) % M;
    tmp = (tmp * a) % M;
    return tmp;
  }
}

long long combination(int n, int k) {
  return ((kai[n] * pkai[k] % M) * pkai[(n - k)]) % M;
}

int main(void) {
  int n, m, k;
  std::cin >> n >> m >> k;

  kai[0] = 1;
  pkai[0] = 1;
  for (int i = 1; i < MAX; i++) {
    kai[i] = (i * kai[i - 1]) % M;
    pkai[i] = pow(kai[i], M - 2);
    // std::cout << pkai[i] << " ";
  }
  // std::cout << std::endl;
  long long ans = 0;
  long long tmp = pow((m - 1), n - k - 1);
  for (int i = k; i >= 0; i--) {
    ans = (ans + ((combination(n - 1, i) * m) % M * tmp) % M) % M;
    tmp = tmp * (m - 1) % M;
  }
  std::cout << ans << std::endl;

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

#include <bits/stdc++.h>

#define hell2 1000000007
#define hell 998244353
#define lcm(a, b) (a * b) / __gcd(a, b)
#define ll long long
#define vll vector<ll>
#define pll vector<pair<ll, ll>>
#define pb push_back
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define ret(x) return cout << x, 0;
#define endl '\\n'

const ll MAX = 300005;
const ll SQN = 330;
const ll LG = 22;
const double PI = atan(1) * 4;
using namespace std;

ll fact[MAX];
void f() {
  fact[0] = fact[1] = 1;
  rep(i, 2, MAX) { fact[i] = (fact[i - 1] * i) % hell; }
}

ll expo(ll a, ll b, ll p) {
  ll res = 1;
  a %= p;
  while (b > 0) {
    if (b & 1) {
      res = (res * a) % p;
    }
    a = (a * a) % p;
    b >>= 1;
  }
  return res;
}

ll inv(ll a, ll p) { return expo(a, p - 2, p); }

ll C(ll x, ll y) {
  if (y == 0)
    return 1;
  if (x < y)
    return 0;
  return ((fact[x] * inv(fact[x - y], hell)) % hell) * (inv(fact[y], hell)) %
         hell;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  f();
  ll n, m, k;
  cin >> n >> m >> k;

  ll ans = 0;
  rep(i, 0, k + 1) {
    // i same;
    ll same = C(n - 1, i);
    ll cost = m;
    ll rem = n - i - 1;
    cost = (cost * expo(m - 1, rem, hell)) % hell;
    cost = (cost * same) % hell;
    ans = (ans + cost) % hell;
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define hell2 1000000007
#define hell 998244353
#define lcm(a, b) (a * b) / __gcd(a, b)
#define ll long long
#define vll vector<ll>
#define pll vector<pair<ll, ll>>
#define pb push_back
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define ret(x) return cout << x, 0;
#define endl '\\n'

const ll MAX = 300005;
const ll SQN = 330;
const ll LG = 22;
const double PI = atan(1) * 4;
using namespace std;

ll fact[MAX];
ll f() {
  fact[0] = fact[1] = 1;
  rep(i, 2, MAX) { fact[i] = (fact[i - 1] * i) % hell; }
}

ll expo(ll a, ll b, ll p) {
  ll res = 1;
  a %= p;
  while (b > 0) {
    if (b & 1) {
      res = (res * a) % p;
    }
    a = (a * a) % p;
    b >>= 1;
  }
  return res;
}

ll inv(ll a, ll p) { return expo(a, p - 2, p); }

ll C(ll x, ll y) {
  if (y == 0)
    return 1;
  if (x < y)
    return 0;
  return ((fact[x] * inv(fact[x - y], hell)) % hell) * (inv(fact[y], hell)) %
         hell;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  f();
  ll n, m, k;
  cin >> n >> m >> k;

  ll ans = m;
  ans = (ans * expo(m - 1, n - 1, hell)) % hell;
  rep(i, 1, k + 1) {
    // i same;
    ll same = C(n - 1, i);
    ll cost = m;
    ll rem = n - i - 1;
    if (m == 1)
      cost = 0;
    else {
      cost = (cost * expo(m - 1, rem, hell)) % hell;
      cost = (cost * same) % hell;
    }
    ans = (ans + cost) % hell;
  }
  cout << ans << endl;
}
Problem p02685 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 998244353;
const ll maxn = 200005;
ll fac[maxn], inv[maxn];
void inverse(int n) {
  inv[1] = 1;
  for (int i = 2; i <= n; i++) {
    inv[i] = (mod - mod / i) * inv[mod % i] % mod;
  }
}
void init(int n) {
  fac[0] = 1;
  inv[0] = 1;
  inverse(n);
  for (int i = 1; i <= n; i++) {
    fac[i] = fac[i - 1] * i % mod, inv[i] = inv[i - 1] * inv[i] % mod;
  }
}
ll c(int n, int m) { return fac[n] * inv[m] % mod * inv[n - m] % mod; }
ll quickp(ll a, ll n) {
  ll ans = 1;
  while (n) {
    if (n & 1)
      ans = ans * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return ans;
}
int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  init(n);
  ll p = quickp(m - 1, n - 1 - k);
  ll ans = 0;
  for (int i = k; i >= 0; i--) {
    ans = (ans + c(n - 1, i) * m % mod * p % mod) % mod, p = p * (m - 1) % mod;
  }
  printf("%lld\\n", ans);
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 998244353;
ll inv(ll a) {
  return a == 1 ? 1 : (long long)(mod - mod / a) * inv(mod % a) % mod;
}
ll quickp(ll a, ll n) {
  a %= mod;
  ll ans = 1;
  while (n) {
    if (n & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
    n >>= 1;
  }
  return ans;
}
ll inv2(ll a) { return quickp(a, mod - 2); }
ll c(ll n, ll m) {
  if (m < 0)
    return 0;
  if (n < m)
    return 0;
  if (m > n - m)
    m = n - m;
  ll up = 1, down = 1;
  for (ll i = 0; i < m; i++) {
    up = up * (n - i) % mod;
    down = down * (i + 1) % mod;
  }
  return up * inv2(down) % mod;
}
int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  ll ans = 0;
  for (int i = 0; i <= k; i++) {
    ans =
        (ans + (c(n - 1, i) * m % mod * quickp(m - 1, n - 1 - i)) % mod) % mod;
  }
  printf("%lld\\n", ans);
}
Problem p02685 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double ld;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define INF 100000000
#define MAX 200001
#define MOD 998244353
ll fac[MAX], finv[MAX], inv[MAX];
typedef vector<vector<int>> Graph;
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;
}
ll RepeatSquare(ll a, ll b, ll mod) {
  if (b == 0)
    return 1;
  if (b % 2 == 0) {
    ll t = RepeatSquare(a, b / 2, mod);
    t %= mod;
    return t * t % mod;
  }
  return a * RepeatSquare(a, b - 1, mod);
}
int main() {
  COMinit();
  ll ans = 0;
  ll n, m, k;
  cin >> n >> m >> k;
  for (int i = 0; i < k + 1; i++) {
    ll cnt = (m * COM(n - 1, i)) % MOD *
             (RepeatSquare(m - 1, n - 1 - i, MOD) % MOD) % MOD;
    ans += cnt;
    ans %= MOD;
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
ll MOD = 998244353;

int modPow(long long a, long long n, long long p) {
  if (n == 1)
    return a % p;
  if (n % 2 == 1)
    return (a * modPow(a, n - 1, p)) % p;
  long long t = modPow(a, n / 2, p);
  return (t * t) % p;
}
const int MAX = 1000000;

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  ll ans = 0;
  vector<ll> fact(1000000);
  vector<ll> inv(1000000);
  vector<ll> fact_inv(1000000);
  for (int i = 2; i < 1000000; i++) {
    fact[i] = fact[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    fact_inv[i] = fact_inv[i - 1] * inv[i] % MOD;
  }
  for (int i = 0; i <= k; i++) {
    ll a = modPow(m, 1 + i, MOD);
    ll b = modPow(m - 1, n - 1 - i, MOD);
    ans += a * b;
    ans %= MOD;
  }
  cout << ans << endl;
}
Problem p02685 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define rep(i, N) for (ll i = 0; i < N; i++)
#define rep1(i, N) for (ll i = 1; i <= N; i++)
#define repr(i, N) for (ll i = N - 1; i >= 0; i--)
#define repr1(i, N) for (ll i = N; i > 0; i--)

#define MOD 998244353

using ll = long long;
using namespace std;

typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<P> vpi;
typedef pair<ll, ll> Pl;
typedef vector<ll> vl;
typedef vector<Pl> vpl;

ll gcd(ll a, ll b) { // aとbの最大公約数を求める
  if (a < b)
    swap(a, b);
  if (b <= 0)
    return -1;
  ll r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) { // aとbの最小公倍数を求める(gcd要)
  return (a / gcd(a, b) * b);
}

/*nCk (mod MOD)の計算 BEGIN*/
// faccal -> n!, k!^(MOD-2)の計算(初期化)
// comb -> nCk (mod MOD)の計算
ll mlpow(ll x, ll p) { // x^p(long long)%MOD
  ll tmp = 1;
  if (p == 0)
    return 1;
  while (p != 0) {
    if (p & 1)
      tmp = tmp * x % MOD;
    x = x * x % MOD;
    p = p >> 1;
  }
  return tmp;
}

int facnum = 200005;
vl fac(facnum);   // n!
vl facM2(facnum); // k!^(MOD-2)

void faccal(ll up) {
  fac[0] = 1;
  facM2[0] = 1;
  for (ll i = 0; i < up + 1; i++) {
    fac[i + 1] = fac[i] * (i + 1) % MOD; // n!(mod M)
    facM2[i + 1] = facM2[i] * mlpow(i + 1, MOD - 2) %
                   MOD; // k!^{M-2} (mod M) ←累乗にmpowを採用
  }
}

ll comb(ll n, ll k) {
  if (n == 0 && k == 0)
    return 1;
  if (n < k || n < 0)
    return 0;
  ll tmp = facM2[n - k] * facM2[k] % MOD;
  return tmp * fac[n] % MOD; // nCk = n!*(k!)^(M-2)*((n-k)!)^(M-2)
}
/*nCk (mod MOD)の計算 END*/

int main() {
  int N, M, K;
  ll ans = 0;
  cin >> N >> M >> K;

  faccal(N);

  rep(i, K + 1) {
    ll tmpM1 = mlpow(M - 1, N - 1 - i);
    ll tmpM = M;
    tmpM = tmpM * tmpM1 % MOD;
    tmpM = tmpM * comb(N - 1, i) % MOD;
    ans = (ans + tmpM) % MOD;
  }

  cout << ans << "\\n";
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define rep(i, N) for (ll i = 0; i < N; i++)
#define rep1(i, N) for (ll i = 1; i <= N; i++)
#define repr(i, N) for (ll i = N - 1; i >= 0; i--)
#define repr1(i, N) for (ll i = N; i > 0; i--)

#define MOD 998244353

using ll = long long;
using namespace std;

typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<P> vpi;
typedef pair<ll, ll> Pl;
typedef vector<ll> vl;
typedef vector<Pl> vpl;

ll gcd(ll a, ll b) {
  if (a < b)
    swap(a, b);
  if (b <= 0)
    return -1;
  ll r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) { return (a / gcd(a, b) * b); }

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

  // K=0
  rep(i, 1) {
    ans *= M;
    ans %= MOD;
  }
  rep(i, N - 1) {
    ans *= M - 1;
    ans %= MOD;
  }
  ll ans_tmp = ans;
  rep1(i, K) {
    ans_tmp = (ans_tmp / (M - 1) * M) % MOD;
    ans += ans_tmp;
    ans %= MOD;
  }

  // string ans = ( flag ? "Yes" : "No" );
  // printf("%.8lf", ans);
  cout << ans;
  cout << "\\n";
  return 0;
}
Problem p02685 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <map>
#include <utility>
using namespace std;
#define int long long
#define DEBUG(x) cerr << #x << " = " << x << endl
int MOD = 998244353;
int power(int x, int y) {
  int res = 1;
  for (; y > 0; y >>= 1, (x *= x) %= MOD) {
    if (y & 1)
      (res *= x) %= MOD;
  }
  return res;
}
int extgcd(int a, int b, int &x, int &y) {
  int d = a;
  if (b != 0) {
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  } else {
    x = 1;
    y = 0;
  }
  return d;
}
int mod_inv(int a, int m) {
  int x, y;
  extgcd(a, m, x, y);
  return (m + x % m) % m;
}
int fact[200001];
void prepare(const int N) {
  fact[0] = 1;
  for (int i = 1; i <= N; i++) {
    fact[i] = fact[i - 1] * i;
    fact[i] %= MOD;
  }
}
int comb(const int n, const int k) {
  int r = fact[n];
  r *= mod_inv(fact[n - k], MOD);
  r %= MOD;
  r *= mod_inv(fact[k], MOD);
  r %= MOD;
  return r;
}
signed main() {
  int N, M, K;
  cin >> N >> M >> K;
  int ans = 0;
  prepare(N);
  for (int k = 0; k <= K; k++) {
    int r = M * comb(N - 1, k);
    r %= MOD;
    r *= power(M - 1, N - 1 - k);
    r %= MOD;
    ans += r;
    ans %= MOD;
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <map>
#include <utility>
using namespace std;
#define int long long
int MOD = 998244353;
int power(int x, int y) {
  int res = 1;
  for (; y > 0; y >>= 1, (x *= x) %= MOD) {
    if (y & 1)
      (res *= x) %= MOD;
  }
  return res;
}
map<pair<int, int>, int> memo;
int f(int M, int n, int k) {
  if (n == k) {
    return power(M, n);
  }
  if (k == 0) {
    return power(M - 1, n);
  }
  pair<int, int> p = make_pair(n, k);
  if (memo.count(p))
    return memo[p];
  int r = f(M, n - 1, k - 1) + (M - 1) * f(M, n - 1, k);
  r %= MOD;
  return memo[p] = r;
}
signed main() {
  int N, M, K;
  cin >> N >> M >> K;
  cout << (M * f(M, N - 1, K)) % MOD << endl;
}
Problem p02685 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define invrepr(i, a, b) for (int i = b - 1; i >= a; i--)
#define invrep(i, n) invrepr(i, 0, n)
#define repitr(itr, a) for (auto itr = a.begin(); itr != a.end(); ++itr)
const int MOD = 998244353;

const int MAX = 200010;

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

void cmbInit() {
  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 cmb(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() {
  ios_base::sync_with_stdio(false);

  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> p(n + 1);
  p[0] = 1;
  rep(i, n) p[i + 1] = (p[i] * (m - 1)) % MOD;
  ll ans = 0;
  cmbInit();
  rep(i, k + 1) {
    ll a = (m * p[n - (i + 1)]) % MOD, b = cmb(n - 1, i);
    ans += (a * b) % MOD;
    ans = ans % MOD;
  }
  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define invrepr(i, a, b) for (int i = b - 1; i >= a; i--)
#define invrep(i, n) invrepr(i, 0, n)
#define repitr(itr, a) for (auto itr = a.begin(); itr != a.end(); ++itr)
const int MOD = 998244353;

const int MAX = 200010;

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

void cmbInit() {
  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 cmb(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() {
  ios_base::sync_with_stdio(false);

  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> p(n);
  p[0] = 1;
  rep(i, n) p[i + 1] = (p[i] * (m - 1)) % MOD;
  ll ans = 0;
  cmbInit();
  rep(i, k + 1) {
    ll a = (m * p[n - (i + 1)]) % MOD, b = cmb(n - 1, i);
    ans += (a * b) % MOD;
    ans = ans % MOD;
  }
  cout << ans << endl;

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

#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
// #define DEBUG 10

using namespace std;
using ll = long long;
using pii = pair<ll, ll>;

const int oo = 1e9 + 7;
const ll mod = 998244353, maxn = 2 * 1e5 + 10, maxm = 15;
const double PI = acos(-1);
ll fat[maxn], inv[maxn];

ll mul(ll a, ll b) {
  ll ans = 0;
  while (b) {
    if (b & 1)
      ans = (ans + a) % mod;
    a = (a + a) % mod;
    b = (b >> 1);
  }
  return ans;
}

ll sum(ll a, ll b) { return (a % mod + b % mod) % mod; }

ll sub(ll a, ll b) { return (a - b + mod + mod) % mod; }

ll fexp(ll a, ll b) {
  ll ans = 1;

  while (b) {
    if (b & 1) {
      ans = mul(ans, a);
    }
    a = mul(a, a);
    b = (b >> 1);
  }
  return ans;
}

void init() {
  fat[0] = fat[1] = inv[0] = inv[1] = 1;
  for (ll i = 2; i < maxn; i++) {
    fat[i] = mul(fat[i - 1], i);
    inv[i] = fexp(fat[i], mod - 2);
  }
}

ll C(ll a, ll b) {
  if (a < b)
    return 0;
  if (a == b || b == 0)
    return 1;
  return mul(mul(fat[a], inv[b]), inv[a - b]);
}

int main() {
  ios_base::sync_with_stdio(false);
  ll n, k, m, ans = 0;
  init();
  cin >> n >> m >> k;
  for (ll i = 0; i <= k; i++) {
    ll x = n - i - 1;
    ans = sum(ans, mul(mul(m, C(n - 1, x)), fexp(m - 1, x)));
  }

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

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
// #define DEBUG 10

using namespace std;
using ll = long long;
using pii = pair<ll, ll>;

const int oo = 1e9 + 7;
const ll mod = 998244353, maxn = 155, maxm = 15;
const double PI = acos(-1);
ll fat[maxn], inv[maxn];

ll mul(ll a, ll b) {
  ll ans = 0;
  while (b) {
    if (b & 1)
      ans = (ans + a) % mod;
    a = (a + a) % mod;
    b = (b >> 1);
  }
  return ans;
}

ll sum(ll a, ll b) { return (a % mod + b % mod) % mod; }

ll sub(ll a, ll b) { return (a - b + mod + mod) % mod; }

ll fexp(ll a, ll b) {
  ll ans = 1;

  while (b) {
    if (b & 1) {
      ans = mul(ans, a);
    }
    a = mul(a, a);
    b = (b >> 1);
  }
  return ans;
}

void init() {
  fat[0] = fat[1] = inv[0] = inv[1] = 1;
  for (ll i = 2; i < maxn; i++) {
    fat[i] = mul(fat[i - 1], i);
    inv[i] = fexp(fat[i], mod - 2);
  }
}

ll C(ll a, ll b) {
  if (a < b)
    return 0;
  if (a == b || b == 0)
    return 1;
  return mul(mul(fat[a], inv[b]), inv[a - b]);
}

int main() {
  ios_base::sync_with_stdio(false);
  ll n, k, m, ans = 0;
  init();
  cin >> n >> m >> k;
  for (ll i = 0; i <= k; i++) {
    ll x = n - i - 1;
    ans = sum(ans, mul(mul(m, C(n - 1, x)), fexp(m - 1, x)));
  }

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

#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define inf LLONG_MAX >> 2
#define MAX 1000000
#define mod 998244353
#define pb push_back
#define f(i, a, n, x) for ((i) = (a); (i) < (n); (i) += (x))
#define fd(i, a, n, x) for ((i) = (a); (i) >= (n); (i) -= (x))
#define fi first
#define se second
#define mk make_pair
#define pi pair
#define vt vector
#define ms multiset
using namespace std;
void read(vt<ll> &a, ll n) {
  ll i, temp;
  f(i, 0, n, 1) {
    cin >> temp;
    a.pb(temp);
  }
}
ll fa[MAX];
ll power(ll p, ll q) {
  ll res = 1;
  p %= mod;
  while (q) {
    if (q & 1)
      res = (res * p) % mod;
    q >>= 1;
    p = (p * p) % mod;
  }
  return res;
}
ll fact(ll n) {
  if (n <= 1)
    return fa[n] = 1;
  if (fa[n])
    return fa[n];
  return fa[n] = (n * fact(n - 1)) % mod;
}
ll ncr(ll n, ll r) {
  if (!r)
    return 1;
  return (((fact(n) * power(fact(n - r), mod - 2)) % mod) *
          power(fact(r), mod - 2)) %
         mod;
}
ll func(ll n, ll m, ll i) {
  return (((m * ncr(n - 1, i)) % mod) * power(m - 1, n - 1 - i)) % mod;
}
void solve() {
  ll n, m, k, i, ans = 0;
  cin >> n >> m >> k;
  f(i, 0, k + 1, 1) ans = (ans + func(n, m, i)) % mod;
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t = 1;
  // cin>>t;
  while (t--)
    solve();
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define inf LLONG_MAX >> 2
#define MAX 1000000
#define mod 998244353
#define pb push_back
#define f(i, a, n, x) for ((i) = (a); (i) < (n); (i) += (x))
#define fd(i, a, n, x) for ((i) = (a); (i) >= (n); (i) -= (x))
#define fi first
#define se second
#define mk make_pair
#define pi pair
#define vt vector
#define ms multiset
using namespace std;
void read(vt<ll> &a, ll n) {
  ll i, temp;
  f(i, 0, n, 1) {
    cin >> temp;
    a.pb(temp);
  }
}
ll power(ll p, ll q) {
  ll res = 1;
  p %= mod;
  while (q) {
    if (q & 1)
      res = (res * p) % mod;
    q >>= 1;
    p = (p * p) % mod;
  }
  return res;
}
ll fact(ll n) {
  ll i, res = 1;
  f(i, 2, n + 1, 1) res = (res * i) % mod;
  return res;
}
ll ncr(ll n, ll r) {
  if (!r)
    return 1;
  return (((fact(n) * power(fact(n - r), mod - 2)) % mod) *
          power(fact(r), mod - 2)) %
         mod;
}
ll func(ll n, ll m, ll i) {
  return (((m * ncr(n - 1, i)) % mod) * power(m - 1, n - 1 - i)) % mod;
}
void solve() {
  ll n, m, k, i, ans = 0;
  cin >> n >> m >> k;
  f(i, 0, k + 1, 1) ans = (ans + func(n, m, i)) % mod;
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t = 1;
  // cin>>t;
  while (t--)
    solve();
  return 0;
}