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

// Mandelbrot: z(n+1) = (z(n))^2 + c
// Rick: I programmed you to believe that
// #include <boost/multiprecision/cpp_int.hpp>
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
typedef long long int ll;
typedef double db;
// __int128 s128;
// __uint128_t u128;
typedef unsigned long long u64;
#define int long long int
#define PI 3.14159265359
#define sz(a) (ll) a.size()
#define lt(a) (ll) a.length()
#define pll pair<ll, ll>
#define tc(x)                                                                  \\
  ll x;                                                                        \\
  cin >> x;                                                                    \\
  while (x--)
#define f(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define bac(i, a, b) for (ll i = (ll)a; i >= (ll)b; i--)
#define print(a)                                                               \\
  for (auto x : a)                                                             \\
    cout << x << " ";                                                          \\
  cout << endl
#define mll map<ll, ll>
#define umll unordered_map<ll, ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define mt make_tuple
#define eb emplace_back
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define setbits(a) __builtin_popcountll(a)
#define ps(x, y) fixed << setprecision(y) << x;
#define F first
#define S second
#define teevra_gati                                                            \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define P 1000000007
#define Q 1000000006
#define inf 1e18
#define N 3000005
// using namespace boost::multiprecision;
using namespace __gnu_pbds;
using namespace std;
mt19937 rng(chrono::steady_clock::now()
                .time_since_epoch()
                .count()); // shuffle(all(v), rng);
ll fact[N];
ll powMod(ll a, ll b, ll m) {
  a %= m;
  ll res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}

ll modInverse(ll n, ll p) { return powMod(n, p - 2, p); }

ll nCrModPFermat(ll n, ll r, ll p) {

  if (r == 0)
    return 1;
  ll r1 = fact[n];
  ll r2 = fact[r];
  ll r3 = fact[n - r];
  return (r1 * modInverse(r2, p) % p * modInverse(r3, p) % p) % p;
}

void solve() {

  ll k, l, ans = 0;
  string s;
  cin >> k >> s;
  l = lt(s);
  f(i, 0, k + 1) {
    ll a = nCrModPFermat(l + k - i - 1, l - 1, P);
    ll b = (powMod(26, i, P) * powMod(25, k - i, P)) % P;
    (ans += (a * b) % P) %= P;
  }
  cout << ans;
}

signed main() {
  teevra_gati

      fact[0] = 1;
  f(i, 1, N) fact[i] = (i * fact[i - 1]) % P;
  solve();
  return 0;
}

Error: WA

Fixed submission:

// Mandelbrot: z(n+1) = (z(n))^2 + c
// Rick: I programmed you to believe that
// #include <boost/multiprecision/cpp_int.hpp>
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
typedef long long int ll;
typedef double db;
// __int128 s128;
// __uint128_t u128;
typedef unsigned long long u64;
#define int long long int
#define PI 3.14159265359
#define sz(a) (ll) a.size()
#define lt(a) (ll) a.length()
#define pll pair<ll, ll>
#define tc(x)                                                                  \\
  ll x;                                                                        \\
  cin >> x;                                                                    \\
  while (x--)
#define f(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define bac(i, a, b) for (ll i = (ll)a; i >= (ll)b; i--)
#define print(a)                                                               \\
  for (auto x : a)                                                             \\
    cout << x << " ";                                                          \\
  cout << endl
#define mll map<ll, ll>
#define umll unordered_map<ll, ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define mt make_tuple
#define eb emplace_back
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define setbits(a) __builtin_popcountll(a)
#define ps(x, y) fixed << setprecision(y) << x;
#define F first
#define S second
#define teevra_gati                                                            \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define P 1000000007
#define Q 1000000006
#define inf 1e18
#define N 1000005
// using namespace boost::multiprecision;
using namespace __gnu_pbds;
using namespace std;
mt19937 rng(chrono::steady_clock::now()
                .time_since_epoch()
                .count()); // shuffle(all(v), rng);
ll fact[N];
ll powMod(ll a, ll b, ll m) {
  a %= m;
  ll res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}

ll modInverse(ll n, ll p) { return powMod(n, p - 2, p); }

ll nCrModPFermat(ll n, ll r, ll p) {

  if (r == 0)
    return 1;
  ll r1 = fact[n];
  ll r2 = fact[r];
  ll r3 = fact[n - r];
  return (r1 * modInverse(r2, p) % p * modInverse(r3, p) % p) % p;
}

void solve() {

  ll k, l, ans = 0;
  string s;
  cin >> k >> s;
  l = lt(s);
  f(i, 0, k + 1) {
    ll a = nCrModPFermat(l + k - i - 1, l - 1, P);
    ll b = (powMod(26, i, P) * powMod(25, k - i, P)) % P;
    (ans += (a * b) % P) %= P;
  }
  cout << ans;
}

signed main() {
  teevra_gati

      fact[0] = 1;
  f(i, 1, N) fact[i] = (i * fact[i - 1]) % P;
  solve();
  return 0;
}