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

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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807
// (-2^63 <= long < 2^63)

#define INF (1 << 30)
// 1,073,741,824
//= 536,870,912 *2

#define MOD 1000000007
#define MAX 2000010

#define Rep0(i, n) for (auto i = 0; i < n; i++)
#define Rep1(i, n) for (auto i = 1; i <= n; i++)
#define Sort(P) sort(P.begin(), P.end())
#define Rev(P) reverse(P.begin(), P.end())

ll myPow(ll x, ll n) {
  ll r = 1;
  while (n > 0)
    if (0 == n % 2) {
      x *= x;
      x %= MOD;
      n /= 2;
    } else {
      r *= x;
      r %= MOD;
      n--;
    }
  return r;
}

ll MPl(ll x, ll y) { return (x + y) % MOD; }

ll MMi(ll x, ll y) { return (x - y + MOD) % MOD; }

ll MMul(ll x, ll y) { return (x * y) % MOD; }

// Array
vector<ll> fac(MAX, 0);
vector<ll> finv(MAX, 0);
vector<ll> inv(MAX, 0);

void DivInit() { // fac, finv, inv
  fac.at(0) = 1;
  fac.at(1) = 1;
  finv.at(0) = 1;
  finv.at(1) = 1;
  inv.at(1) = 1;
  for (int i = 2; i < MAX; i++) {
    fac.at(i) = (fac.at(i - 1) * i) % MOD;
    inv.at(i) = MOD - (inv.at(MOD % i) * (MOD / i)) % MOD;
    finv.at(i) = (finv.at(i - 1) * inv.at(i)) % MOD;
  }
}

ll MDiv(ll x, ll y) {
  if (1 != inv.at(1))
    DivInit();
  return (x * inv.at(y)) % MOD;
}

ll MComb(ll N, ll K) {
  if (1 != inv.at(1))
    DivInit();
  if (N < K)
    return 0;
  if ((N < 0) || (K < 0))
    return 0;
  return (fac.at(N) * ((finv.at(K) * finv.at(N - K)) % MOD)) % MOD;
}

int main() {
  ll K;
  string S;
  cin >> K >> S;
  ll N = S.size();
  ll SS = 0;
  Rep0(i, K + 1) {
    ll SSS = MComb(N + i - 1, i);
    SSS = MMul(SSS, myPow(25, i));
    SSS = MMul(SSS, myPow(26, K - i));
    SS = MPl(SS, SSS);
  }
  cout << SS << endl;
  return 0;
}


Error: 0

Fixed submission:

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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807
// (-2^63 <= long < 2^63)

#define INF (1 << 30)
// 1,073,741,824
//= 536,870,912 *2

#define MOD 1000000007
#define MAX 1000010

#define Rep0(i, n) for (auto i = 0; i < n; i++)
#define Rep1(i, n) for (auto i = 1; i <= n; i++)
#define Sort(P) sort(P.begin(), P.end())
#define Rev(P) reverse(P.begin(), P.end())

ll myPow(ll x, ll n) {
  ll r = 1;
  while (n > 0)
    if (0 == n % 2) {
      x *= x;
      x %= MOD;
      n /= 2;
    } else {
      r *= x;
      r %= MOD;
      n--;
    }
  return r;
}

ll MPl(ll x, ll y) { return (x + y) % MOD; }

ll MMi(ll x, ll y) { return (x - y + MOD) % MOD; }

ll MMul(ll x, ll y) { return (x * y) % MOD; }

// Array
vector<ll> fac(MAX, 0);
vector<ll> finv(MAX, 0);
vector<ll> inv(MAX, 0);

void DivInit() { // fac, finv, inv
  fac.at(0) = 1;
  fac.at(1) = 1;
  finv.at(0) = 1;
  finv.at(1) = 1;
  inv.at(1) = 1;
  for (int i = 2; i < MAX; i++) {
    fac.at(i) = (fac.at(i - 1) * i) % MOD;
    inv.at(i) = MOD - (inv.at(MOD % i) * (MOD / i)) % MOD;
    finv.at(i) = (finv.at(i - 1) * inv.at(i)) % MOD;
  }
}

ll MDiv(ll x, ll y) {
  if (1 != inv.at(1))
    DivInit();
  return (x * inv.at(y)) % MOD;
}

ll MComb(ll N, ll K) {
  if (1 != inv.at(1))
    DivInit();
  if (N < K)
    return 0;
  if ((N < 0) || (K < 0))
    return 0;
  return (fac.at(N) * ((finv.at(K) * finv.at(N - K)) % MOD)) % MOD;
}

int main() {
  ll K;
  string S;
  cin >> K >> S;
  ll N = S.size();
  int SS = 0;
  Rep0(i, K + 1) {
    ll SSS = MComb(N + i - 1, i);
    SSS = MMul(SSS, myPow(25, i));
    SSS = MMul(SSS, myPow(26, K - i));
    SS = MPl(SS, SSS);
  }
  cout << SS << endl;
  return 0;
}