Problem p02632 (C++)

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

#define vl vector<ll>
#define vi vector<int>

#define ff first
#define ss second

#define pb push_back
#define MOD 1000000007
// const int nax = 1e6+5;
#define inf 4e18

#define display(v)                                                             \
  for (int i = 0; i < v.size(); ++i)                                           \
  cout << v[i] << " "
#define all(v) v.begin(), v.end()
ll sqr(ll x) { return x * x; }
inline ll add(ll a, ll b) {
  ll c = a + b;
  if (c >= MOD)
    c -= MOD;
  return c;
}
inline ll mul(ll a, ll b) { return (a * 1ll * b) % MOD; }
inline ll sub(ll a, ll b) {
  ll c = a - b;
  if (c < 0)
    c += MOD;
  return c;
}
const int nax = 1000 * 1000 + 10;
const int MAX_ = 1e6 + 2;
ll fac[MAX_];
ll inv[MAX_];
ll facinv[MAX_];

ll power(ll a, ll b) {
  ll ans = 1LL;
  while (b) {
    if (b & 1) {
      ans = mul(ans, a);
      b--;
    } else {
      a = mul(a, a);
      b /= 2;
    }
  }
  return ans;
}

void furious() {
  fac[1] = 1;
  fac[0] = 1;
  inv[0] = inv[1] = 1;
  facinv[0] = facinv[1] = 1;
  for (int i = 2; i < MAX_; i++) {
    fac[i] = (i * fac[i - 1]) % MOD;
    inv[i] = (inv[MOD % i] * (MOD - MOD / i)) % MOD;
    facinv[i] = (inv[i] * facinv[i - 1]) % MOD;
  }
}

ll ncrm(ll n, ll r) {
  if (n == r || r == 0) {
    return 1;
  }
  if (n < r) {
    return 0;
  }
  return mul(fac[n], mul(facinv[r], facinv[n - r]));
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  furious();
  ll k;
  cin >> k;
  string str;
  cin >> str;
  ll n = str.size();
  n += k;
  ll pos = power(26, n);
  for (int i = 0; i < str.size(); ++i) {
    ll val = mul(ncrm(n, i), power(25, n - i));
    pos = sub(pos, val);
  }
  cout << pos;

  return 0;
}

// Химаншу


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

#define vl vector<ll>
#define vi vector<int>

#define ff first
#define ss second

#define pb push_back
#define MOD 1000000007
// const int nax = 1e6+5;
#define inf 4e18

#define display(v)                                                             \
  for (int i = 0; i < v.size(); ++i)                                           \
  cout << v[i] << " "
#define all(v) v.begin(), v.end()
ll sqr(ll x) { return x * x; }
inline ll add(ll a, ll b) {
  ll c = a + b;
  if (c >= MOD)
    c -= MOD;
  return c;
}
inline ll mul(ll a, ll b) { return (a * 1ll * b) % MOD; }
inline ll sub(ll a, ll b) {
  ll c = a - b;
  if (c < 0)
    c += MOD;
  return c;
}
const int nax = 1000 * 1000 + 10;
const int MAX_ = 5e6 + 2;
ll fac[MAX_];
ll inv[MAX_];
ll facinv[MAX_];

ll power(ll a, ll b) {
  ll ans = 1LL;
  while (b) {
    if (b & 1) {
      ans = mul(ans, a);
      b--;
    } else {
      a = mul(a, a);
      b /= 2;
    }
  }
  return ans;
}

void furious() {
  fac[1] = 1;
  fac[0] = 1;
  inv[0] = inv[1] = 1;
  facinv[0] = facinv[1] = 1;
  for (int i = 2; i < MAX_; i++) {
    fac[i] = (i * fac[i - 1]) % MOD;
    inv[i] = (inv[MOD % i] * (MOD - MOD / i)) % MOD;
    facinv[i] = (inv[i] * facinv[i - 1]) % MOD;
  }
}

ll ncrm(ll n, ll r) {
  if (n == r || r == 0) {
    return 1;
  }
  if (n < r) {
    return 0;
  }
  return mul(fac[n], mul(facinv[r], facinv[n - r]));
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  furious();
  ll k;
  cin >> k;
  string str;
  cin >> str;
  ll n = str.size();
  n += k;
  ll pos = power(26, n);
  for (int i = 0; i < str.size(); ++i) {
    ll val = mul(ncrm(n, i), power(25, n - i));
    pos = sub(pos, val);
  }
  cout << pos;

  return 0;
}

// Химаншу