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

#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL << (n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;
typedef long long ll;

long long powMod(long long x, long long n, long long m) {
  long long res = 1;
  while (n > 0) {
    if ((n & 1) == 1)
      res = res * x % MOD;
    x = x * x % MOD;
    n >>= 1;
  }
  return res;
}

/*
  階乗計算（MODで割った余りで返す）
*/

class Factorial {
private:
  vector<long long> fac;

public:
  Factorial();
  Factorial(long long n_max);
  void initialization(long long n_max);
  long long getFactorial(long long n);
};

Factorial::Factorial() {}
Factorial::Factorial(long long n_max) {
  fac.clear();
  fac.push_back(1);
  fac.push_back(1);
  for (long long i = 2; i <= n_max; i++) {
    fac.push_back(fac[i - 1] * i % MOD);
  }
}
void Factorial::initialization(long long n_max) {
  fac.clear();
  fac.push_back(1);
  fac.push_back(1);
  for (long long i = 2; i <= n_max; i++) {
    fac.push_back(fac[i - 1] * i % MOD);
  }
}
long long Factorial::getFactorial(long long n) { return fac[n]; }

/*
  MOD計算
*/
// 割り算のための逆元を求める（mod m での a の逆元）
long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u % m;
}

/*
    順列と組み合わせ (P, C, H)
*/

class PCH {
private:
  Factorial fact;

public:
  PCH(long long n_max);
  long long P(long long n, long long r);
  long long C(long long n, long long r);
  long long H(long long n, long long r);
};
PCH::PCH(long long n_max) { fact.initialization(n_max); }
long long PCH::P(long long n, long long r) {
  return fact.getFactorial(n) % MOD * modinv(fact.getFactorial(r), MOD) % MOD;
}

long long PCH::C(long long n, long long r) {
  return fact.getFactorial(n) % MOD * modinv(fact.getFactorial(r), MOD) % MOD *
         modinv(fact.getFactorial(n - r), MOD) % MOD;
}

long long PCH::H(long long n, long long r) { return C(n - 1 + r, r); }

int main() {

  int K;
  cin >> K;
  string S;
  cin >> S;
  int N = S.length();

  PCH pch(N + K);

  ll ans = 0;

  for (int k = N; k <= N + K; k++) {
    ll count = 1;
    count *= pch.C(k - 1, N - 1);
    count *= powMod(25, k - N, MOD);
    count %= MOD;
    count *= powMod(26, N + K - k, MOD);
    count %= MOD;
    ans += count;
    ans %= MOD;
  }

  cout << ans << endl;

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL << (n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;
typedef long long ll;

long long powMod(long long x, long long n, long long m) {
  long long res = 1;
  while (n > 0) {
    if ((n & 1) == 1)
      res = res * x % MOD;
    x = x * x % MOD;
    n >>= 1;
  }
  return res;
}

/*
  階乗計算（MODで割った余りで返す）
*/

class Factorial {
private:
  vector<long long> fac;

public:
  Factorial();
  Factorial(long long n_max);
  void initialization(long long n_max);
  long long getFactorial(long long n);
};

Factorial::Factorial() {}
Factorial::Factorial(long long n_max) {
  fac.clear();
  fac.push_back(1);
  fac.push_back(1);
  for (long long i = 2; i <= n_max; i++) {
    fac.push_back(fac[i - 1] * i % MOD);
  }
}
void Factorial::initialization(long long n_max) {
  fac.clear();
  fac.push_back(1);
  fac.push_back(1);
  for (long long i = 2; i <= n_max; i++) {
    fac.push_back(fac[i - 1] * i % MOD);
  }
}
long long Factorial::getFactorial(long long n) { return fac[n]; }

/*
  MOD計算
*/
// 割り算のための逆元を求める（mod m での a の逆元）
long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u % m;
}

/*
    順列と組み合わせ (P, C, H)
*/

class PCH {
private:
  Factorial fact;

public:
  PCH(long long n_max);
  long long P(long long n, long long r);
  long long C(long long n, long long r);
  long long H(long long n, long long r);
};
PCH::PCH(long long n_max) { fact.initialization(n_max); }
long long PCH::P(long long n, long long r) {
  return fact.getFactorial(n) % MOD * modinv(fact.getFactorial(r), MOD) % MOD;
}

long long PCH::C(long long n, long long r) {
  return fact.getFactorial(n) % MOD * modinv(fact.getFactorial(r), MOD) % MOD *
         modinv(fact.getFactorial(n - r), MOD) % MOD;
}

long long PCH::H(long long n, long long r) { return C(n - 1 + r, r); }

int main() {

  int K;
  cin >> K;
  string S;
  cin >> S;
  int N = S.length();
  PCH pch(N + 1);

  ll p = powMod(26, K, MOD);
  cout << pch.H(N + 1, K) * p % MOD << endl;

  return 0;
}