Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define rep(i, a, b) for (i = a; i < b; i++)
#define per(i, a, b) for (i = a; i >= b; i--)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define trav(x, it) for (auto it = x.begin(); it != x.end(); it++)
#define pr(x) cout << #x << " = " << x << endl
#define fill(x, y) memset(x, y, sizeof(x))
#define endl "\n"
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ld eps = 1e-7;
const ll mod = 1000000007;
const ll N = 998244353;

ll binpow(ll b, ll p) {
  ll ans = 1;
  while (p > 0) {
    if (p & 1)
      ans = (ans * b) % mod;
    b = (b * b) % mod;
    p >>= 1;
  }
  return ans;
}
ll modinv(ll x) { return binpow(x, mod - 2); }

const int mxn = 1e6 + 10;
ll fac[mxn];
ll invfac[mxn];

ll ncr(ll n, ll r) {
  if (r > n)
    return 0;
  return (((fac[n] * invfac[n - r]) % mod) * invfac[r]) % mod;
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  ll k, n, ans = 1, i, rem = 0, val, len;
  fac[0] = invfac[0] = fac[1] = invfac[1] = 1;
  rep(i, 2, mxn) {
    fac[i] = (fac[i - 1] * i) % mod;
    invfac[i] = modinv(fac[i]);
  }

  string s;
  cin >> k >> s;
  n = s.length() + k;
  len = s.length();
  rep(i, 0, len) {
    val = (ncr(n, i) * binpow(25LL, n - i)) % mod;
    rem = (rem + val) % mod;
  }
  ans = (binpow(26LL, n) - rem + mod) % mod;
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define rep(i, a, b) for (i = a; i < b; i++)
#define per(i, a, b) for (i = a; i >= b; i--)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define trav(x, it) for (auto it = x.begin(); it != x.end(); it++)
#define pr(x) cout << #x << " = " << x << endl
#define fill(x, y) memset(x, y, sizeof(x))
#define endl "\n"
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ld eps = 1e-7;
const ll mod = 1000000007;
const ll N = 998244353;

ll binpow(ll b, ll p) {
  ll ans = 1;
  while (p > 0) {
    if (p & 1)
      ans = (ans * b) % mod;
    b = (b * b) % mod;
    p >>= 1;
  }
  return ans;
}
ll modinv(ll x) { return binpow(x, mod - 2); }

const int mxn = 2e6 + 10;
ll fac[mxn];
ll invfac[mxn];

ll ncr(ll n, ll r) {
  if (r > n)
    return 0;
  return (((fac[n] * invfac[n - r]) % mod) * invfac[r]) % mod;
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  ll k, n, ans = 1, i, rem = 0, val, len;
  fac[0] = invfac[0] = fac[1] = invfac[1] = 1;
  rep(i, 2, mxn) {
    fac[i] = (fac[i - 1] * i) % mod;
    invfac[i] = modinv(fac[i]);
  }

  string s;
  cin >> k >> s;
  n = s.length() + k;
  len = s.length();
  rep(i, 0, len) {
    val = (ncr(n, i) * binpow(25LL, n - i)) % mod;
    rem = (rem + val) % mod;
  }
  ans = (binpow(26LL, n) - rem + mod) % mod;
  cout << ans << endl;
}