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

#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long LL;
#define MS(A) memset(A, 0, sizeof(A))
#define MSV(A, a) memset(A, a, sizeof(A))
#define MP make_pair
#define PB push_back
#define getcx getchar_unlocked
#define INF (int(1e9))
#define INFL (LL(1e18))
#define EPS 1e-12
#define chkbit(s, b) (s & (1 << b))
#define setbit(s, b) (s |= (1 << b))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a, b)                                                             \\
  cerr << endl << #a << " : " << a << "\\t" << #b << " : " << b << endl
#define chk3(a, b, c)                                                          \\
  cerr << endl                                                                 \\
       << #a << " : " << a << "\\t" << #b << " : " << b << "\\t" << #c << " : "  \\
       << c << endl
#define chk4(a, b, c, d)                                                       \\
  cerr << endl                                                                 \\
       << #a << " : " << a << "\\t" << #b << " : " << b << "\\t" << #c << " : "  \\
       << c << "\\t" << #d << " : " << d << endl
#define rep(i, a, n) for (i = a; i < n; i++)
#define rev(i, a, n) for (i = a; i >= n; i--)
#define rep_itr(itr, c) for (itr = (c).begin(); itr != (c).end(); itr++)
#define MOD 1000000007
#define MAX 1000000

/* Factorial modulo MOD */
LL fact[2 * MAX];
char s[2 * MAX];

void factorial() {
  fact[0] = 1;
  for (int i = 1; i < 2 * MAX; i++) {
    fact[i] = (i * fact[i - 1]) % MOD;
  }
}

/* Modulo exponentiation */
LL power(LL base, LL exp, LL ans) {
  if (!exp)
    return ans % MOD;
  if (exp & 1)
    ans = (ans * base) % MOD;
  return power((base * base) % MOD, exp >> 1, ans);
}

/* nCr modulo MOD */
LL nCr(LL n, LL r) {
  if (n < r)
    return 0;
  LL numerator = fact[n];
  LL denominator = (fact[n - r] * fact[r]) % MOD;
  return (numerator * power(denominator, MOD - 2, 1)) % MOD;
}

int main() {

  int k, n, i;
  LL ans = 0;
  factorial();

  cin >> k;
  cin >> s;

  n = strlen(s);
  for (i = 0; i <= k; i++) {

    LL lp = power(26, i, 1);

    LL rp = (power(25, k - i, 1) * nCr(k - i + n - 1, n - 1)) % MOD;
    ans = (ans + (lp * rp) % MOD) % MOD;
  }

  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long LL;
#define MS(A) memset(A, 0, sizeof(A))
#define MSV(A, a) memset(A, a, sizeof(A))
#define MP make_pair
#define PB push_back
#define getcx getchar_unlocked
#define INF (int(1e9))
#define INFL (LL(1e18))
#define EPS 1e-12
#define chkbit(s, b) (s & (1 << b))
#define setbit(s, b) (s |= (1 << b))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a, b)                                                             \\
  cerr << endl << #a << " : " << a << "\\t" << #b << " : " << b << endl
#define chk3(a, b, c)                                                          \\
  cerr << endl                                                                 \\
       << #a << " : " << a << "\\t" << #b << " : " << b << "\\t" << #c << " : "  \\
       << c << endl
#define chk4(a, b, c, d)                                                       \\
  cerr << endl                                                                 \\
       << #a << " : " << a << "\\t" << #b << " : " << b << "\\t" << #c << " : "  \\
       << c << "\\t" << #d << " : " << d << endl
#define rep(i, a, n) for (i = a; i < n; i++)
#define rev(i, a, n) for (i = a; i >= n; i--)
#define rep_itr(itr, c) for (itr = (c).begin(); itr != (c).end(); itr++)
#define MOD 1000000007
#define MAX 1000000

/* Factorial modulo MOD */
LL fact[MAX + 1];
char s[1000001];

void factorial() {
  fact[0] = 1;
  for (int i = 1; i < MAX; i++) {
    fact[i] = (i * fact[i - 1]) % MOD;
  }
}

/* Modulo exponentiation */
LL power(LL base, LL exp, LL ans) {
  if (!exp)
    return ans % MOD;
  if (exp & 1)
    ans = (ans * base) % MOD;
  return power((base * base) % MOD, exp >> 1, ans);
}

/* nCr modulo MOD */
LL nCr(LL n, LL r) {
  if (n < r)
    return 0;
  LL numerator = fact[n];
  LL denominator = (fact[n - r] * fact[r]) % MOD;
  return (numerator * power(denominator, MOD - 2, 1)) % MOD;
}

int main() {

  int k, n, i;
  LL ans = 0;
  factorial();

  cin >> k;
  cin >> s;

  n = strlen(s);
  for (i = 0; i <= k; i++) {

    LL lp = power(26, i, 1);

    LL rp = (power(25, k - i, 1) * nCr(k - i + n - 1, n - 1)) % MOD;
    ans = (ans + (lp * rp) % MOD) % MOD;
  }

  cout << ans << endl;
  return 0;
}