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

#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

template <int64_t MOD> struct Mint {
  int64_t v;
  Mint() { v = 0; }
  Mint(int64_t x) {
    v = x % MOD;
    if (v < 0)
      v += MOD;
  }

  Mint operator-() { return Mint{-v}; };
  Mint operator+(Mint x) { return Mint(v + x.v); };
  Mint operator-(Mint x) { return Mint(v - x.v); };
  Mint operator*(Mint x) { return Mint(v * x.v); };
  Mint operator/(Mint x) { return Mint(v * pow(x.v, MOD - 2).v); };

  Mint &operator+=(Mint x) { return *this = (*this + x); };
  Mint &operator-=(Mint x) { return *this = (*this - x); };
  Mint &operator*=(Mint x) { return *this = (*this * x); };
  Mint &operator/=(Mint x) { return *this = (*this / x); };

  static Mint pow(Mint base, int64_t exp) {
    if (exp == 0)
      return Mint(1);
    return pow(base * base, exp / 2) * (exp & 1 ? base : Mint(1));
  }

  friend ostream &operator<<(ostream &os, Mint x) { return os << x.v; }
};
using mint = Mint<1000000007>;

template <class T> struct Counting {
  Counting(int64_t n) {
    _fact.assign(n + 1, 1);
    for (int64_t i = 1; i <= n; i++)
      _fact[i] = T(i) * _fact[i - 1];
  }

  T fact(int64_t n) {
    assert(0 <= n && n < (int)_fact.size());
    return _fact[n];
  }

  T perm(int64_t n, int64_t k) {
    if (n < k)
      return 0;
    return fact(n) / fact(n - k);
  }

  T comb(int64_t n, int64_t k) {
    if (n < k)
      return 0;
    return fact(n) / (fact(k) * fact(n - k));
  }

private:
  vector<T> _fact;
};

int main() {
  Counting<mint> cnt(2123456);
  lint K;
  cin >> K;

  string S;
  cin >> S;
  lint N = S.size();

  mint sum = 0;
  for (lint i = N; i <= N + K; i++) {
    sum += cnt.comb(i - 1, N - 1) * mint::pow(25, i - N) *
           mint::pow(26, N + K - i);
  }

  cout << sum << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

template <int64_t MOD> struct Mint {
  int64_t v;
  Mint() { v = 0; }
  Mint(int64_t x) {
    v = x % MOD;
    if (v < 0)
      v += MOD;
  }

  Mint operator-() { return Mint{-v}; };
  Mint operator+(Mint x) { return Mint(v + x.v); };
  Mint operator-(Mint x) { return Mint(v - x.v); };
  Mint operator*(Mint x) { return Mint(v * x.v); };
  Mint operator/(Mint x) { return Mint(v * pow(x.v, MOD - 2).v); };

  Mint &operator+=(Mint x) { return *this = (*this + x); };
  Mint &operator-=(Mint x) { return *this = (*this - x); };
  Mint &operator*=(Mint x) { return *this = (*this * x); };
  Mint &operator/=(Mint x) { return *this = (*this / x); };

  static Mint pow(Mint base, int64_t exp) {
    if (exp == 0)
      return Mint(1);
    return pow(base * base, exp / 2) * (exp & 1 ? base : Mint(1));
  }

  friend ostream &operator<<(ostream &os, Mint x) { return os << x.v; }
};
using mint = Mint<1000000007>;

template <class T> struct Counting {
  Counting(int64_t n) {
    _fact.assign(n + 1, 1);
    for (int64_t i = 1; i <= n; i++)
      _fact[i] = T(i) * _fact[i - 1];
  }

  T fact(int64_t n) {
    assert(0 <= n && n < (int)_fact.size());
    return _fact[n];
  }

  T perm(int64_t n, int64_t k) {
    if (n < k)
      return 0;
    return fact(n) / fact(n - k);
  }

  T comb(int64_t n, int64_t k) {
    if (n < k)
      return 0;
    return fact(n) / (fact(k) * fact(n - k));
  }

private:
  vector<T> _fact;
};

int main() {
  Counting<mint> cnt(1123456);
  lint K;
  cin >> K;

  string S;
  cin >> S;
  lint N = S.size();

  mint sum = 0;
  for (lint i = N; i <= N + K; i++) {
    sum += cnt.comb(i - 1, N - 1) * mint::pow(25, i - N) *
           mint::pow(26, N + K - i);
  }

  cout << sum << endl;
}