Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#pragma region Macros
using ll = long long;
#define int ll
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
template <class T = ll> using V = vector<T>;
template <class T = ll> using VV = V<V<T>>;
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define FOR(i, l, r) for (ll i = (l); i < (r); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FOR(i, 1, n + 1)
#define RFOR(i, l, r) for (ll i = (l); i >= (r); --i)
#define RREP(i, n) RFOR(i, n - 1, 0)
#define RREPS(i, n) RFOR(i, n, 1)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define SORT(name) sort(name.begin(), name.end())
#define RSORT(name)                                                            \
  SORT(name);                                                                  \
  reverse(all(name));
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
inline void Yes(bool b = true) { cout << (b ? "Yes" : "No") << '\n'; }
inline void YES(bool b = true) { cout << (b ? "YES" : "NO") << '\n'; }
template <class T> inline void print(T x) { cout << x << '\n'; }
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
  if (a > b)
    a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
  if (a < b)
    a = b;
}

const ll LLINF = (1LL << 60);
const int INF = (1LL << 30);
const double DINF = std::numeric_limits<double>::infinity();
#pragma endregion

#if 1
#define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#define DBG(fmt, ...)
#endif

template <typename T> class NumberOfCase {
public:
  // 初期化 O(n log m) m は素数
  // n : 求めたい組み合わせの最大値
  NumberOfCase(ll n) : m_Size(n) {
    m_Fact.resize(m_Size + 1);
    m_FInv.resize(m_Size + 1);
    m_Inv.resize(m_Size + 1);
    // 0! ～ m_Size! までの階乗を保管する配列の作成 (mod m_Mod をとってある)
    m_Fact[0] = 1;
    for (int i = 1; i <= m_Size; ++i) {
      m_Fact[i] = m_Fact[i - 1] * i;
    }
    // m_Size! の逆元 1/m_Size! を二分累乗法で求める
    // フェルマーの小定理より a^-1 = a^(p-2) mod p -> (m_Size!)^-1 =
    // (m_Size!)^(p-2) mod p
    m_FInv[m_Size] = T(1) / m_Fact[m_Size];
    // 以下 1 / (N-1)! = N / N! であることを利用
    for (int i = m_Size - 1; i >= 0; --i) {
      m_FInv[i] = m_FInv[i + 1] * (i + 1);
    }
    // 逆元の作成（割り算のとき利用）
    m_Inv[0] = 1;
    for (int i = 1; i <= m_Size; ++i) {
      m_Inv[i] = m_FInv[i] * m_Fact[i - 1];
    }
  }
  // 階乗 n! の取得 O(1)
  T Factorial(ll n) const { return m_Fact[n]; }
  // n! の逆元の取得 O(1)
  T FInverse(ll n) const { return m_FInv[n]; }
  // 逆元の取得 O(1) or O(log MOD)
  T Inverse(ll n) const { return m_Inv[n]; }
  // 順列 nPr の取得 O(1)
  T Permutation(ll n, ll r) const {
    if (r < 0 || n < r) {
      return 0;
    }
    return m_Fact[n] * m_FInv[n - r];
  }
  // 組み合わせ nCr の取得 O(1)
  T Combination(ll n, ll r) const {
    if (r < 0 || n < r) {
      return 0;
    }
    return m_Fact[n] * m_FInv[r] * m_FInv[n - r];
  }
  // 重複組み合わせ nHr の取得 O(1)
  T Homogen(ll n, ll r) const {
    if (n < 0 || r < 0) {
      return 0;
    }
    return (r == 0) ? 1 : Combination(r + n - 1, r);
  }

private:
  const ll m_Size; // 導出する範囲 (10^5 くらいまでにして欲しい)
  vector<T> m_Fact; // 階乗
  vector<T> m_FInv; // 階乗の逆元
  vector<T> m_Inv;  // 逆元
};

const int MOD = 1000000007;

// 自動で余りを取ってくれる整数型
// 割り算や負の数による初期化も可能
template <int mod> struct ModInt {
  int x;
  ModInt() : x(0) {}
  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  ModInt &operator+=(const ModInt &p) {
    if ((x += p.x) >= mod)
      x -= mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p) {
    if ((x += mod - p.x) >= mod)
      x -= mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p) {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
  ModInt operator-() const { return ModInt(-x); }
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
  bool operator==(const ModInt &p) const { return x == p.x; }
  bool operator!=(const ModInt &p) const { return x != p.x; }
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while (n > 0) {
      if (n & 1)
        ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
  friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }
  static int get_mod() { return mod; }
};
using modint = ModInt<MOD>;

const int MAX_N = 1000010;

int K;
string S;

signed main() {
  IOS;

  NumberOfCase<modint> noc(MAX_N);

  cin >> K >> S;

  modint ans(0);
  REP(i, K + 1) {
    modint n(26), m(25);
    ans += n.pow(i) * m.pow(K - i) *
           noc.Combination(S.length() + K - i - 1, S.length() - 1);
  }
  print(ans);

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

#pragma region Macros
using ll = long long;
#define int ll
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
template <class T = ll> using V = vector<T>;
template <class T = ll> using VV = V<V<T>>;
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define FOR(i, l, r) for (ll i = (l); i < (r); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FOR(i, 1, n + 1)
#define RFOR(i, l, r) for (ll i = (l); i >= (r); --i)
#define RREP(i, n) RFOR(i, n - 1, 0)
#define RREPS(i, n) RFOR(i, n, 1)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define SORT(name) sort(name.begin(), name.end())
#define RSORT(name)                                                            \
  SORT(name);                                                                  \
  reverse(all(name));
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
inline void Yes(bool b = true) { cout << (b ? "Yes" : "No") << '\n'; }
inline void YES(bool b = true) { cout << (b ? "YES" : "NO") << '\n'; }
template <class T> inline void print(T x) { cout << x << '\n'; }
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
  if (a > b)
    a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
  if (a < b)
    a = b;
}

const ll LLINF = (1LL << 60);
const int INF = (1LL << 30);
const double DINF = std::numeric_limits<double>::infinity();
#pragma endregion

#if 1
#define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#define DBG(fmt, ...)
#endif

template <typename T> class NumberOfCase {
public:
  // 初期化 O(n log m) m は素数
  // n : 求めたい組み合わせの最大値
  NumberOfCase(ll n) : m_Size(n) {
    m_Fact.resize(m_Size + 1);
    m_FInv.resize(m_Size + 1);
    m_Inv.resize(m_Size + 1);
    // 0! ～ m_Size! までの階乗を保管する配列の作成 (mod m_Mod をとってある)
    m_Fact[0] = 1;
    for (int i = 1; i <= m_Size; ++i) {
      m_Fact[i] = m_Fact[i - 1] * i;
    }
    // m_Size! の逆元 1/m_Size! を二分累乗法で求める
    // フェルマーの小定理より a^-1 = a^(p-2) mod p -> (m_Size!)^-1 =
    // (m_Size!)^(p-2) mod p
    m_FInv[m_Size] = T(1) / m_Fact[m_Size];
    // 以下 1 / (N-1)! = N / N! であることを利用
    for (int i = m_Size - 1; i >= 0; --i) {
      m_FInv[i] = m_FInv[i + 1] * (i + 1);
    }
    // 逆元の作成（割り算のとき利用）
    m_Inv[0] = 1;
    for (int i = 1; i <= m_Size; ++i) {
      m_Inv[i] = m_FInv[i] * m_Fact[i - 1];
    }
  }
  // 階乗 n! の取得 O(1)
  T Factorial(ll n) const { return m_Fact[n]; }
  // n! の逆元の取得 O(1)
  T FInverse(ll n) const { return m_FInv[n]; }
  // 逆元の取得 O(1) or O(log MOD)
  T Inverse(ll n) const { return m_Inv[n]; }
  // 順列 nPr の取得 O(1)
  T Permutation(ll n, ll r) const {
    if (r < 0 || n < r) {
      return 0;
    }
    return m_Fact[n] * m_FInv[n - r];
  }
  // 組み合わせ nCr の取得 O(1)
  T Combination(ll n, ll r) const {
    if (r < 0 || n < r) {
      return 0;
    }
    return m_Fact[n] * m_FInv[r] * m_FInv[n - r];
  }
  // 重複組み合わせ nHr の取得 O(1)
  T Homogen(ll n, ll r) const {
    if (n < 0 || r < 0) {
      return 0;
    }
    return (r == 0) ? 1 : Combination(r + n - 1, r);
  }

private:
  const ll m_Size; // 導出する範囲 (10^5 くらいまでにして欲しい)
  vector<T> m_Fact; // 階乗
  vector<T> m_FInv; // 階乗の逆元
  vector<T> m_Inv;  // 逆元
};

const int MOD = 1000000007;

// 自動で余りを取ってくれる整数型
// 割り算や負の数による初期化も可能
template <int mod> struct ModInt {
  int x;
  ModInt() : x(0) {}
  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  ModInt &operator+=(const ModInt &p) {
    if ((x += p.x) >= mod)
      x -= mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p) {
    if ((x += mod - p.x) >= mod)
      x -= mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p) {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
  ModInt operator-() const { return ModInt(-x); }
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
  bool operator==(const ModInt &p) const { return x == p.x; }
  bool operator!=(const ModInt &p) const { return x != p.x; }
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while (n > 0) {
      if (n & 1)
        ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
  friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }
  static int get_mod() { return mod; }
};
using modint = ModInt<MOD>;

const int MAX_N = 2000010;

int K;
string S;

signed main() {
  IOS;

  NumberOfCase<modint> noc(MAX_N);

  cin >> K >> S;

  modint ans(0);
  REP(i, K + 1) {
    modint n(26), m(25);
    ans += n.pow(i) * m.pow(K - i) *
           noc.Combination(S.length() + K - i - 1, S.length() - 1);
  }
  print(ans);

  return 0;
}