Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cmath>     //sqrt pow
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // dequef
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector

#define rep(i, n) for (int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
ll modPow(ll a, ll n, ll p) { // 繰り返し二乗法 a**n % p
  if (!n)
    return 1;
  if (n == 1)
    return a % p;
  if (n & 1)
    return (a * modPow(a, n - 1, p)) % p;
  ll t = modPow(a, n / 2, p);
  return (t * t) % p;
}
ll choose(ll n, ll k, vector<ll> &fact, vector<ll> &inv) {
  return fact[n] * (inv[k] * inv[n - k] % mod) % mod;
}
int main() {
  const int len = 100000;
  vector<ll> fact(len), inv(len);
  fact[0] = fact[1] = 1;
  for (int i = 2; i < len; i++)
    fact[i] = fact[i - 1] * i % mod;
  inv[len - 1] = modPow(fact[len - 1], mod - 2, mod);
  for (int i = len - 2; i >= 0; i--)
    inv[i] = inv[i + 1] * (i + 1) % mod;
  int k;
  string s;
  cin >> k >> s;
  int n = s.size();
  ll ans = 0;
  rep(x, k + 1) {
    ll num = choose(k + n - x - 1, n - 1, fact, inv);
    (num *= modPow(26, x, mod)) %= mod;
    (num *= modPow(25, k - x, mod)) % mod;
    (ans += num) %= mod;
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cmath>     //sqrt pow
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // dequef
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector

#define rep(i, n) for (int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
ll modPow(ll a, ll n, ll p) { // 繰り返し二乗法 a**n % p
  if (!n)
    return 1;
  if (n == 1)
    return a % p;
  if (n & 1)
    return (a * modPow(a, n - 1, p)) % p;
  ll t = modPow(a, n / 2, p);
  return (t * t) % p;
}
ll choose(ll n, ll k, vector<ll> &fact, vector<ll> &inv) {
  return fact[n] * (inv[k] * inv[n - k] % mod) % mod;
}
int main() {
  const int len = 2000002;
  vector<ll> fact(len), inv(len);
  fact[0] = fact[1] = 1;
  for (int i = 2; i < len; i++)
    fact[i] = fact[i - 1] * i % mod;
  inv[len - 1] = modPow(fact[len - 1], mod - 2, mod);
  for (int i = len - 2; i >= 0; i--)
    inv[i] = inv[i + 1] * (i + 1) % mod;
  int k;
  string s;
  cin >> k >> s;
  int n = s.size();
  ll ans = 0;
  rep(x, k + 1) {
    ll num = choose(k + n - x - 1, n - 1, fact, inv);
    (num *= modPow(26, x, mod)) %= mod;
    (num *= modPow(25, k - x, mod)) % mod;
    (ans += num) %= mod;
  }
  cout << ans << endl;
}