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

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define reu(i, l, u) for (int(i) = (int)(l); (i) < (int)(u); ++(i))
#define each(it, o) for (auto it = (o).begin(); it != (o).end(); ++it)
#define mp(x, y) make_pair((x), (y))
#define mset(m, v) memset(m, v, sizeof(m))
#define inrep                                                                  \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define pb emplace_back
using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef long double ld;
const ll MOD = 1e9 + 7;
template <typename T> istream &operator>>(istream &in, vector<T> &v) {

  for (unsigned i = 0; i < v.size(); i++)
    in >> v[i];
  return in;
}

ll extended_GCD(ll a, ll b, ll &x, ll &y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  ll x1, y1;
  ll gcd = extended_GCD(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return gcd;
}
ll power(ll a, ll b, ll m = MOD) {
  a %= m;
  ll res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
ll modinv(ll a, ll mod) {
  ll x, y;
  extended_GCD(a, mod, x, y);
  if (x < 0)
    x += mod;
  return x;
}

ll mul(ll a, ll b, ll m) { return (a % m * b % m) % m; }

vector<ll> fact(2000005, 1);

ll ncr(ll n, ll r) {
  ll x = fact[n];
  ll y = fact[r];
  ll z = fact[n - r];
  y = z % MOD * y % MOD;
  y = modinv(y, MOD);
  x *= y;
  x %= MOD;
  return x;
}

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll k;
  string s;
  for (int i = 2; i <= 2000000; i++) {
    fact[i] = fact[i - 1] * i;
    fact[i] %= MOD;
  }
  // cout<<ncr(3,1);
  cin >> k >> s;
  ll n = s.length();
  ll p = n + k;
  ll z = power(26, p);
  ll y = 0;
  // cout<<ncr(4,0)<<"\\n";
  for (ll i = 0; i <= n - 1; i++) {
    ll mul = ncr(p, i) % MOD;
    // cout<<mul<<" ";
    ll h = power(25, p - i) % MOD;
    mul = (mul * h) % MOD;
    // cout<<mul<<" ";
    z = (z - mul + MOD) % MOD;
  }
  cout << z;

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define reu(i, l, u) for (int(i) = (int)(l); (i) < (int)(u); ++(i))
#define each(it, o) for (auto it = (o).begin(); it != (o).end(); ++it)
#define mp(x, y) make_pair((x), (y))
#define mset(m, v) memset(m, v, sizeof(m))
#define inrep                                                                  \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define pb emplace_back
using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef long double ld;
const ll MOD = 1e9 + 7;
template <typename T> istream &operator>>(istream &in, vector<T> &v) {

  for (unsigned i = 0; i < v.size(); i++)
    in >> v[i];
  return in;
}

ll extended_GCD(ll a, ll b, ll &x, ll &y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  ll x1, y1;
  ll gcd = extended_GCD(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return gcd;
}
ll power(ll a, ll b, ll m = MOD) {
  a %= m;
  ll res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
ll modinv(ll a, ll mod) {
  ll x, y;
  extended_GCD(a, mod, x, y);
  if (x < 0)
    x += mod;
  return x;
}

ll mul(ll a, ll b, ll m) { return (a % m * b % m) % m; }

vector<ll> fact(1000000, 1);

ll ncr(ll n, ll r) {
  ll x = fact[n];
  ll y = fact[r];
  ll z = fact[n - r];
  y = z % MOD * y % MOD;
  y = modinv(y, MOD);
  x *= y;
  x %= MOD;
  return x;
}

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll k;
  string s;
  for (int i = 2; i <= 1000000; i++) {
    fact[i] = fact[i - 1] * i;
    fact[i] %= MOD;
  }
  // cout<<ncr(3,1);
  cin >> k >> s;
  ll n = s.length();
  ll p = n + k;
  ll z = power(26, p);
  ll y = 0;
  // cout<<ncr(4,0)<<"\\n";
  for (ll i = 0; i <= n - 1; i++) {
    ll mul = ncr(p, i) % MOD;
    // cout<<mul<<" ";
    ll h = power(25, p - i) % MOD;
    mul = (mul * h) % MOD;
    // cout<<mul<<" ";
    z = (z - mul + MOD) % MOD;
  }
  cout << z;

  return 0;
}