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

#pragma GCC optimize("O3")

#include <bits/stdc++.h>

using namespace std;

#define forn(i, n) for (long long i = 0; i < (long long)(n); ++i)
#define pb emplace_back
#define endl '\\n'

template <typename T> void _dbg(const char *_s, T _h) {
  cerr << _s << " = " << _h << "\\n";
}

template <typename T, typename... Ts>
void _dbg(const char *_s, T _h, Ts... _t) {
  for (int _b = 0; ((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',';)
    cerr << *_s++;
  cerr << " = " << _h << ",";
  _dbg(_s + 1, _t...);
}

#define int long long

#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

const int N = 2 * 1000 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int k;
string s;
int F[N];

bool read() {
  if (!(cin >> k >> s))
    return false;

  return true;
}

int bpow(int a, int n, int mod = MOD) {
  int res = 1;

  for (; n > 0; n /= 2, (a *= a) %= mod)
    if (n & 1)
      (res *= a) %= mod;

  return res;
}

int rev(int x) { return bpow(x, MOD - 2, MOD); }

int binomial(int n, int k) {
  return k < 0 || n - k < 0 ? 0 : F[n] * rev(F[k] * F[n - k] % MOD) % MOD;
}

void solve(int id = 0) {
  F[0] = 1;

  forn(i, N - 1) F[i + 1] = F[i] * (i + 1) % MOD;

  int res = 0;
  int n = s.size();

  for (int i = 0; i <= k; ++i)
    (res += bpow(26, i) * bpow(25, k - i) % MOD *
            binomial(k - i + n - 1, n - 1) % MOD) %= MOD;

  cout << res << endl;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int T;
  // cin >> T;
  T = 1;

  while (read())
    solve(T++);

  return 0;
}


Error: 0

Fixed submission:

#pragma GCC optimize("O3")

#include <bits/stdc++.h>

using namespace std;

#define forn(i, n) for (long long i = 0; i < (long long)(n); ++i)
#define pb emplace_back
#define endl '\\n'

template <typename T> void _dbg(const char *_s, T _h) {
  cerr << _s << " = " << _h << "\\n";
}

template <typename T, typename... Ts>
void _dbg(const char *_s, T _h, Ts... _t) {
  for (int _b = 0; ((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',';)
    cerr << *_s++;
  cerr << " = " << _h << ",";
  _dbg(_s + 1, _t...);
}

#define int long long

#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

const int N = 500 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int k;
string s;
int F[N];

bool read() {
  if (!(cin >> k >> s))
    return false;

  return true;
}

int bpow(int a, int n, int mod = MOD) {
  int res = 1;

  for (; n > 0; n /= 2, (a *= a) %= mod)
    if (n & 1)
      (res *= a) %= mod;

  return res;
}

int rev(int x) { return bpow(x, MOD - 2, MOD); }

int binomial(int n, int k) { return F[n] * rev(F[k] * F[n - k] % MOD) % MOD; }

void solve(int id = 0) {
  F[0] = 1;

  forn(i, N - 1) F[i + 1] = F[i] * (i + 1) % MOD;

  int res = 0;
  int n = s.size();

  for (int i = 0; i <= k; ++i)
    (res += bpow(26, i) * bpow(25, k - i) % MOD *
            binomial(k - i + n - 1, n - 1) % MOD) %= MOD;

  cout << res << endl;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int T;
  // cin >> T;
  T = 1;

  while (read())
    solve(T++);

  return 0;
}