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

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using ll = long long;
#define int ll
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define SZ(x) ((int)x.size())
#define fi first
#define se second
const int INF = 1e15;
const int MOD = 1e9 + 7;
using namespace std;

template <class T> using vc = vector<T>;
template <class T> using vvc = vc<vc<T>>;

using pi = pair<int, int>;
using vi = vc<int>;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

const int MX = 2000100 + 5;
int fac[MX + 5], inv[MX + 5];

int power(int x, int y, int p) {
  int res = 1;
  x = x % p;
  while (y) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
void init() {
  int n = MX + 4;
  fac[0] = 1;
  for (int i = 0; i < n; ++i)
    fac[i + 1] = fac[i] * (i + 1) % MOD;
  inv[n] = power(fac[n], MOD - 2, MOD);
  for (int i = n - 1; i >= 0; --i)
    inv[i] = inv[i + 1] * (i + 1) % MOD;
}
int comb(int n, int r) { return (fac[n] * inv[r]) % MOD * inv[n - r] % MOD; }

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
  init();

  int K;
  cin >> K;
  string S;
  cin >> S;
  int T = K + SZ(S);
  int ans = 0;
  rng(i, SZ(S), K + SZ(S) + 1) {
    ans += (comb(T, i) * power(25, T - i, MOD)) % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using ll = long long;
#define int ll
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define SZ(x) ((int)x.size())
#define fi first
#define se second
const int INF = 1e15;
const int MOD = 1e9 + 7;
using namespace std;

template <class T> using vc = vector<T>;
template <class T> using vvc = vc<vc<T>>;

using pi = pair<int, int>;
using vi = vc<int>;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

const int MX = 1777777 + 5;
int fac[MX + 5], inv[MX + 5];

int power(int x, int y, int p) {
  int res = 1;
  x = x % p;
  while (y) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
void init() {
  int n = MX + 4;
  fac[0] = 1;
  for (int i = 0; i < n; ++i)
    fac[i + 1] = fac[i] * (i + 1) % MOD;
  inv[n] = power(fac[n], MOD - 2, MOD);
  for (int i = n - 1; i >= 0; --i)
    inv[i] = inv[i + 1] * (i + 1) % MOD;
}
int comb(int n, int r) { return (fac[n] * inv[r]) % MOD * inv[n - r] % MOD; }

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
  init();

  int K;
  cin >> K;
  string S;
  cin >> S;
  int T = K + SZ(S);
  int ans = 0;
  rng(i, SZ(S), K + SZ(S) + 1) {
    ans += (comb(T, i) * power(25, T - i, MOD)) % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
}