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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
// const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

ll f[2000200], finv[2000200];

ll modpow(ll a, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

ll modinv(ll a) { return modpow(a, mod - 2); }

ll nCr(ll n, ll r) {
  if (r < 0 || r > n)
    return 0;
  return f[n] * finv[n - r] % mod * finv[r] % mod;
}

ll nHr(ll n, ll r) { return nCr(n + r - 1, r); }

void init() {
  f[0] = 1, finv[0] = 1;
  FOR(i, 1, 2000200) {
    f[i] = i * f[i - 1] % mod;
    finv[i] = modinv(f[i]);
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);

  init();

  ll k;
  string s;
  cin >> k >> s;

  ll sn = s.length();
  ll n = sn + k;
  ll ans = 0;
  FOR(i, sn, n + 1) {
    ll res = nCr(i - 1, sn - 1) * modpow(25, i - sn) % mod;
    ans = (ans + res * modpow(26, n - i)) % mod;
  }
  cout << ans << '\\n';

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
// const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

ll f[1000100], finv[1000100];

ll modpow(ll a, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

ll modinv(ll a) { return modpow(a, mod - 2); }

ll nCr(ll n, ll r) {
  if (r < 0 || r > n)
    return 0;
  return f[n] * finv[n - r] % mod * finv[r] % mod;
}

ll nHr(ll n, ll r) { return nCr(n + r - 1, r); }

void init() {
  f[0] = 1, finv[0] = 1;
  FOR(i, 1, 1000100) {
    f[i] = i * f[i - 1] % mod;
    finv[i] = modinv(f[i]);
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);

  init();

  ll k;
  string s;
  cin >> k >> s;

  ll sn = s.length();
  ll n = sn + k;
  ll ans = 0;
  FOR(i, sn, n + 1) {
    ll res = nCr(i - 1, sn - 1) * modpow(25, i - sn) % mod;
    ans = (ans + res * modpow(26, n - i)) % mod;
  }
  cout << ans << '\\n';

  return 0;
}