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

// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
#define endl '\\n'
#define ld long double
#define all(a) a.begin(), a.end()
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define sz(v) (int)v.size()
#define UB upper_bound
#define LB lower_bound
#define BP(x) __builtin_popcountll(x)
#define OST                                                                    \\
  tree<pii, null_type, less<pii>, rb_tree_tag,                                 \\
       tree_order_statistics_node_update>
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int getRand(int l, int r) {
  uniform_int_distribution<int> uid(l, r);
  return uid(rng);
}

const int INF = 1e18 + 0;
const int mod = 1e9 + 7;
const int mex = 2e6 + 0;
int fact[mex + 5], inv[mex + 5];

int toPower(int a, int p) {
  int res = 1;
  while (p) {
    if (p & 1)
      res = ll(res) * a % mod;
    p >>= 1;
    a = ll(a) * a % mod;
  }
  return res;
}

int Inv(int x) { return toPower(x, mod - 2); }
int add(int a, int b) {
  a %= mod;
  b %= mod;
  return ((a + b) % mod);
}
int sub(int a, int b) {
  a %= mod;
  b %= mod;
  return ((a - b + mod) % mod);
}
int mul(int a, int b) {
  a %= mod;
  b %= mod;
  return ((a * b) % mod);
}

void initialize() {
  inv[0] = Inv(fact[0]);
  fact[0] = inv[0] = 1;

  for (int i = 1; i <= mex; i++) {
    fact[i] = (ll(i) * fact[i - 1]) % mod;
    inv[i] = Inv(fact[i]);
  }
}

int C(int n, int k) {
  if (n < 0 || k < 0 || k > n)
    return 0;
  return ll(fact[n]) * inv[k] % mod * inv[n - k] % mod;
}

void solve() {
  int n, k;
  cin >> k;
  int ans = 0;
  string s;
  cin >> s;
  n = k + sz(s);
  int t = sz(s);
  for (int i = t; i <= n; i++) {
    int cur = toPower(26, n - i);
    cur = mul(cur, toPower(25, i - t));
    cur = mul(cur, C(i - 1, t - 1));
    ans = add(ans, cur);
  }
  cout << ans << '\\n';
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  initialize();
  int t = 1; // cin >> t;
  for (int i = 1; i <= t; i++) {
    solve();
  }
}


Error: WA

Fixed submission:

// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
#define endl '\\n'
#define ld long double
#define all(a) a.begin(), a.end()
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define sz(v) (int)v.size()
#define UB upper_bound
#define LB lower_bound
#define BP(x) __builtin_popcountll(x)
#define OST                                                                    \\
  tree<pii, null_type, less<pii>, rb_tree_tag,                                 \\
       tree_order_statistics_node_update>
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int getRand(int l, int r) {
  uniform_int_distribution<int> uid(l, r);
  return uid(rng);
}

const int INF = 1e18 + 0;
const int mod = 1e9 + 7;
const int mex = 1e6 + 0;
int fact[mex + 5], inv[mex + 5];

int toPower(int a, int p) {
  int res = 1;
  while (p) {
    if (p & 1)
      res = ll(res) * a % mod;
    p >>= 1;
    a = ll(a) * a % mod;
  }
  return res;
}

int Inv(int x) { return toPower(x, mod - 2); }
int add(int a, int b) {
  a %= mod;
  b %= mod;
  return ((a + b) % mod);
}
int sub(int a, int b) {
  a %= mod;
  b %= mod;
  return ((a - b + mod) % mod);
}
int mul(int a, int b) {
  a %= mod;
  b %= mod;
  return ((a * b) % mod);
}

void initialize() {
  inv[0] = Inv(fact[0]);
  fact[0] = inv[0] = 1;

  for (int i = 1; i <= mex; i++) {
    fact[i] = (ll(i) * fact[i - 1]) % mod;
    inv[i] = Inv(fact[i]);
  }
}

int C(int n, int k) {
  if (n < 0 || k < 0 || k > n)
    return 0;
  return ll(fact[n]) * inv[k] % mod * inv[n - k] % mod;
}

void solve() {
  int n, k;
  cin >> k;
  int ans = 0;
  string s;
  cin >> s;
  n = k + sz(s);
  int t = sz(s);
  for (int i = t; i <= n; i++) {
    int cur = toPower(26, n - i);
    cur = mul(cur, toPower(25, i - t));
    cur = mul(cur, C(i - 1, t - 1));
    ans = add(ans, cur);
  }
  cout << ans << '\\n';
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  initialize();
  int t = 1; // cin >> t;
  for (int i = 1; i <= t; i++) {
    solve();
  }
}