Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
void debugF(ostream &os) { os << endl; }
template <typename Head, typename... Tail>
void debugF(ostream &os, Head H, Tail... T) {
  os << " " << H;
  debugF(os, T...);
}
#define debug(...)                                                             \
  cout << "[" << #__VA_ARGS__ << "]:", debugF(cout, __VA_ARGS__)
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
  for (auto &x : v)
    is >> x;
  return is;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (int i = 0; i < v.size(); os << (i > 0 ? " " : "") << v[i++])
    ;
  return os;
}

ll mod = 1e9 + 7;
vi fat, fatI;
int maxn = 1e6 + 42;

ll expMod(ll a, ll b, ll mod) {
  ll ans = 1;
  while (b) {
    if (b & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}

void init() {
  fat.resize(maxn + 1);
  fatI.resize(maxn + 1);
  fat[0] = fatI[0] = 1;
  for (int i = 1; i <= maxn; i++) {
    fat[i] = (fat[i - 1] * ll(i)) % mod;
    fatI[i] = expMod(fat[i], mod - 2, mod);
  }
}

int C(int n, int k) {
  ll tmp = (fat[n] * ll(fatI[k])) % mod;
  tmp *= fatI[n - k];
  tmp %= mod;
  return tmp;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  init();
  int n, k, i;
  cin >> k;
  string s;
  cin >> s;
  n = s.size();
  ll ans = 0;
  int p25 = expMod(25, k, mod);
  ll p25I = expMod(25, mod - 2, mod);
  int p26 = 1;
  for (i = 0; i <= k; i++) {
    ll tmp = C(n + k - i - 1, n - 1);
    tmp *= p25;
    tmp %= mod;
    tmp *= p26;
    tmp %= mod;
    ans += tmp;
    ans %= mod;
    p26 = (p26 * ll(26)) % mod;
    p25 = (p25 * p25I) % mod;
  }
  cout << ans << "\n";

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
void debugF(ostream &os) { os << endl; }
template <typename Head, typename... Tail>
void debugF(ostream &os, Head H, Tail... T) {
  os << " " << H;
  debugF(os, T...);
}
#define debug(...)                                                             \
  cout << "[" << #__VA_ARGS__ << "]:", debugF(cout, __VA_ARGS__)
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
  for (auto &x : v)
    is >> x;
  return is;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (int i = 0; i < v.size(); os << (i > 0 ? " " : "") << v[i++])
    ;
  return os;
}

ll mod = 1e9 + 7;
vi fat, fatI;
int maxn = 2e6 + 42;

ll expMod(ll a, ll b, ll mod) {
  ll ans = 1;
  while (b) {
    if (b & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}

void init() {
  fat.resize(maxn + 1);
  fatI.resize(maxn + 1);
  fat[0] = fatI[0] = 1;
  for (int i = 1; i <= maxn; i++) {
    fat[i] = (fat[i - 1] * ll(i)) % mod;
    fatI[i] = expMod(fat[i], mod - 2, mod);
  }
}

int C(int n, int k) {
  ll tmp = (fat[n] * ll(fatI[k])) % mod;
  tmp *= fatI[n - k];
  tmp %= mod;
  return tmp;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  init();
  int n, k, i;
  cin >> k;
  string s;
  cin >> s;
  n = s.size();
  ll ans = 0;
  int p25 = expMod(25, k, mod);
  ll p25I = expMod(25, mod - 2, mod);
  int p26 = 1;
  for (i = 0; i <= k; i++) {
    ll tmp = C(n + k - i - 1, n - 1);
    tmp *= p25;
    tmp %= mod;
    tmp *= p26;
    tmp %= mod;
    ans += tmp;
    ans %= mod;
    p26 = (p26 * ll(26)) % mod;
    p25 = (p25 * p25I) % mod;
  }
  cout << ans << "\n";

  return 0;
}