Problem p02632 (C++)

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

//.define
// #define FILE_IN_OUT
#define RET(_x) return cout << (_x) << '\n', 0;
#define all(_obj) (_obj).begin(), (_obj).end()
#define loop(_n) for (int i = 0; i < (_n); ++i)
#define CeilDiv(_dividend, _divider)                                           \
  (((_dividend)-1LL + (_divider)) / (_divider))
#define sz(_obj) static_cast<int>((_obj).size())
#ifdef SHJ_LOCAL
#define debug(_x) std::cerr << (#_x) << " = " << (_x) << '\n' << std::flush;
#else
#define debug(_x)                                                              \
  {}
#endif
#define endl "\n"
template <typename Tp>
inline void outarr(Tp _begin, Tp _end, const char *_delim = " ") {
  for (Tp current = _begin; current != _end; ++current) {
    std::cout << *current << _delim;
  }
  std::cout << '\n';
}

//.constant
using ll = long long;
using pii = std::pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr int MOD = static_cast<const int>(1e9 + 7);

//.data
constexpr int MAXN = 1000005;

int fact[MAXN];
int ifact[MAXN];

int Add(int x, int y) {
  x += y;
  return x < MOD ? x : x - MOD;
}

int Sub(int x, int y) {
  x -= y;
  return x >= 0 ? x : x + MOD;
}

int Mul(int x, int y) { return int(1LL * x * y % MOD); }

int FastPow(int x, int p) {
  int res = 1;
  while (p > 0) {
    if (p & 1) {
      res = Mul(res, x);
    }
    p >>= 1;
    x = Mul(x, x);
  }
  return res;
}

int Inv(int x) { return FastPow(x, MOD - 2); }

int C(int k, int n) { return Mul(fact[n], Mul(ifact[k], ifact[n - k])); }

//.code
int main() {
#ifdef FILE_IN_OUT
  std::ifstream cin("input.txt", std::ios::in);
  std::ofstream cout("output.txt", std::ios::out);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
#endif

  fact[0] = fact[1] = 1;
  for (int i = 2; i < MAXN; ++i) {
    fact[i] = Mul(i, fact[i - 1]);
  }
  ifact[MAXN - 1] = Inv(fact[MAXN - 1]);
  for (int i = MAXN - 2; i >= 0; --i) {
    ifact[i] = Mul(ifact[i + 1], i + 1);
  }
  int k;
  string s;
  cin >> k >> s;
  int n = k + sz(s);
  int ans = 0;
  for (int i = sz(s); i <= n; ++i) {
    ans = Add(ans, Mul(Mul(C(sz(s) - 1, i - 1), FastPow(25, i - sz(s))),
                       FastPow(26, n - i)));
  }
  cout << ans << endl;

#ifdef FILE_IN_OUT
  cin.close();
  cout.close();
#endif
  return 0;
}

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

//.define
// #define FILE_IN_OUT
#define RET(_x) return cout << (_x) << '\n', 0;
#define all(_obj) (_obj).begin(), (_obj).end()
#define loop(_n) for (int i = 0; i < (_n); ++i)
#define CeilDiv(_dividend, _divider)                                           \
  (((_dividend)-1LL + (_divider)) / (_divider))
#define sz(_obj) static_cast<int>((_obj).size())
#ifdef SHJ_LOCAL
#define debug(_x) std::cerr << (#_x) << " = " << (_x) << '\n' << std::flush;
#else
#define debug(_x)                                                              \
  {}
#endif
#define endl "\n"
template <typename Tp>
inline void outarr(Tp _begin, Tp _end, const char *_delim = " ") {
  for (Tp current = _begin; current != _end; ++current) {
    std::cout << *current << _delim;
  }
  std::cout << '\n';
}

//.constant
using ll = long long;
using pii = std::pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr int MOD = static_cast<const int>(1e9 + 7);

//.data
constexpr int MAXN = 2000005;

int fact[MAXN];
int ifact[MAXN];

int Add(int x, int y) {
  x += y;
  return x < MOD ? x : x - MOD;
}

int Sub(int x, int y) {
  x -= y;
  return x >= 0 ? x : x + MOD;
}

int Mul(int x, int y) { return int(1LL * x * y % MOD); }

int FastPow(int x, int p) {
  int res = 1;
  while (p > 0) {
    if (p & 1) {
      res = Mul(res, x);
    }
    p >>= 1;
    x = Mul(x, x);
  }
  return res;
}

int Inv(int x) { return FastPow(x, MOD - 2); }

int C(int k, int n) { return Mul(fact[n], Mul(ifact[k], ifact[n - k])); }

//.code
int main() {
#ifdef FILE_IN_OUT
  std::ifstream cin("input.txt", std::ios::in);
  std::ofstream cout("output.txt", std::ios::out);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
#endif

  fact[0] = fact[1] = 1;
  for (int i = 2; i < MAXN; ++i) {
    fact[i] = Mul(i, fact[i - 1]);
  }
  ifact[MAXN - 1] = Inv(fact[MAXN - 1]);
  for (int i = MAXN - 2; i >= 0; --i) {
    ifact[i] = Mul(ifact[i + 1], i + 1);
  }
  int k;
  string s;
  cin >> k >> s;
  int n = k + sz(s);
  int ans = 0;
  for (int i = sz(s); i <= n; ++i) {
    ans = Add(ans, Mul(Mul(C(sz(s) - 1, i - 1), FastPow(25, i - sz(s))),
                       FastPow(26, n - i)));
  }
  cout << ans << endl;

#ifdef FILE_IN_OUT
  cin.close();
  cout.close();
#endif
  return 0;
}