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

/*                        _
                       _oo0oo_
                      o8888888o
                      88" . "88
                      (| -_- |)
                      0\\  =  /0
                   ____/`---'\\____
                  /  \\\\|     |//  \\
                 / \\\\||| /:\\ |||// \\
                / _||||| -:- |||||- \\
               |   | \\\\\\ \\-/ /// |   |
               | \\_|  ''\\---/''  |_/ |
               \\  .-\\__  '-'  ___/-. /
            ____'. .'  /--.--\\  `. .'_____
          /"" '<  `.___\\_<|>_/___.' >' "" \\
         | | :  `- \\`.;`\\ _ /`;.`/ - ` : | |
         \\  \\ `_.   \\_ __\\ /__ _/   .-` / _/
          `-.____`.___ \\_____/___.-`___.-'

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 JENISH MONPARA S.    IIT PATNA    I_LOVE_ADITI_GOEL
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define LIM 1000010

#define fio                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define mpq priority_queue<int, vector<int>, greater<int>>
#define deb(a) cerr << #a << ": " << a << endl
#define ftt                                                                    \\
  cin >> t;                                                                    \\
  for (int tt = 1; tt <= t; ++tt)
#define forr(i, n) for ((i) = 1; (i) <= (n); (i)++)
#define Rev(v) reverse(v.begin(), v.end())
#define Sort(v) sort(v.begin(), v.end())
#define mem(a, b) memset(a, b, sizeof(a))
#define umii unordered_map<int, int>
#define all(a) a.begin(), a.end()
#define vvi vector<vector<int>>
#define pq priority_queue<int>
#define sqr(a) (((a) * (a)))
#define double long double
#define dbg cout << "\\nhi\\n"
#define pii pair<int, int>
#define mii map<int, int>
#define vb vector<bool>
#define eb emplace_back
#define vi vector<int>
#define nl cout << "\\n"
#define pb push_back
#define int long long
#define sp << " " <<
#define se second
#define fi first

int fpow(int x, int n) {
  int res = 1;
  int mul = x;
  while (n) {
    if (n & 1)
      res = res * mul % mod;
    mul = mul * mul % mod;
    n /= 2;
  }
  return res;
}
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
void sieve(int n) {
  bool prime[5 * LIM];
  memset(prime, true, sizeof(prime));
  int rootn = (int)sqrt(n);
  for (int p = 2; p <= rootn; p++)
    if (prime[p] == true)
      for (int i = p * p; i <= n; i += p)
        prime[i] = false;
  prime[1] = 0;
}

int cnt, sum, mid, mx = -1e17, mn = 1e17, a[2 * LIM];
int n, m, d, t, i, j, k, l, r, x, y, z;
bool f, f1, f2;
string s;

//*************************************************************************************************************************
vi fact(2 * LIM), infact(2 * LIM);

void preprocess() {
  fact[0] = 1;
  infact[0] = 1;
  forr(i, 2e6 + 5) {
    fact[i] = (fact[i - 1] * i) % mod;
    infact[i] = fpow(fact[i], mod - 2) % mod;
  }
}

int c(int n, int r) {
  return (fact[n] * ((infact[n - r] * infact[r]) % mod)) % mod;
}

int32_t main() {
  fio;
  preprocess();
  cin >> k >> s;
  n = s.length();

  sum = 0;
  for (i = n; i <= n + k; i++) {
    cnt = fpow(26, n + k - i);
    cnt *= c(i - 1, n - 1);
    cnt %= mod;
    cnt *= fpow(25, i - n);
    cnt %= mod;

    sum += cnt;
    sum %= mod;
  }
  cout << sum;
}


Error: WA

Fixed submission:

/*                        _
                       _oo0oo_
                      o8888888o
                      88" . "88
                      (| -_- |)
                      0\\  =  /0
                   ____/`---'\\____
                  /  \\\\|     |//  \\
                 / \\\\||| /:\\ |||// \\
                / _||||| -:- |||||- \\
               |   | \\\\\\ \\-/ /// |   |
               | \\_|  ''\\---/''  |_/ |
               \\  .-\\__  '-'  ___/-. /
            ____'. .'  /--.--\\  `. .'_____
          /"" '<  `.___\\_<|>_/___.' >' "" \\
         | | :  `- \\`.;`\\ _ /`;.`/ - ` : | |
         \\  \\ `_.   \\_ __\\ /__ _/   .-` / _/
          `-.____`.___ \\_____/___.-`___.-'

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 JENISH MONPARA S.    IIT PATNA    I_LOVE_ADITI_GOEL
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define LIM 1000010

#define fio                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define mpq priority_queue<int, vector<int>, greater<int>>
#define deb(a) cerr << #a << ": " << a << endl
#define ftt                                                                    \\
  cin >> t;                                                                    \\
  for (int tt = 1; tt <= t; ++tt)
#define forr(i, n) for ((i) = 1; (i) <= (n); (i)++)
#define Rev(v) reverse(v.begin(), v.end())
#define Sort(v) sort(v.begin(), v.end())
#define mem(a, b) memset(a, b, sizeof(a))
#define umii unordered_map<int, int>
#define all(a) a.begin(), a.end()
#define vvi vector<vector<int>>
#define pq priority_queue<int>
#define sqr(a) (((a) * (a)))
#define double long double
#define dbg cout << "\\nhi\\n"
#define pii pair<int, int>
#define mii map<int, int>
#define vb vector<bool>
#define eb emplace_back
#define vi vector<int>
#define nl cout << "\\n"
#define pb push_back
#define int long long
#define sp << " " <<
#define se second
#define fi first

int fpow(int x, int n) {
  int res = 1;
  int mul = x;
  while (n) {
    if (n & 1)
      res = res * mul % mod;
    mul = mul * mul % mod;
    n /= 2;
  }
  return res;
}
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
void sieve(int n) {
  bool prime[5 * LIM];
  memset(prime, true, sizeof(prime));
  int rootn = (int)sqrt(n);
  for (int p = 2; p <= rootn; p++)
    if (prime[p] == true)
      for (int i = p * p; i <= n; i += p)
        prime[i] = false;
  prime[1] = 0;
}

int cnt, sum, mid, mx = -1e17, mn = 1e17, a[2 * LIM];
int n, m, d, t, i, j, k, l, r, x, y, z;
bool f, f1, f2;
string s;

//*************************************************************************************************************************
vi fact(LIM), infact(LIM);

void preprocess() {
  fact[0] = 1;
  infact[0] = 1;
  forr(i, 1e6 + 5) {
    fact[i] = (fact[i - 1] * i) % mod;
    infact[i] = fpow(fact[i], mod - 2) % mod;
  }
}

int c(int n, int r) {
  return (fact[n] * ((infact[n - r] * infact[r]) % mod)) % mod;
}

int32_t main() {
  fio;
  preprocess();
  cin >> k >> s;
  n = s.length();

  sum = 0;
  for (i = n; i <= n + k; i++) {
    cnt = fpow(26, n + k - i);
    cnt *= c(i - 1, n - 1);
    cnt %= mod;
    cnt *= fpow(25, i - n);
    cnt %= mod;

    sum += cnt;
    sum %= mod;
  }
  cout << sum;
}