Problem p02632 (C++)

Buggy submission (status: Runtime Error):
/*input
37564
whydidyoudesertme
*/

// Nihesh Anderson - knandy

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set; // find_by_order, order_of_key
ll MOD = 1000000007;

#define endl '\n'
#define fast_cin()                                                             \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define pb push_back
ll INF = 2000000000000000001;
long double EPS = 1e-9;
ll power(ll a, ll n, ll md) {
  if (n == 0) {
    return 1;
  } else {
    ll res = power(a, n / 2, md);
    res = (res * res) % md;
    if (n % 2 != 0) {
      res = (res * a) % md;
    }
    return res;
  }
}
random_device rndm;
mt19937 grndm(rndm());
void mix(ll *a, ll *b) { shuffle(a, b, grndm); }

const ll MX = 1000006;

ll fact[MX], ifact[MX], pow25[MX], pow26[MX];

ll choose(ll n, ll k) { return fact[n] * ifact[k] % MOD * ifact[n - k] % MOD; }

int main() {
  fast_cin();
  // freopen("input.in","r",stdin);
  // freopen("output.out","w",stdout);
  fact[0] = 1;
  for (ll i = 1; i < MX; i++) {
    fact[i] = (i * fact[i - 1]) % MOD;
  }
  for (ll i = 0; i < MX; i++) {
    ifact[i] = power(fact[i], MOD - 2, MOD);
  }
  pow25[0] = pow26[0] = 1;
  for (ll i = 1; i < MX; i++) {
    pow25[i] = (25 * pow25[i - 1]) % MOD;
    pow26[i] = (26 * pow26[i - 1]) % MOD;
  }
  ll k;
  cin >> k;
  string s;
  cin >> s;
  ll n = s.size();
  ll ans = 0;
  for (ll i = n - 1; i <= n + k - 1; i++) {
    ans = (ans + choose(i, n - 1) * pow26[n + k - 1 - i] % MOD *
                     pow25[i - n + 1] % MOD) %
          MOD;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
/*input
37564
whydidyoudesertme
*/

// Nihesh Anderson - knandy

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set; // find_by_order, order_of_key
ll MOD = 1000000007;

#define endl '\n'
#define fast_cin()                                                             \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define pb push_back
ll INF = 2000000000000000001;
long double EPS = 1e-9;
ll power(ll a, ll n, ll md) {
  if (n == 0) {
    return 1;
  } else {
    ll res = power(a, n / 2, md);
    res = (res * res) % md;
    if (n % 2 != 0) {
      res = (res * a) % md;
    }
    return res;
  }
}
random_device rndm;
mt19937 grndm(rndm());
void mix(ll *a, ll *b) { shuffle(a, b, grndm); }

const ll MX = 2000006;

ll fact[MX], ifact[MX], pow25[MX], pow26[MX];

ll choose(ll n, ll k) { return fact[n] * ifact[k] % MOD * ifact[n - k] % MOD; }

int main() {
  fast_cin();
  // freopen("input.in","r",stdin);
  // freopen("output.out","w",stdout);
  fact[0] = 1;
  for (ll i = 1; i < MX; i++) {
    fact[i] = (i * fact[i - 1]) % MOD;
  }
  for (ll i = 0; i < MX; i++) {
    ifact[i] = power(fact[i], MOD - 2, MOD);
  }
  pow25[0] = pow26[0] = 1;
  for (ll i = 1; i < MX; i++) {
    pow25[i] = (25 * pow25[i - 1]) % MOD;
    pow26[i] = (26 * pow26[i - 1]) % MOD;
  }
  ll k;
  cin >> k;
  string s;
  cin >> s;
  ll n = s.size();
  ll ans = 0;
  for (ll i = n - 1; i <= n + k - 1; i++) {
    ans = (ans + choose(i, n - 1) * pow26[n + k - 1 - i] % MOD *
                     pow25[i - n + 1] % MOD) %
          MOD;
  }
  cout << ans << endl;
  return 0;
}