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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
// #define ll long long
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int(i) = (int)(n)-1; (i) >= 0; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define all(x) (x).begin(), (x).end()
ll t1, t2, t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;

// nの最大値が1e5の時とかは使える
const int MAX = 2000001;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理 O(MAX)
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % mod;
    inv[i] = mod - inv[mod % i] * (mod / i) % mod;
    finv[i] = finv[i - 1] * inv[i] % mod;
  }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

int main() {
  // 前処理
  COMinit();
  ll k;
  string s;
  cin >> k;
  cin >> s;
  ll len1 = s.size();
  ll len = len1 + k;
  vector<ll> po1(len), po2(len);
  po1[0] = 1;
  po2[0] = 1;
  rep(i, len - 1) {
    po1[i + 1] = po1[i] * 25;
    po1[i + 1] %= mod;
    po2[i + 1] = po2[i] * 26;
    po2[i + 1] %= mod;
  }
  ll ans = 0;
  REP(i, len1 - 1, len) {
    // cout << i+1 << " " << i-len1+1 << " " << len-i << endl;
    // cout << COM(i,i-len1+1) << " " << po1[i-len1+1] << " " << po2[len-i-1] <<
    // endl;
    ans += (COM(i, i - len1 + 1) * po1[i - len1 + 1] % mod) * po2[len - i - 1];
    ans %= mod;
    // cout << ans << endl;
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
// #define ll long long
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int(i) = (int)(n)-1; (i) >= 0; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define all(x) (x).begin(), (x).end()
ll t1, t2, t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;

// nの最大値が1e5の時とかは使える
const int MAX = 200001;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理 O(MAX)
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % mod;
    inv[i] = mod - inv[mod % i] * (mod / i) % mod;
    finv[i] = finv[i - 1] * inv[i] % mod;
  }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

int main() {
  // 前処理
  COMinit();
  ll k;
  string s;
  cin >> k;
  cin >> s;
  ll len1 = s.size();
  ll len = len1 + k;
  vector<ll> po1(len), po2(len);
  po1[0] = 1;
  po2[0] = 1;
  rep(i, len - 1) {
    po1[i + 1] = po1[i] * 25;
    po1[i + 1] %= mod;
    po2[i + 1] = po2[i] * 26;
    po2[i + 1] %= mod;
  }
  ll ans = 0;
  REP(i, len1 - 1, len) {
    // cout << i+1 << " " << i-len1+1 << " " << len-i << endl;
    // cout << COM(i,i-len1+1) << " " << po1[i-len1+1] << " " << po2[len-i-1] <<
    // endl;
    ans += (COM(i, i - len1 + 1) * po1[i - len1 + 1] % mod) * po2[len - i - 1];
    ans %= mod;
    // cout << ans << endl;
  }
  cout << ans << endl;
}