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

#pragma optimize("O3")
#pragma GCC target("sse4")

#include <bits/stdc++.h>
// #include<iomanip>
using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pii;
#define f(i, a, b) for (ll i = a; i < b; i++)
#define fo(i, a, b) for (ll i = a; i <= b; i += 1)
#define rf(i, a, b) for (ll i = a; i >= b; i--)
#define vll vector<ll>
#define sz(a) ll(a.size())
#define all(v) v.begin(), v.end()
#define pb push_back
#define pf push_front
#define MAXN 100010
#define N 100010
#define MOD 1000000007
#define mod 998244353
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define nl '\\n'
#define MS(x, y) fill_n(*x, sizeof x / sizeof **x, y);
#define mem(x, y) memset(x, y, sizeof(x));
#define INF 1000000000000000000
#define IO                                                                     \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

template <int D, typename T> struct Vec : public vector<Vec<D - 1, T>> {
  static_assert(D >= 1, "Vector dimension must be greater than zero!");
  template <typename... Args>
  Vec(int n = 0, Args... args)
      : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {}
};
template <typename T> struct Vec<1, T> : public vector<T> {
  Vec(int n = 0, const T &val = T()) : vector<T>(n, val) {}
};

ll modpower(ll x, ll y, ll p) {
  ll res = 1; // Initialize result
  x = x % p;
  if (y == 0)
    return 1;
  if (x == 0)
    return 0;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;      // y = y/2
    x = (x * x) % p; // Change x to x^2
  }
  return res;
}
ll power(ll x, ll y) {
  ll res = 1; // Initialize result
  x = x;
  if (y == 0)
    return 1;
  if (x == 0)
    return 0;
  while (y > 0) {
    if (y & 1)
      res = (res * x);
    y = y >> 1;  // y = y/2
    x = (x * x); // Change x to x^2
  }
  return res;
}
// int gcd(int a, int b) { if (a == 0)return b;return gcd(b % a, a);}

ll modinv(ll a, ll p) { return modpower(a, p - 2, p); }

const int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1},
          dy[8] = {0, 1, 0, -1, -1, 1, -1, 1};

long long safe_sqrt(long long n) {
  long long res = sqrt((long double)n);
  if (res * res == n)
    return res;
  const long double eps = 1e-8;
  if ((long double)(res + 1) * (res + 1) < n + eps)
    return res + 1;
  if ((long double)res * res + eps > n)
    return res - 1;
  return res;
}
// (a+b-1)/b for ceil

const int miMOD = 1000000007;
const int MX = 2000001;
struct mi {
  ll v;
  explicit operator ll() const { return v; }
  mi() { v = 0; }
  mi(ll _v) {
    v = (-miMOD < _v && _v < miMOD) ? _v : _v % miMOD;
    if (v < 0)
      v += miMOD;
  }
  friend bool operator==(const mi &a, const mi &b) { return a.v == b.v; }
  friend bool operator!=(const mi &a, const mi &b) { return !(a == b); }
  friend bool operator<(const mi &a, const mi &b) { return a.v < b.v; }

  mi &operator+=(const mi &m) {
    if ((v += m.v) >= miMOD)
      v -= miMOD;
    return *this;
  }
  mi &operator-=(const mi &m) {
    if ((v -= m.v) < 0)
      v += miMOD;
    return *this;
  }
  mi &operator*=(const mi &m) {
    v = v * m.v % miMOD;
    return *this;
  }
  mi &operator/=(const mi &m) { return (*this) *= inv(m); }
  friend mi pow(mi a, ll p) {
    mi ans = 1;
    assert(p >= 0);
    for (; p; p /= 2, a *= a)
      if (p & 1)
        ans *= a;
    return ans;
  }
  friend mi inv(const mi &a) {
    assert(a.v != 0);
    return pow(a, miMOD - 2);
  }

  mi operator-() const { return mi(-v); }
  mi &operator++() { return *this += 1; }
  mi &operator--() { return *this -= 1; }
  mi operator++(int) {
    mi temp;
    temp.v = v++;
    return temp;
  }
  mi operator--(int) {
    mi temp;
    temp.v = v--;
    return temp;
  }
  friend mi operator+(mi a, const mi &b) { return a += b; }
  friend mi operator-(mi a, const mi &b) { return a -= b; }
  friend mi operator*(mi a, const mi &b) { return a *= b; }
  friend mi operator/(mi a, const mi &b) { return a /= b; }
  friend ostream &operator<<(ostream &os, const mi &m) {
    os << m.v;
    return os;
  }
  friend istream &operator>>(istream &is, mi &m) {
    ll x;
    is >> x;
    m.v = x;
    return is;
  }
};
typedef vector<mi> vmi;
typedef pair<mi, mi> pmi;
typedef vector<pmi> vpmi;
mi facs[MX];
mi facInvs[MX];

mi choose(mi _a, mi _b) {
  ll a = (ll)_a, b = (ll)_b;
  if (b > a)
    return 0;
  if (a < 0)
    return 0;
  if (b < 0)
    return 0;
  mi cur = facs[a];
  cur = cur * facInvs[b];
  cur = cur * facInvs[a - b];
  return cur;
}

void initFacs() {
  facs[0] = 1;
  facInvs[0] = 1;
  fo(i, 1, MX - 1) {
    facs[i] = (facs[i - 1] * i);
    facInvs[i] = inv(facs[i]);
  }
}
void solve() {
  initFacs();
  ll k;
  cin >> k;
  string s;
  cin >> s;
  ll n = s.size();
  mi ans = 0;
  fo(x, 0, n + k) {
    if (k - x >= ll(0) and n + k - x - ll(1) >= ll(0)) {
      ans += mi(modpower(26, x, MOD) * modpower(25, k - x, MOD)) *
             choose(n + k - x - 1, n - 1);
    }
  }
  cout << ans << nl;
  return;
}
int main() {
  IO;
  // #ifndef ONLINE_JUDGE
  // freopen("input.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  // #endif
  int T = 1;
  // cin >> T;
  f(c, 0, T) { solve(); }
  return 0;
} // multiset m make_pair make_tuple  tuple<int,int,int> continue resize insert
  // count size else true isValid second first false erase double priority_queue
// cout<<setprecision(12); push_back pop_back pop_front push_front  lower_bound
// upper_bound  reverse

Error: 0

Fixed submission:

#pragma optimize("O3")
#pragma GCC target("sse4")

#include <bits/stdc++.h>
// #include<iomanip>
using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pii;
#define f(i, a, b) for (ll i = a; i < b; i++)
#define fo(i, a, b) for (ll i = a; i <= b; i += 1)
#define rf(i, a, b) for (ll i = a; i >= b; i--)
#define vll vector<ll>
#define sz(a) ll(a.size())
#define all(v) v.begin(), v.end()
#define pb push_back
#define pf push_front
#define MAXN 100010
#define N 100010
#define MOD 1000000007
#define mod 998244353
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define nl '\\n'
#define MS(x, y) fill_n(*x, sizeof x / sizeof **x, y);
#define mem(x, y) memset(x, y, sizeof(x));
#define INF 1000000000000000000
#define IO                                                                     \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

template <int D, typename T> struct Vec : public vector<Vec<D - 1, T>> {
  static_assert(D >= 1, "Vector dimension must be greater than zero!");
  template <typename... Args>
  Vec(int n = 0, Args... args)
      : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {}
};
template <typename T> struct Vec<1, T> : public vector<T> {
  Vec(int n = 0, const T &val = T()) : vector<T>(n, val) {}
};

ll modpower(ll x, ll y, ll p) {
  ll res = 1; // Initialize result
  x = x % p;
  if (y == 0)
    return 1;
  if (x == 0)
    return 0;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;      // y = y/2
    x = (x * x) % p; // Change x to x^2
  }
  return res;
}
ll power(ll x, ll y) {
  ll res = 1; // Initialize result
  x = x;
  if (y == 0)
    return 1;
  if (x == 0)
    return 0;
  while (y > 0) {
    if (y & 1)
      res = (res * x);
    y = y >> 1;  // y = y/2
    x = (x * x); // Change x to x^2
  }
  return res;
}
// int gcd(int a, int b) { if (a == 0)return b;return gcd(b % a, a);}

ll modinv(ll a, ll p) { return modpower(a, p - 2, p); }

const int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1},
          dy[8] = {0, 1, 0, -1, -1, 1, -1, 1};

long long safe_sqrt(long long n) {
  long long res = sqrt((long double)n);
  if (res * res == n)
    return res;
  const long double eps = 1e-8;
  if ((long double)(res + 1) * (res + 1) < n + eps)
    return res + 1;
  if ((long double)res * res + eps > n)
    return res - 1;
  return res;
}
// (a+b-1)/b for ceil

const int miMOD = 1000000007;
const int MX = 1000001;
struct mi {
  ll v;
  explicit operator ll() const { return v; }
  mi() { v = 0; }
  mi(ll _v) {
    v = (-miMOD < _v && _v < miMOD) ? _v : _v % miMOD;
    if (v < 0)
      v += miMOD;
  }
  friend bool operator==(const mi &a, const mi &b) { return a.v == b.v; }
  friend bool operator!=(const mi &a, const mi &b) { return !(a == b); }
  friend bool operator<(const mi &a, const mi &b) { return a.v < b.v; }

  mi &operator+=(const mi &m) {
    if ((v += m.v) >= miMOD)
      v -= miMOD;
    return *this;
  }
  mi &operator-=(const mi &m) {
    if ((v -= m.v) < 0)
      v += miMOD;
    return *this;
  }
  mi &operator*=(const mi &m) {
    v = v * m.v % miMOD;
    return *this;
  }
  mi &operator/=(const mi &m) { return (*this) *= inv(m); }
  friend mi pow(mi a, ll p) {
    mi ans = 1;
    assert(p >= 0);
    for (; p; p /= 2, a *= a)
      if (p & 1)
        ans *= a;
    return ans;
  }
  friend mi inv(const mi &a) {
    assert(a.v != 0);
    return pow(a, miMOD - 2);
  }

  mi operator-() const { return mi(-v); }
  mi &operator++() { return *this += 1; }
  mi &operator--() { return *this -= 1; }
  mi operator++(int) {
    mi temp;
    temp.v = v++;
    return temp;
  }
  mi operator--(int) {
    mi temp;
    temp.v = v--;
    return temp;
  }
  friend mi operator+(mi a, const mi &b) { return a += b; }
  friend mi operator-(mi a, const mi &b) { return a -= b; }
  friend mi operator*(mi a, const mi &b) { return a *= b; }
  friend mi operator/(mi a, const mi &b) { return a /= b; }
  friend ostream &operator<<(ostream &os, const mi &m) {
    os << m.v;
    return os;
  }
  friend istream &operator>>(istream &is, mi &m) {
    ll x;
    is >> x;
    m.v = x;
    return is;
  }
};
typedef vector<mi> vmi;
typedef pair<mi, mi> pmi;
typedef vector<pmi> vpmi;
mi facs[MX];
mi facInvs[MX];

mi choose(mi _a, mi _b) {
  ll a = (ll)_a, b = (ll)_b;
  if (b > a)
    return 0;
  if (a < 0)
    return 0;
  if (b < 0)
    return 0;
  mi cur = facs[a];
  cur = cur * facInvs[b];
  cur = cur * facInvs[a - b];
  return cur;
}

void initFacs() {
  facs[0] = 1;
  facInvs[0] = 1;
  fo(i, 1, MX - 1) {
    facs[i] = (facs[i - 1] * i);
    facInvs[i] = inv(facs[i]);
  }
}
void solve() {
  initFacs();
  ll k;
  cin >> k;
  string s;
  cin >> s;
  ll n = s.size();
  mi ans = 0;
  fo(x, 0, n + k) {
    if (k - x >= ll(0) and n + k - x - ll(1) >= ll(0)) {
      ans += mi(modpower(26, x, MOD) * modpower(25, k - x, MOD)) *
             choose(n + k - x - 1, n - 1);
    }
  }
  cout << ans << nl;
  return;
}
int main() {
  IO;
  // #ifndef ONLINE_JUDGE
  // freopen("input.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  // #endif
  int T = 1;
  // cin >> T;
  f(c, 0, T) { solve(); }
  return 0;
} // multiset m make_pair make_tuple  tuple<int,int,int> continue resize insert
  // count size else true isValid second first false erase double priority_queue
// cout<<setprecision(12); push_back pop_back pop_front push_front  lower_bound
// upper_bound  reverse