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

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

class mint {
  uint32_t value;
  static vector<uint32_t> _fact;
  static void fill(const long n) {
    mint val = _fact.back();
    for (long i = _fact.size(); i <= n; ++i) {
      _fact.push_back(val *= i);
    }
  }

public:
  static const uint32_t MOD = 1e9 + 7;
  mint(const int64_t x) : value(x % MOD + (x < 0 ? MOD : 0)) {}
  operator int() const { return value; }
  mint operator+(const mint y) const { return mint(value + y.value); }
  mint &operator+=(const mint a) { return *this = *this + a; }
  mint operator*(const mint y) const { return mint(int64_t(value) * y.value); }
  mint &operator*=(const mint a) { return *this = *this * a; }
  mint operator-() const { return *this * mint(-1); }
  mint operator-(const mint y) const { return *this + (-y); }
  mint &operator-=(const mint a) { return *this = *this - a; }
  static mint fact(const long n) {
    fill(n);
    return _fact[n];
  }
  static mint pow(mint a, long n) {
    mint ans = 1;
    while (n > 0) {
      if (n & 1)
        ans *= a;
      a *= a;
      n >>= 1;
    }
    return ans;
  }
  mint inv() const { return pow(value, MOD - 2); }
  mint operator/(const mint y) const { return *this * y.inv(); }
  static mint comb(const long n, const long k) {
    return fact(n) / fact(k) / fact(n - k);
  }
};
vector<uint32_t> mint::_fact = {1};

int main() {
  int N, K;
  string S;
  cin >> K >> S;
  N = S.size();

  mint ans = 0;
  for (int i = N - 1; i < N + K; i++) {
    ans += mint::pow(25, i - (N - 1)) * mint::pow(26, N + K - 1 - i) *
           mint::comb(i, N - 1);
  }
  cout << ans << endl;
}


Error: WA

Fixed submission:

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

class mint {
  int32_t value;
  static vector<int32_t> _fact;
  static void fill(long n) {
    for (long i = _fact.size(); i <= n; i++) {
      _fact[i] = _fact[i - 1] * i;
    }
  }

public:
  static const int32_t MOD = 1e9 + 7;
  mint(int64_t x) : value(x % MOD + (x < 0 ? MOD : 0)) {}
  mint operator+(mint y) const { return mint(value + y.value); }
  mint &operator+=(mint a) { return *this = *this + a; }
  mint operator*(mint y) const { return mint(long(value) * y.value); }
  mint &operator*=(mint a) { return *this = *this * a; }
  mint operator-() const { return *this * mint(-1); }
  mint operator-(mint y) const { return *this + (-y); }
  mint &operator-=(mint a) { return *this = *this - a; }
  operator int() const { return value; }
  static mint pow(mint a, long n) {
    mint ans = 1;
    while (n > 0) {
      if (n & 1)
        ans *= a;
      a *= a;
      n >>= 1;
    }
    return ans;
  }
  mint inv() { return pow(value, MOD - 2); }
  static mint fact(long n) {
    fill(n);
    return _fact[n];
  }
  static mint comb(long n, long k) {
    return fact(n) * fact(k).inv() * fact(n - k).inv();
  }
};
vector<int32_t> mint::_fact = {1};

int main() {
  int K;
  cin >> K;

  string S;
  cin >> S;

  int W = S.size();
  int L = W + K;

  mint ans = 0;
  for (int i = W - 1; i < L; i++) {
    ans += mint::pow(25, i - (W - 1)) * mint::pow(26, L - 1 - i) *
           mint::comb(i, W - 1);
  }
  cout << (1 + ans) << endl;
}