Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#ifndef Local
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")
#endif

#include <bits/stdc++.h>

using namespace std;

#define popCnt(x) (__builtin_popcountll(x))
#define sz(x) ((int)(x.size()))
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
typedef long long Long;
typedef double Double;

template <class U, class V> istream &operator>>(istream &is, pair<U, V> &p) {
  is >> p.first >> p.second;
  return is;
}
template <class T> istream &operator>>(istream &is, vector<T> &v) {
  for (auto &x : v) {
    is >> x;
  }
  return is;
}

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto &x : v) {
    os << x << " ";
  }
  return os;
}

const int MOD = round(1e9 + 7);

int power(int base, int p) {
  if (p == 0)
    return 1;
  int res = power(base, p / 2);
  res = 1LL * res * res % MOD;
  if (p & 1) {
    res = 1LL * res * base % MOD;
  }
  return res;
}

int modInverse(int x) { return power(x, MOD - 2); }

const int FN = 1e6 + 5;
int fact[FN];
int inv_fact[FN];

void buildFactorial() {
  fact[0] = 1;
  inv_fact[0] = 1;
  for (int i = 1; i < FN; ++i) {
    fact[i] = 1LL * i * fact[i - 1] % MOD;
    inv_fact[i] = modInverse(fact[i]);
  }
}

int nCr(int n, int r) {
  if (r > n)
    return 0;
  int res = fact[n];
  res = 1LL * res * inv_fact[r] % MOD;
  res = 1LL * res * inv_fact[n - r] % MOD;
  return res;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  buildFactorial();
  int k;
  string s;
  cin >> k >> s;

  int res = 0;
  for (int i = 0; i <= k; ++i) {
    int tmp = power(26, i);
    tmp = 1LL * tmp * power(25, k - i) % MOD;
    tmp = 1LL * tmp * nCr(k - i + sz(s) - 1, k - i) % MOD;
    res = (res + tmp) % MOD;
  }
  cout << res << endl;

  return 0;
}

Fixed submission:
#ifndef Local
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")
#endif

#include <bits/stdc++.h>

using namespace std;

#define popCnt(x) (__builtin_popcountll(x))
#define sz(x) ((int)(x.size()))
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
typedef long long Long;
typedef double Double;

template <class U, class V> istream &operator>>(istream &is, pair<U, V> &p) {
  is >> p.first >> p.second;
  return is;
}
template <class T> istream &operator>>(istream &is, vector<T> &v) {
  for (auto &x : v) {
    is >> x;
  }
  return is;
}

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto &x : v) {
    os << x << " ";
  }
  return os;
}

const int MOD = round(1e9 + 7);

int power(int base, int p) {
  if (p == 0)
    return 1;
  int res = power(base, p / 2);
  res = 1LL * res * res % MOD;
  if (p & 1) {
    res = 1LL * res * base % MOD;
  }
  return res;
}

int modInverse(int x) { return power(x, MOD - 2); }

const int FN = 2e6 + 5;
int fact[FN];
int inv_fact[FN];

void buildFactorial() {
  fact[0] = 1;
  inv_fact[0] = 1;
  for (int i = 1; i < FN; ++i) {
    fact[i] = 1LL * i * fact[i - 1] % MOD;
    inv_fact[i] = modInverse(fact[i]);
  }
}

int nCr(int n, int r) {
  if (r > n)
    return 0;
  int res = fact[n];
  res = 1LL * res * inv_fact[r] % MOD;
  res = 1LL * res * inv_fact[n - r] % MOD;
  return res;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  buildFactorial();
  int k;
  string s;
  cin >> k >> s;

  int res = 0;
  for (int i = 0; i <= k; ++i) {
    int tmp = power(26, i);
    tmp = 1LL * tmp * power(25, k - i) % MOD;
    tmp = 1LL * tmp * nCr(k - i + sz(s) - 1, k - i) % MOD;
    res = (res + tmp) % MOD;
  }
  cout << res << endl;

  return 0;
}