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

#include "bits/stdc++.h"
using namespace std;
#define PIGRECO 3.141592653589793
#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                 \\
  sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(    \\
            c i) {
sim > struct rge {
  c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
  ~debug() { cerr << endl; }
  eni(!=) cerr << boolalpha << i;
  ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
  sim dor(const c &) { ris; }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
#define int long long
const int mod = 998244353;
const int maxn = 2e5 + 5;
int fact[maxn], fin[maxn];

long long binpow(long long a, long long b) {

  long long res = 1;

  a = a % mod;

  while (b > 0) {

    if (b & 1)
      res = (res * a) % mod;

    a = (a * a) % mod;

    b >>= 1;
  }

  return res;
}

long long inverse(long long a) { return binpow(a, mod - 2); }

long long nCr(long long n, long long r) {

  if (r < 0 || r > n)
    return 0;

  return ((fact[n] * fin[r]) % mod * fin[n - r]) % mod;
}

int32_t main() {

  int n, m, k;
  cin >> n >> m >> k;
  fact[0] = 1;

  for (int i = 1; i < maxn; i++)
    fact[i] = fact[i - 1] * i % mod;

  fin[maxn - 1] = inverse(fact[maxn - 1]);

  for (int i = maxn - 2; i >= 0; i--) {
    fin[i] = fin[i + 1] * (i + 1) % mod;
  }

  long long ans = 0;

  for (int i = 0; i <= k; i++) {

    ans =
        (ans + (((nCr(n - 1, i) * m) % mod) * binpow(m - 1, n - 1 - i)) % mod) %
        mod;
  }

  cout << ans << endl;
}

Error: WA

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
#define PIGRECO 3.141592653589793
#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                 \\
  sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(    \\
            c i) {
sim > struct rge {
  c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
  ~debug() { cerr << endl; }
  eni(!=) cerr << boolalpha << i;
  ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
  sim dor(const c &) { ris; }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
#define int long long
const int mod = 998244353;
const int maxn = 1e5 + 5;
int fact[maxn], fin[maxn];

long long binpow(long long a, long long b) {

  long long res = 1;

  a = a % mod;

  while (b > 0) {

    if (b & 1)
      res = (res * a) % mod;

    a = (a * a) % mod;

    b >>= 1;
  }

  return res;
}

long long inverse(long long a) { return binpow(a, mod - 2); }

long long nCr(long long n, long long r) {

  if (r == 0)
    return 1;

  return ((fact[n] * fin[r]) % mod * fin[n - r] % mod) % mod;
}

int32_t main() {

  int n, m, k;
  cin >> n >> m >> k;
  fact[0] = 1;

  for (int i = 1; i < maxn; i++)
    fact[i] = fact[i - 1] * i % mod;

  fin[maxn - 1] = inverse(fact[maxn - 1]);

  long long ans = 0;

  for (int i = 0; i <= k; i++) {

    ans =
        (ans + (((nCr(n - 1, i) * m) % mod) * binpow(m - 1, n - 1 - i)) % mod) %
        mod;
  }

  cout << ans << endl;
}