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

#include <bits/stdc++.h>
using namespace std;
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define int long long int
#define ld long double
#define endl "\\n"
#define rep(i, a, b) for (int i = a; i < b; i++)
#define reprev(i, a, b) for (int i = b - 1; i >= a; i--)
#define all(c) c.begin(), c.end()
#define sz(c) (int)c.size()
#define ff first
#define ss second
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define vin(a, n)                                                              \\
  vi a(n);                                                                     \\
  rep(i, 0, n) cin >> a[i];
#define vout(a)                                                                \\
  rep(i, 0, sz(a)) cout << a[i] << " ";                                        \\
  cout << endl;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define mod2 998244353
#define inf LLONG_MAX
#define pi 3.1415926535897932384626
#define tr(container, it)                                                      \\
  for (auto it = container.begin(); it != container.end(); it++)

int power(int x, unsigned int y, int p) {
  int res = 1; // Initialize result

  x = x % p; // Update x if it is more than or
             // equal to p

  if (x == 0)
    return 0; // In case x is divisible by p;

  while (y > 0) {
    // If y is odd, multiply x with result
    if (y & 1)
      res = (res * x) % p;

    // y must be even now
    y = y >> 1; // y = y/2
    x = (x * x) % p;
  }
  return res;
}

int modInverse(int n, int p) { return power(n, p - 2, p); }
const int N = 2000000;
int fac[N + 1];
void precomp(int p) {
  fac[0] = 1;
  for (int i = 1; i <= N; i++)
    fac[i] = fac[i - 1] * i % p;
}
// Returns nCr % p using Fermat's little
// theorem.
int nCrModPFermat(int n, int r, int p) {
  // Base case
  if (r == 0)
    return 1;

  // Fill factorial array so that we
  // can find all factorial of r, n
  // and n-r
  return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %
         p;
}
signed main() {
  IOS precomp(mod);
  int k;
  cin >> k;
  string s;
  cin >> s;
  int n = s.length();
  int final_ans = 0;
  rep(i, n, n + k + 1) {
    int ans = 1;
    int x1 = nCrModPFermat(i - 1, n - 1, mod);
    ans *= x1;
    ans %= mod;
    ans *= power(25, i - n, mod);
    ans %= mod;
    ans *= power(26, n + k - i, mod);
    ans %= mod;
    final_ans += ans;
    final_ans %= mod;
  }
  cout << final_ans;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define int long long int
#define ld long double
#define endl "\\n"
#define rep(i, a, b) for (int i = a; i < b; i++)
#define reprev(i, a, b) for (int i = b - 1; i >= a; i--)
#define all(c) c.begin(), c.end()
#define sz(c) (int)c.size()
#define ff first
#define ss second
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define vin(a, n)                                                              \\
  vi a(n);                                                                     \\
  rep(i, 0, n) cin >> a[i];
#define vout(a)                                                                \\
  rep(i, 0, sz(a)) cout << a[i] << " ";                                        \\
  cout << endl;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define mod2 998244353
#define inf LLONG_MAX
#define pi 3.1415926535897932384626
#define tr(container, it)                                                      \\
  for (auto it = container.begin(); it != container.end(); it++)

int power(int x, unsigned int y, int p) {
  int res = 1; // Initialize result

  x = x % p; // Update x if it is more than or
             // equal to p

  if (x == 0)
    return 0; // In case x is divisible by p;

  while (y > 0) {
    // If y is odd, multiply x with result
    if (y & 1)
      res = (res * x) % p;

    // y must be even now
    y = y >> 1; // y = y/2
    x = (x * x) % p;
  }
  return res;
}

int modInverse(int n, int p) { return power(n, p - 2, p); }
const int N = 1000000;
int fac[N + 1];
void precomp(int p) {
  fac[0] = 1;
  for (int i = 1; i <= N; i++)
    fac[i] = fac[i - 1] * i % p;
}
// Returns nCr % p using Fermat's little
// theorem.
int nCrModPFermat(int n, int r, int p) {
  // Base case
  if (r == 0)
    return 1;

  // Fill factorial array so that we
  // can find all factorial of r, n
  // and n-r
  return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %
         p;
}
signed main() {
  IOS precomp(mod);
  int k;
  cin >> k;
  string s;
  cin >> s;
  int n = s.length();
  int final_ans = 0;
  rep(i, n, n + k + 1) {
    int ans = 1;
    int x1 = nCrModPFermat(i - 1, n - 1, mod);
    ans *= x1;
    ans %= mod;
    ans *= power(25, i - n, mod);
    ans %= mod;
    ans *= power(26, n + k - i, mod);
    ans %= mod;
    final_ans += ans;
    final_ans %= mod;
  }
  cout << final_ans;
  return 0;
}