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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define REP(i, n) for (ll(i) = (0); (i) < (n); ++i)
#define REV(i, n) for (ll(i) = (n)-1; (i) >= 0; --i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v, n)                                                           \\
  {                                                                            \\
    REP(WW, n) cerr << v[WW] << ' ';                                           \\
    cerr << endl;                                                              \\
  }
#define SHOW2d(v, WW, HH)                                                      \\
  {                                                                            \\
    REP(W_, WW) {                                                              \\
      REP(H_, HH) cerr << v[W_][H_] << ' ';                                    \\
      cerr << endl;                                                            \\
    }                                                                          \\
  }
#define ALL(v) v.begin(), v.end()
#define Decimal fixed << setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> P;

// a^b % MOD
long long mod_pow(ll a, ll b) {
  long long ret = 1;
  long long c = a;
  for (int i = 0; i <= 60; i++) {
    if (b & (1LL << i))
      ret = (ret * c) % MOD;
    c = (c * c) % MOD;
  }
  return ret;
}

// ａをbで割る
long long mod_div(long long a, long long b) {
  long long tmp = MOD - 2, c = b, ret = 1;
  while (tmp > 0) {
    if (tmp & 1) {
      ret *= c;
      ret %= MOD;
    }
    c *= c;
    c %= MOD;
    tmp >>= 1;
  }
  return a * ret % MOD;
}

#define MAX_K 2222222
vector<long long> fact(MAX_K);
long long combination(long long n, long long r) {
  if (n < r || n < 0 || r < 0)
    return 0;
  if (fact[0] != 1) {
    fact[0] = 1;
    for (long long i = 1; i < MAX_K; i++)
      fact[i] = (fact[i - 1] * i) % MOD;
  }
  long long ret = fact[n];
  long long tmp = (fact[r] * fact[n - r]) % MOD;
  return mod_div(ret, tmp);
}

int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);

  ll n;
  cin >> n;
  string str;
  cin >> str;
  ll m = str.size();
  ll ans = 0;
  for (ll i = m; i <= n + m; i++) {
    ll seica = combination(i - 1, m - 1);
    seica = seica * mod_pow(25, i - m) % MOD;
    seica = seica * mod_pow(26, n + m - i) % MOD;
    ans = (ans + seica) % MOD;
    // cout << "seica: " << seica << endl;
  }
  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define REP(i, n) for (ll(i) = (0); (i) < (n); ++i)
#define REV(i, n) for (ll(i) = (n)-1; (i) >= 0; --i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v, n)                                                           \\
  {                                                                            \\
    REP(WW, n) cerr << v[WW] << ' ';                                           \\
    cerr << endl;                                                              \\
  }
#define SHOW2d(v, WW, HH)                                                      \\
  {                                                                            \\
    REP(W_, WW) {                                                              \\
      REP(H_, HH) cerr << v[W_][H_] << ' ';                                    \\
      cerr << endl;                                                            \\
    }                                                                          \\
  }
#define ALL(v) v.begin(), v.end()
#define Decimal fixed << setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> P;

// a^b % MOD
long long mod_pow(ll a, ll b) {
  long long ret = 1;
  long long c = a;
  for (int i = 0; i <= 60; i++) {
    if (b & (1LL << i))
      ret = (ret * c) % MOD;
    c = (c * c) % MOD;
  }
  return ret;
}

// ａをbで割る
long long mod_div(long long a, long long b) {
  long long tmp = MOD - 2, c = b, ret = 1;
  while (tmp > 0) {
    if (tmp & 1) {
      ret *= c;
      ret %= MOD;
    }
    c *= c;
    c %= MOD;
    tmp >>= 1;
  }
  return a * ret % MOD;
}

#define MAX_K 1111111
vector<long long> fact(MAX_K);
long long combination(long long n, long long r) {
  if (n < r || n < 0 || r < 0)
    return 0;
  if (fact[0] != 1) {
    fact[0] = 1;
    for (long long i = 1; i < MAX_K; i++)
      fact[i] = (fact[i - 1] * i) % MOD;
  }
  long long ret = fact[n];
  long long tmp = (fact[r] * fact[n - r]) % MOD;
  return mod_div(ret, tmp);
}

int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);

  ll n;
  cin >> n;
  string str;
  cin >> str;
  ll m = str.size();
  ll ans = 0;
  for (ll i = m; i <= n + m; i++) {
    ll seica = combination(i - 1, m - 1);
    seica = seica * mod_pow(25, i - m) % MOD;
    seica = seica * mod_pow(26, n + m - i) % MOD;
    ans = (ans + seica) % MOD;
    // cout << "seica: " << seica << endl;
  }
  cout << ans << endl;

  return 0;
}