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

// According to all known laws of aviation, there is no way that a bee should be
// able to fly. Its wings are too small to get its fat little body off the
// ground. The bee, of course, flies anyway. Because bees don't care what humans
// think is impossible.
#include <bits/stdc++.h>
#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define mod 1000000007
using namespace std;
using bigint = long long int;
using vi = vector<int>;
using vll = vector<long long int>;
bigint fact[2000001];
bigint inv[2000001];
bigint fact_inv[2000001];
void factorial() {
  fact[0] = fact[1] = 1;
  for (bigint i = 2; i <= 2000000; i++) {
    fact[i] = i * fact[i - 1];
    fact[i] %= mod;
  }
}
void inverse() {
  inv[1] = 1;
  for (bigint i = 2; i <= 2000000; i++) {
    inv[i] = (mod - ((mod / i) * inv[mod % i]) % mod) % mod;
  }
  fact_inv[0] = fact_inv[1] = 1;
  for (int i = 2; i <= 2000000; i++)
    fact_inv[i] = (inv[i] * fact_inv[i - 1]) % mod;
}
bigint nCr(bigint N, bigint R) {
  if (N < 0 || R < 0 || N < R)
    return 0;
  bigint ans = ((fact_inv[R] * fact_inv[N - R]) % mod * fact[N]) % mod;
  return ans;
}
bigint power(bigint A, bigint B, bigint md = mod) {
  bigint ans = 1;
  while (B > 0) {
    if (B & 1)
      (ans *= A) %= md;
    (A *= A) %= md;
    B >>= 1;
  }
  return ans;
}

int main() {
  factorial();
  inverse();
  bigint K;
  cin >> K;
  string str;
  cin >> str;
  bigint N = str.length();
  bigint ans = 0;
  for (bigint i = 0; i <= K; i++) {
    bigint temp = (power(26, i) * power(25, K - i)) % mod;
    temp = (temp * nCr(N + K - i - 1, N - 1)) % mod;
    ans = (ans + temp) % mod;
  }
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

// According to all known laws of aviation, there is no way that a bee should be
// able to fly. Its wings are too small to get its fat little body off the
// ground. The bee, of course, flies anyway. Because bees don't care what humans
// think is impossible.
#include <bits/stdc++.h>
#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define mod 1000000007
using namespace std;
using bigint = long long int;
using vi = vector<int>;
using vll = vector<long long int>;
bigint fact[1000001];
bigint inv[1000001];
void factorial() {
  fact[0] = fact[1] = 1;
  for (int i = 2; i < 1000001; i++) {
    fact[i] = i * fact[i - 1];
    fact[i] %= mod;
  }
  inv[1] = 1;
  for (int i = 2; i < 1000001; i++) {
    inv[i] = (mod - ((mod / i) * inv[mod % i]) % mod) % mod;
  }
}
bigint power(bigint A, bigint B) {
  bigint ans = 1;
  while (B > 0) {
    if (B & 1)
      (ans *= A) %= mod;
    (A *= A) %= mod;
    B >>= 1;
  }
  return ans;
}
bigint nCr(bigint N, bigint R) {
  bigint ans = fact[N];
  (ans *= inv[fact[R]]) %= mod;
  (ans *= inv[fact[N - R]]) %= mod;
  return ans;
}
int main() {
  FAST_IO;
  factorial();
  int K;
  cin >> K;
  string str;
  cin >> str;
  int N = (int)str.length();
  bigint ans = 0;
  for (bigint i = 0; i <= K; i++) {
    bigint temp = (power(26, i) * power(25, K - i)) % mod;
    temp = (temp * nCr(N + K - i - 1, N - 1)) % mod;
    ans = (ans + temp) % mod;
  }
  cout << ans << endl;
  return 0;
}