Problem p02685 (C++)

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

const int64_t MOD = 998244353;
struct mint {
  int64_t x;
  mint(int64_t x = 0) : x((x % MOD + MOD) % MOD) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a) {
    if ((x += a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x += MOD - a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(int64_t n) const {
    if (n == 0)
      return 1;
    mint t = pow(n >> 1);
    t *= t;
    if (n & 1)
      t *= *this;
    return t;
  }
  mint inv() const { return pow(MOD - 2); }
  mint &operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};

vector<mint> fac;
vector<mint> fac_inv;
vector<mint> inv;
void init_comb(int mx) {
  fac = vector<mint>(mx + 1), fac_inv = vector<mint>(mx + 1),
  inv = vector<mint>(mx + 1);
  fac.at(0) = fac.at(1) = 1;
  fac_inv.at(0) = fac_inv.at(1) = 1;
  inv.at(1) = 1;
  for (int i = 2; i <= mx; i++) {
    fac.at(i) = fac.at(i - 1) * i;
    inv.at(i) = -inv.at(MOD % i) * (MOD / i);
    fac_inv.at(i) = fac_inv.at(i - 1) * inv.at(i);
  }
}
mint comb(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac.at(n) * fac_inv.at(k) * fac_inv.at(n - k);
}

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

  init_comb(N - 1);
  mint res = 0;
  for (int i = 0; i < K + 1; i++) {
    res += mint(M) * comb(N - 1, i) * mint(M - 1).pow(N - 1 - i);
  }
  cout << res.x << endl;
}

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

const int64_t MOD = 998244353;
struct mint {
  int64_t x;
  mint(int64_t x = 0) : x((x % MOD + MOD) % MOD) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a) {
    if ((x += a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x += MOD - a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(int64_t n) const {
    if (n == 0)
      return 1;
    mint t = pow(n >> 1);
    t *= t;
    if (n & 1)
      t *= *this;
    return t;
  }
  mint inv() const { return pow(MOD - 2); }
  mint &operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};

vector<mint> fac;
vector<mint> fac_inv;
vector<mint> inv;
void init_comb(int mx) {
  fac = vector<mint>(mx + 1), fac_inv = vector<mint>(mx + 1),
  inv = vector<mint>(mx + 1);
  fac.at(0) = fac.at(1) = 1;
  fac_inv.at(0) = fac_inv.at(1) = 1;
  inv.at(1) = 1;
  for (int i = 2; i <= mx; i++) {
    fac.at(i) = fac.at(i - 1) * i;
    inv.at(i) = -inv.at(MOD % i) * (MOD / i);
    fac_inv.at(i) = fac_inv.at(i - 1) * inv.at(i);
  }
}
mint comb(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac.at(n) * fac_inv.at(k) * fac_inv.at(n - k);
}

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

  init_comb(2 * 1e5);
  mint res = 0;
  for (int i = 0; i < K + 1; i++) {
    res += mint(M) * comb(N - 1, i) * mint(M - 1).pow(N - 1 - i);
  }
  cout << res.x << endl;
}