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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(nullptr);                                                            \\
  cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\\n'
#define all(x) x.begin(), x.end()

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <class T>
using oset =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

using vvll = vector<vector<ll>>;
using vll = vector<ll>;

const ll maxs = 1e6 + 5;
const ll lmaxs = 20;
ll mod = 1e9 + 7;
ll oo = 1e15;

ll fast(ll x, ll y) {
  ll res = 1;
  while (y) {
    if (y & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    y >>= 1;
  }
  return res;
}

ll inv(ll n) { return fast(n, mod - 2); }

const ll N = 2e6 + 5;
ll fact[N];
ll ifact[N];
ll p25[N];

void pre() {

  fact[0] = 1;
  ifact[0] = 1;
  p25[0] = 1;
  for (ll i = 1; i < N; i++) {
    fact[i] = fact[i - 1] * i % mod;
    ifact[i] = inv(fact[i]);
    p25[i] = p25[i - 1] * 25 % mod;
  }
}

ll ncr(ll n, ll r) {
  ll tmp = fact[n] * ifact[r] % mod;
  tmp = tmp * ifact[n - r] % mod;
  return tmp;
}

void solve() {

  ll k;
  cin >> k;
  string s;
  cin >> s;
  ll n = s.size();
  ll sz = n + k;
  ll ans = 0;
  for (ll i = n; i <= sz; i++) {
    ans += ncr(sz, i) * p25[sz - i] % mod;
    ans %= mod;
  }
  cout << ans << endl;
}

int main() {
  // #ifndef ONLINE_JUDGE
  // freopen("input00.txt","r",stdin);
  // #endif
  IOS;
  pre();
  ll T = 1;
  // cin>>T;
  while (T--) {
    solve();
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(nullptr);                                                            \\
  cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\\n'
#define all(x) x.begin(), x.end()

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <class T>
using oset =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

using vvll = vector<vector<ll>>;
using vll = vector<ll>;

const ll maxs = 1e6 + 5;
const ll lmaxs = 20;
ll mod = 1e9 + 7;
ll oo = 1e15;

ll fast(ll x, ll y) {
  ll res = 1;
  while (y) {
    if (y & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    y >>= 1;
  }
  return res;
}

ll inv(ll n) { return fast(n, mod - 2); }

ll fact[maxs];
ll ifact[maxs];
ll p25[maxs];

void pre() {

  fact[0] = 1;
  ifact[0] = 1;
  p25[0] = 1;
  for (ll i = 1; i < maxs; i++) {
    fact[i] = fact[i - 1] * i % mod;
    ifact[i] = inv(fact[i]);
    p25[i] = p25[i - 1] * 25 % mod;
  }
}

ll ncr(ll n, ll r) {
  ll tmp = fact[n] * ifact[r] % mod;
  tmp = tmp * ifact[n - r] % mod;
  return tmp;
}

void solve() {

  ll k;
  cin >> k;
  string s;
  cin >> s;
  ll n = s.size();
  ll sz = n + k;
  ll ans = 0;
  for (ll i = n; i <= sz; i++) {
    ans += ncr(sz, i) * p25[sz - i] % mod;
    ans %= mod;
  }
  cout << ans << endl;
}

int main() {
  // #ifndef ONLINE_JUDGE
  // freopen("input00.txt","r",stdin);
  // #endif
  IOS;
  pre();
  ll T = 1;
  // cin>>T;
  while (T--) {
    solve();
  }
  return 0;
}