Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
// #define ll int128_t
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define IOS                                                                    \
  std::ios::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define pb push_back
#define eb emplace_back
#define pii pair<int, int>
#define endl '\n'
#define all(x) x.begin(), x.end()
#define smax(a, b) a = max(a, b)
// #if !defined(ONLINE_JUDGE)
// #include "debugging.h"
// #endif
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
// erase,insert same as normal set

int const mod = 1e9 + 7;
// int const mod = 998244353;
int power(int a, int b, int m) {
  int res = 1;
  while (b) {
    if (b & 1) {
      res = (res * a) % m;
      res %= m;
    }
    a = (a * a) % m;
    a %= m;
    b = b / 2;
  }
  return res;
}

int inverse(int x, int m) { return power(x, m - 2, m); }

int const N = 1e6 + 55;
int const inf = 1e18;
ld pi = 3.14159265359;

int fact[N];
int ifact[N];

void precompute_factorials() {
  fact[0] = 1;
  for (int i = 1; i < N; i++) {
    fact[i] = i * fact[i - 1];
    fact[i] %= mod;
  }
  ifact[N - 1] = inverse(fact[N - 1], mod);
  for (int i = N - 2; i >= 0; i--) {
    ifact[i] = (i + 1) * ifact[i + 1];
    ifact[i] %= mod;
  }
}

int ncr(int n, int r) {
  if (n < r || r < 0)
    return 0;
  if (n == r)
    return 1;

  int res = fact[n];
  res *= ifact[r];
  res %= mod;
  res *= ifact[n - r];
  res %= mod;
  return res;
}

void solve() {
  int i, j, l;
  int k;
  cin >> k;
  string s;
  cin >> s;
  int n = s.size();

  int ans = 0;

  for (i = n; i <= n + k; i++) {
    int rem = n + k - i;
    int tmp = power(26LL, rem, mod);
    tmp = tmp * power(25LL, i - n, mod);
    tmp %= mod;
    tmp = tmp * ncr(i - 1, n - 1);
    tmp %= mod;
    ans += tmp;
    ans %= mod;
  }

  cout << ans << endl;
}

int32_t main() {
  IOS;
  int t;
  t = 1;
  precompute_factorials();
  // precompute();
  // cin>>t;
  for (int tt = 1; tt <= t; tt++) {
    // cout << "Case #"<<tt<<": ";
    solve();
  }
  return 0;
}

/*


*/

Fixed submission:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
// #define ll int128_t
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define IOS                                                                    \
  std::ios::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define pb push_back
#define eb emplace_back
#define pii pair<int, int>
#define endl '\n'
#define all(x) x.begin(), x.end()
#define smax(a, b) a = max(a, b)
// #if !defined(ONLINE_JUDGE)
// #include "debugging.h"
// #endif
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
// erase,insert same as normal set

int const mod = 1e9 + 7;
// int const mod = 998244353;
int power(int a, int b, int m) {
  int res = 1;
  while (b) {
    if (b & 1) {
      res = (res * a) % m;
      res %= m;
    }
    a = (a * a) % m;
    a %= m;
    b = b / 2;
  }
  return res;
}

int inverse(int x, int m) { return power(x, m - 2, m); }

int const N = 2e6 + 55;
int const inf = 1e18;
ld pi = 3.14159265359;

int fact[N];
int ifact[N];

void precompute_factorials() {
  fact[0] = 1;
  for (int i = 1; i < N; i++) {
    fact[i] = i * fact[i - 1];
    fact[i] %= mod;
  }
  ifact[N - 1] = inverse(fact[N - 1], mod);
  for (int i = N - 2; i >= 0; i--) {
    ifact[i] = (i + 1) * ifact[i + 1];
    ifact[i] %= mod;
  }
}

int ncr(int n, int r) {
  if (n < r || r < 0)
    return 0;
  if (n == r)
    return 1;

  int res = fact[n];
  res *= ifact[r];
  res %= mod;
  res *= ifact[n - r];
  res %= mod;
  return res;
}

void solve() {
  int i, j, l;
  int k;
  cin >> k;
  string s;
  cin >> s;
  int n = s.size();

  int ans = 0;

  for (i = n; i <= n + k; i++) {
    int rem = n + k - i;
    int tmp = power(26LL, rem, mod);
    tmp = tmp * power(25LL, i - n, mod);
    tmp %= mod;
    tmp = tmp * ncr(i - 1, n - 1);
    tmp %= mod;
    ans += tmp;
    ans %= mod;
  }

  cout << ans << endl;
}

int32_t main() {
  IOS;
  int t;
  t = 1;
  precompute_factorials();
  // precompute();
  // cin>>t;
  for (int tt = 1; tt <= t; tt++) {
    // cout << "Case #"<<tt<<": ";
    solve();
  }
  return 0;
}

/*


*/