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

#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)x.size()
#define cl(x) x.clear()
#define all(x) x.begin(), x.end()
#define rep(i, x, n) for (int i = x; i <= n; i++)
#define per(i, n, x) for (int i = n; i >= x; i--)
#define mem0(x) memset(x, 0, sizeof(x))
#define mem_1(x) memset(x, -1, sizeof(x))
#define mem_inf(x) memset(x, 0x3f, sizeof(x))
#define debug(x) cout << '*' << x << '\\n'
#define ddebug(x, y) cout << '*' << x << ' ' << y << '\\n'
#define ios std::ios::sync_with_stdio(false), cin.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod = 1e9 + 7;
const int maxn = 2e6 + 10;
const int inf = 0x3f3f3f3f;
const double eps = 1e-6;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
int k;
ll ans = 0;
string s;
ll fac[maxn];
ll inv[maxn];
void init() {
  fac[0] = fac[1] = inv[0] = inv[1] = 1;
  for (int i = 2; i <= 2e6; i++) {
    fac[i] = fac[i - 1] * i % mod;
    inv[i] = -inv[mod % i] * (mod / i) % mod;
    while (inv[i] < 0)
      inv[i] += mod;
  }
  for (int i = 2; i <= 2e6; i++)
    inv[i] = inv[i] * inv[i - 1] % mod;
}
ll C(int n, int m) { return fac[n] * inv[m] % mod * inv[n - m] % mod; }
ll qpow(ll a, ll b) {
  if (b < 0)
    return 0;
  ll ans = 1;
  a %= mod;
  while (b) {
    if (b & 1)
      ans = (ans * a) % mod;
    b >>= 1, a = (a * a) % mod;
  }
  return ans % mod;
}
int main() {
  ios;
  cin >> k >> s;
  init();
  int n = sz(s);
  rep(i, n, n + k) ans +=
      C(i - 1, n - 1) * qpow(25, i - n) % mod * qpow(26, n + k - i) % mod,
      ans %= mod;
  cout << ans << '\\n';
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)x.size()
#define cl(x) x.clear()
#define all(x) x.begin(), x.end()
#define rep(i, x, n) for (int i = x; i <= n; i++)
#define per(i, n, x) for (int i = n; i >= x; i--)
#define mem0(x) memset(x, 0, sizeof(x))
#define mem_1(x) memset(x, -1, sizeof(x))
#define mem_inf(x) memset(x, 0x3f, sizeof(x))
#define debug(x) cout << '*' << x << '\\n'
#define ddebug(x, y) cout << '*' << x << ' ' << y << '\\n'
#define ios std::ios::sync_with_stdio(false), cin.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 10;
const int inf = 0x3f3f3f3f;
const double eps = 1e-6;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
int k;
ll ans = 0;
string s;
ll fac[maxn];
ll inv[maxn];
void init() {
  fac[0] = fac[1] = inv[0] = inv[1] = 1;
  for (int i = 2; i <= 1e6; i++) {
    fac[i] = fac[i - 1] * i % mod;
    inv[i] = -inv[mod % i] * (mod / i) % mod;
    while (inv[i] < 0)
      inv[i] += mod;
  }
  for (int i = 2; i <= 1e6; i++)
    inv[i] = inv[i] * inv[i - 1] % mod;
}
ll C(int n, int m) { return fac[n] * inv[m] % mod * inv[n - m] % mod; }
ll qpow(ll a, ll b) {
  if (b < 0)
    return 0;
  ll ans = 1;
  a %= mod;
  while (b) {
    if (b & 1)
      ans = (ans * a) % mod;
    b >>= 1, a = (a * a) % mod;
  }
  return ans % mod;
}
int main() {
  ios;
  cin >> k >> s;
  init();
  int n = sz(s);
  rep(i, n, n + k) ans +=
      C(i - 1, n - 1) * qpow(25, i - n) % mod * qpow(26, n + k - i) % mod,
      ans %= mod;
  cout << ans << '\\n';
  return 0;
}