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

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll, ll>
#define vvll vector<vector<ll>>
#define pb push_back
#define sz(v) (ll)(v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(), (v).end()
#define rep(i, a, b) for (ll i = a; i < b; ++i)
#define tel(a)                                                                 \\
  { cout << a << "\\n"; }
#define tell(a, b)                                                             \\
  { cout << a << " | " << b << "\\n"; }
#define telll(a, b, c)                                                         \\
  { cout << a << " | " << b << " | " << c << "\\n"; }
#define teln(v, n)                                                             \\
  {                                                                            \\
    cout << "v- ";                                                             \\
    rep(o, 0, n) cout << v[o] << " ";                                          \\
    cout << "\\n";                                                              \\
  }
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
using namespace std;
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

#define M 4000010
ll ex(ll a, ll b) {
  ll ans = 1;
  while (b) {
    if (b & 1)
      ans = (ans * a) % md;
    a = (a * a) % md, b /= 2;
  }
  return ans;
}
inline ll add(ll a, ll b) { return (a + b) % md; }
inline ll mul(ll a, ll b) { return (a * b) % md; }
ll f[M], iv[M];
ll C(ll n, ll r) { return mul(f[n], mul(iv[r], iv[n - r])); }
void prep_fac() {
  f[0] = 1;
  rep(i, 1, M) f[i] = mul(i, f[i - 1]);
  iv[M - 1] = ex(f[M - 1], md - 2);
  for (ll i = M - 2; i >= 0; --i)
    iv[i] = mul(i + 1, iv[i + 1]);
}
int main() {
  IOS;

  prep_fac();
  ll k;
  cin >> k;
  string s;
  cin >> s;
  ll n;
  n = sz(s);
  ll ans = 0, x = 1;
  ll a[k + 1];
  rep(i, 0, k + 1) {
    a[i] = mul(C(n + i - 1, i), x);
    x = mul(x, 25);
  }
  x = 1;
  for (ll i = k; i >= 0; --i)
    a[i] = mul(a[i], x), x = mul(x, 26), ans = add(ans, a[i]);
  cout << ans << "\\n";

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll, ll>
#define vvll vector<vector<ll>>
#define pb push_back
#define sz(v) (ll)(v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(), (v).end()
#define rep(i, a, b) for (ll i = a; i < b; ++i)
#define tel(a)                                                                 \\
  { cout << a << "\\n"; }
#define tell(a, b)                                                             \\
  { cout << a << " | " << b << "\\n"; }
#define telll(a, b, c)                                                         \\
  { cout << a << " | " << b << " | " << c << "\\n"; }
#define teln(v, n)                                                             \\
  {                                                                            \\
    cout << "v- ";                                                             \\
    rep(o, 0, n) cout << v[o] << " ";                                          \\
    cout << "\\n";                                                              \\
  }
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
using namespace std;
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

#define M 500010
ll ex(ll a, ll b) {
  ll ans = 1;
  while (b) {
    if (b & 1)
      ans = (ans * a) % md;
    a = (a * a) % md, b /= 2;
  }
  return ans;
}
inline ll add(ll a, ll b) { return (a + b) % md; }
inline ll mul(ll a, ll b) { return (a * b) % md; }
ll f[M], iv[M];
ll C(ll n, ll r) { return mul(f[n], mul(iv[r], iv[n - r])); }
void prep_fac() {
  f[0] = 1;
  rep(i, 1, M) f[i] = mul(i, f[i - 1]);
  iv[M - 1] = ex(f[M - 1], md - 2);
  for (ll i = M - 2; i >= 0; --i)
    iv[i] = mul(i + 1, iv[i + 1]);
}
int main() {
  IOS;

  prep_fac();
  ll k;
  cin >> k;
  string s;
  cin >> s;
  ll n;
  n = sz(s);
  ll ans = 0, x = 1;
  ll a[k + 1];
  rep(i, 0, k + 1) {
    a[i] = mul(C(n + i - 1, i), x);
    x = mul(x, 25);
  }
  x = 1;
  for (ll i = k; i >= 0; --i)
    a[i] = mul(a[i], x), x = mul(x, 26), ans = add(ans, a[i]);
  cout << ans << "\\n";

  return 0;
}