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

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define mp make_pair
#define v vector
#define inp_push(no, v)                                                        \\
  ll no;                                                                       \\
  cin >> no;                                                                   \\
  v.push_back(no);
#define pb push_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define UN(v)                                                                  \\
  sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end())
#define N 2000006
#define mod 1000000007
#define INF INT64_MAX

//////////////////////////IMPORTANT
///FUNCTIONS/////////////////////////////////////////////

/* Guidlines berfore submitting solution
1. Check N value before submitting
2. Check all constant kind of values you are using. Might give WA. Think
3. Check mod value
*/

v<ll> fact(N);
v<ll> prime_check(1e7 + 2);
v<ll> primes;

long long powmod(long long x, long long y, long long m) {
  long long res = 1LL;
  while (y) {
    if (y & 1)
      res = (res * x) % m;
    x = (x * x) % m;
    y /= 2;
  }
  return res;
}

void init_fact() {
  fact[0] = 1;
  for (ll i = 1; i < N; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
  }
}

ll C(ll n, ll r) {
  if (n < r)
    return 0;
  ll temp = fact[n] * powmod(fact[r], mod - 2, mod) % mod;
  temp *= powmod(fact[n - r], mod - 2, mod);
  temp %= mod;
  return temp;
}

void Sieve() {
  for (ll i = 2; i <= 1e7 + 1; i++) {
    if (prime_check[i])
      continue;
    primes.pb(i);
    for (ll j = 2 * i; j <= 1e7 + 1; j += i)
      prime_check[j] = i;
  }
}
ll phi(ll n) {
  ll i, res = n;
  for (i = 2; i * i <= n; i++)
    if (n % i == 0) {
      while (n % i == 0)
        n /= i;
      res -= res / i;
    }
  if (n > 1)
    res -= res / n;
  return res;
}

/////////////////////////////////////START CODE
///HERE/////////////////////////////////////////////

ll k, n;
string s;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  init_fact();
  // Sieve();
  cin >> k >> s;
  n = s.size();
  ll ans = 0;
  for (ll i = 0; i <= k; i++) {
    ll temp = (C(n + k - i - 1, n - 1) *
               ((powmod(26, i, mod) * powmod(25, k - i, mod)) % mod));
    // cout << C(n + k - i - 1, n - 1) << " " << n + k - i - 1 << " " << n - 1;
    ans = (ans + temp) % mod;
  }
  cout << ans << "\\n";
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define mp make_pair
#define v vector
#define inp_push(no, v)                                                        \\
  ll no;                                                                       \\
  cin >> no;                                                                   \\
  v.push_back(no);
#define pb push_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define UN(v)                                                                  \\
  sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end())
#define N 1000006
#define mod 1000000007
#define INF INT64_MAX

//////////////////////////IMPORTANT
///FUNCTIONS/////////////////////////////////////////////

/* Guidlines berfore submitting solution
1. Check N value before submitting
2. Check all constant kind of values you are using. Might give WA. Think
3. Check mod value
*/

v<ll> fact(N);
v<ll> prime_check(1e7 + 2);
v<ll> primes;

long long powmod(long long x, long long y, long long m) {
  long long res = 1LL;
  while (y) {
    if (y & 1)
      res = (res * x) % m;
    x = (x * x) % m;
    y /= 2;
  }
  return res;
}

void init_fact() {
  fact[0] = 1;
  for (ll i = 1; i < N; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
  }
}

ll C(ll n, ll r) {
  if (n < r)
    return 0;
  ll temp = fact[n] * powmod(fact[r], mod - 2, mod) % mod;
  temp *= powmod(fact[n - r], mod - 2, mod);
  temp %= mod;
  return temp;
}

void Sieve() {
  for (ll i = 2; i <= 1e7 + 1; i++) {
    if (prime_check[i])
      continue;
    primes.pb(i);
    for (ll j = 2 * i; j <= 1e7 + 1; j += i)
      prime_check[j] = i;
  }
}
ll phi(ll n) {
  ll i, res = n;
  for (i = 2; i * i <= n; i++)
    if (n % i == 0) {
      while (n % i == 0)
        n /= i;
      res -= res / i;
    }
  if (n > 1)
    res -= res / n;
  return res;
}

/////////////////////////////////////START CODE
///HERE/////////////////////////////////////////////

ll k, n;
string s;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  init_fact();
  // Sieve();
  cin >> k >> s;
  n = s.size();
  ll ans = 0;
  for (ll i = 0; i <= k; i++) {
    ll temp = (C(n + k - i - 1, n - 1) *
               ((powmod(26, i, mod) * powmod(25, k - i, mod)) % mod));
    // cout << C(n + k - i - 1, n - 1) << " " << n + k - i - 1 << " " << n - 1;
    ans = (ans + temp) % mod;
  }
  cout << ans << "\\n";
}