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

/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i, m, n) for (ll i = (m); i < (n); i++)
#define rrep(i, m, n) for (ll i = (m); i >= (n); i--)
#define printa(x, n)                                                           \\
  for (ll i = 0; i < n; i++) {                                                 \\
    cout << (x[i]) << " \\n"[i == n - 1];                                       \\
  };
void print() {}
template <class H, class... T> void print(H &&h, T &&...t) {
  cout << h << " \\n"[sizeof...(t) == 0];
  print(forward<T>(t)...);
}
struct Combination {
private:
  ll N;
  vector<ll> fac, facinv;

public:
  Combination(ll n) {
    N = n;
    fac.push_back(1);
    fac.push_back(1);
    rep(i, 2, N + 1) fac.push_back(fac[i - 1] * i % MOD);
    rep(i, 0, N + 1) facinv.push_back(power(fac[i], MOD - 2));
  }
  ll power(ll x, ll n) {
    if (n == 0)
      return 1LL;
    ll res = power(x * x % MOD, n / 2);
    if (n % 2 == 1)
      res = res * x % MOD;
    return res;
  }
  ll nck(ll n, ll k) {
    if (k == 0 || n == k)
      return 1LL;
    return fac[n] * facinv[k] % MOD * facinv[n - k] % MOD;
  }
  ll npk(ll n, ll k) {
    if (k == 0 || n == k)
      return 1LL;
    return fac[n] * facinv[n - k] % MOD;
  }
  ll get(ll x) { return fac[x]; };
  ll getinv(ll x) { return facinv[x]; };
};
vector<ll> factor(ll M) { // 素因数分解
  vector<ll> dd;
  if (M == 1) {
    dd.push_back(1);
    return dd;
  }
  for (ll i = 2; i * i <= M; i++) {
    while (M % i == 0) {
      dd.push_back(i);
      M /= i;
    }
  }
  if (M != 1)
    dd.push_back(M);
  sort(dd.begin(), dd.end());
  return dd;
}
ll val[2000010] = {};

void solve() {
  ll K;
  cin >> K;
  string S;
  cin >> S;
  ll N = S.size();
  Combination cb(2000010);
  rep(i, N, N + K + 1) {
    val[i] = cb.nck(i, N - 1) * cb.power(25, i - (N - 1)) % MOD;
  }
  // printa(val, N+K+1);
  ll ans = 1;
  rep(i, N, N + K) {
    ans = ans * 26 + val[i];
    ans %= MOD;
  }
  print(ans);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}

Error: 0

Fixed submission:

/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i, m, n) for (ll i = (m); i < (n); i++)
#define rrep(i, m, n) for (ll i = (m); i >= (n); i--)
#define printa(x, n)                                                           \\
  for (ll i = 0; i < n; i++) {                                                 \\
    cout << (x[i]) << " \\n"[i == n - 1];                                       \\
  };
void print() {}
template <class H, class... T> void print(H &&h, T &&...t) {
  cout << h << " \\n"[sizeof...(t) == 0];
  print(forward<T>(t)...);
}
struct Combination {
private:
  ll N;
  vector<ll> fac, facinv;

public:
  Combination(ll n) {
    N = n;
    fac.push_back(1);
    fac.push_back(1);
    rep(i, 2, N + 1) fac.push_back(fac[i - 1] * i % MOD);
    rep(i, 0, N + 1) facinv.push_back(power(fac[i], MOD - 2));
  }
  ll power(ll x, ll n) {
    if (n == 0)
      return 1LL;
    ll res = power(x * x % MOD, n / 2);
    if (n % 2 == 1)
      res = res * x % MOD;
    return res;
  }
  ll nck(ll n, ll k) {
    if (k == 0 || n == k)
      return 1LL;
    return fac[n] * facinv[k] % MOD * facinv[n - k] % MOD;
  }
  ll npk(ll n, ll k) {
    if (k == 0 || n == k)
      return 1LL;
    return fac[n] * facinv[n - k] % MOD;
  }
  ll get(ll x) { return fac[x]; };
  ll getinv(ll x) { return facinv[x]; };
};
vector<ll> factor(ll M) { // 素因数分解
  vector<ll> dd;
  if (M == 1) {
    dd.push_back(1);
    return dd;
  }
  for (ll i = 2; i * i <= M; i++) {
    while (M % i == 0) {
      dd.push_back(i);
      M /= i;
    }
  }
  if (M != 1)
    dd.push_back(M);
  sort(dd.begin(), dd.end());
  return dd;
}
ll val[1000010] = {};

void solve() {
  ll K;
  cin >> K;
  string S;
  cin >> S;
  ll N = S.size();
  Combination cb(1000010);
  rep(i, N, N + K + 1) {
    val[i] = cb.nck(i, N - 1) * cb.power(25, i - (N - 1)) % MOD;
  }
  // printa(val, N+K+1);
  ll ans = 1;
  rep(i, N, N + K) {
    ans = ans * 26 + val[i];
    ans %= MOD;
  }
  print(ans);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}