Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

void fst() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
#endif
}
int nxt() {
  int x;
  cin >> x;
  return x;
}
int nex_l() {
  long long x;
  cin >> x;
  return x;
}

typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define all(v) v.begin(), v.end()
#define binary(n) cout << bitset<31>(n) << "\n";
#define FOR(i, n) for (int i = 0; i < n; i++)
#define rep(i, a, b) for (int i = a; i < b; i++)
#define input_arr(a, n)                                                        \
  for (int i = 0; i < n; i++)                                                  \
    cin >> a[i];
#define print_arr(a, n)                                                        \
  for (int i = 0; i < n; i++)                                                  \
    cout << a[i] << " ";
#define deb(n) cerr << #n << "=" << n << "\n";

const int MS = 1e6 + 5, mod = 1e9 + 7;

ll fact[MS];
void cal_fact() {
  fact[0] = 1;
  for (int i = 1; i < MS; i++) {
    fact[i] = i * fact[i - 1];
    fact[i] %= mod;
  }
}
ll binpow(ll val, ll deg, ll mod) {
  if (!deg)
    return 1 % mod;
  if (deg & 1)
    return binpow(val, deg - 1, mod) * val % mod;
  ll res = binpow(val, deg >> 1, mod);
  return (res * res) % mod;
}

ll cal_c(ll n, ll i) {
  ll res = fact[n];
  ll div = fact[n - i] * fact[i];
  div %= mod;
  // using fermat little theorum
  div = binpow(div, mod - 2, mod);
  return (res * div) % mod;
}

int main() {
  cal_fact();
  ll n, k;
  cin >> k;
  string s;
  cin >> s;
  n = s.size();

  ll ans = 0;
  for (int i = n; i <= n + k; i++) {
    ans += cal_c(n + k, i) * binpow(25, n + k - i, mod);
    ans %= mod;
  }
  cout << ans << "\n";
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

void fst() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
#endif
}
int nxt() {
  int x;
  cin >> x;
  return x;
}
int nex_l() {
  long long x;
  cin >> x;
  return x;
}

typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define all(v) v.begin(), v.end()
#define binary(n) cout << bitset<31>(n) << "\n";
#define FOR(i, n) for (int i = 0; i < n; i++)
#define rep(i, a, b) for (int i = a; i < b; i++)
#define input_arr(a, n)                                                        \
  for (int i = 0; i < n; i++)                                                  \
    cin >> a[i];
#define print_arr(a, n)                                                        \
  for (int i = 0; i < n; i++)                                                  \
    cout << a[i] << " ";
#define deb(n) cerr << #n << "=" << n << "\n";

const int MS = 2e6 + 5, mod = 1e9 + 7;

ll fact[MS];
void cal_fact() {
  fact[0] = 1;
  for (int i = 1; i < MS; i++) {
    fact[i] = i * fact[i - 1];
    fact[i] %= mod;
  }
}
ll binpow(ll val, ll deg, ll mod) {
  if (!deg)
    return 1 % mod;
  if (deg & 1)
    return binpow(val, deg - 1, mod) * val % mod;
  ll res = binpow(val, deg >> 1, mod);
  return (res * res) % mod;
}

ll cal_c(ll n, ll i) {
  ll res = fact[n];
  ll div = fact[n - i] * fact[i];
  div %= mod;
  // using fermat little theorum
  div = binpow(div, mod - 2, mod);
  return (res * div) % mod;
}

int main() {
  cal_fact();
  ll n, k;
  cin >> k;
  string s;
  cin >> s;
  n = s.size();

  ll ans = 0;
  for (int i = n; i <= n + k; i++) {
    ans += cal_c(n + k, i) * binpow(25, n + k - i, mod);
    ans %= mod;
  }
  cout << ans << "\n";
}