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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 1e9 + 7;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

vector<ll> inv, fact, invfact;
void Mod_build(int n = 2010101) {
  fact.resize(n + 1);
  inv.resize(n + 1);
  invfact.resize(n + 1);
  fact[0] = inv[0] = invfact[0] = 1;
  inv[1] = 1;
  for (ll i = 0; i < n; i++) {
    fact[i + 1] = fact[i] * (i + 1) % mod;
    if (i > 0)
      inv[i + 1] = mod - inv[mod % (i + 1)] * (mod / (i + 1)) % mod;
    invfact[i + 1] = invfact[i] * inv[i + 1] % mod;
  }
}
ll perm(int n, int k) {
  if (n < 0 || k < 0 || k > n)
    return 0;
  return fact[n] * invfact[n - k] % mod;
}
ll comb(int n, int k) {
  if (n < 0 || k < 0 || k > n)
    return 0;
  return (fact[n] * invfact[n - k] % mod) * invfact[k] % mod;
}
ll powmod(ll n, ll k) {
  k %= mod - 1;
  if (k < 0)
    k += mod - 1;
  ll ret = 1;
  while (k) {
    if (k & 1)
      ret = ret * n % mod;
    n = n * n % mod;
    k >>= 1;
  }
  return ret;
}

int main() {
  Mod_build();
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int i, j;
  ll k;
  cin >> k;
  string s;
  cin >> s;
  ll n = s.size();
  ll m = n + k;
  ll ans = 0;
  for (i = 0; i <= m; i++) {
    ll sum = comb(m - i - 1, n - 1) * powmod(25, k - i);
    sum %= mod;
    sum *= powmod(26, i);
    sum %= mod;
    ans += sum;
    ans %= mod;
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 1e9 + 7;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

vector<ll> inv, fact, invfact;
void Mod_build(int n = 1010101) {
  fact.resize(n + 1);
  inv.resize(n + 1);
  invfact.resize(n + 1);
  fact[0] = inv[0] = invfact[0] = 1;
  inv[1] = 1;
  for (ll i = 0; i < n; i++) {
    fact[i + 1] = fact[i] * (i + 1) % mod;
    if (i > 0)
      inv[i + 1] = mod - inv[mod % (i + 1)] * (mod / (i + 1)) % mod;
    invfact[i + 1] = invfact[i] * inv[i + 1] % mod;
  }
}
ll perm(int n, int k) {
  if (n < 0 || k < 0 || k > n)
    return 0;
  return fact[n] * invfact[n - k] % mod;
}
ll comb(int n, int k) {
  if (n < 0 || k < 0 || k > n)
    return 0;
  return (fact[n] * invfact[n - k] % mod) * invfact[k] % mod;
}
ll powmod(ll n, ll k) {
  k %= mod - 1;
  if (k < 0)
    k += mod - 1;
  ll ret = 1;
  while (k) {
    if (k & 1)
      ret = ret * n % mod;
    n = n * n % mod;
    k >>= 1;
  }
  return ret;
}

int main() {
  Mod_build();
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int i, j;
  ll k;
  cin >> k;
  string s;
  cin >> s;
  ll n = s.size();
  ll m = n + k;
  ll ans = 0;
  for (i = 0; i <= m; i++) {
    ll sum = comb(m - i - 1, n - 1) * powmod(25, k - i);
    sum %= mod;
    sum *= powmod(26, i);
    sum %= mod;
    ans += sum;
    ans %= mod;
  }
  cout << ans << endl;
}