prithivMLmods/Coder-Stat huggingface dataset:
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;
const int MAX = 1100000;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint log_mul(lint base, lint bit) {
  lint res = 0;

  while (bit) {
    if (bit & 1)
      res = (res + base) % MOD;
    base = (base + base) % MOD;
    bit >>= 1;
  }

  return res;
}

long long modpow(long long a, long long n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return res;
}

int main() {
  lint k;
  cin >> k;
  string s;
  cin >> s;
  int n = s.size();

  COMinit();

  lint res = 0;

  for (int x = 0; x <= k; x++) {
    lint t;

    t = COM(n - 1 + k - x, k - x);
    t *= modpow(25, k - x);
    t %= MOD;
    t *= modpow(26, x);
    t %= MOD;

    res += t;
    res %= MOD;
  }

  cout << res << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;
const int MAX = 2100000;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint log_mul(lint base, lint bit) {
  lint res = 0;

  while (bit) {
    if (bit & 1)
      res = (res + base) % MOD;
    base = (base + base) % MOD;
    bit >>= 1;
  }

  return res;
}

long long modpow(long long a, long long n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return res;
}

int main() {
  lint k;
  cin >> k;
  string s;
  cin >> s;
  int n = s.size();

  COMinit();

  lint res = 0;

  for (int x = 0; x <= k; x++) {
    lint t;

    t = COM(n - 1 + k - x, k - x);
    t *= modpow(25, k - x);
    t %= MOD;
    t *= modpow(26, x);
    t %= MOD;

    res += t;
    res %= MOD;
  }

  cout << res << endl;
  return 0;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 2e5 + 555;
const int MOD = 1e9 + 7;
ll xpow(ll a, ll b) {
  ll ret = 1;
  a %= MOD;
  assert(b >= 0);
  while (b) {
    if (b & 1)
      ret = ret * a % MOD;
    a = a * a % MOD;
    b >>= 1;
  }
  return ret;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.precision(10);
  cout << fixed;
  static ll inv[maxn + 555], invp[maxn + 555], p[maxn + 555];
  inv[1] = 1;
  for (int i = 2; i <= maxn; i++)
    inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
  p[0] = 1;
  for (int i = 1; i <= maxn; i++)
    p[i] = p[i - 1] * i % MOD;
  invp[0] = 1;
  for (int i = 1; i <= maxn; i++)
    invp[i] = invp[i - 1] * inv[i] % MOD;
  auto C = [&](int a, int b) -> ll {
    if (a < b)
      return 0;
    else
      return p[a] * invp[b] % MOD * invp[a - b] % MOD;
  };
  int n;
  string s;
  cin >> n >> s;
  ll ans = 0;
  int tot = n + (int)s.size();
  for (int i = (int)s.size(); i <= tot; i++) {
    // 枚举放i个a，剩下地方放b..z
    (ans += C(tot, i) * xpow(25, tot - i)) %= MOD;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 2e6 + 555;
const int MOD = 1e9 + 7;
ll xpow(ll a, ll b) {
  ll ret = 1;
  a %= MOD;
  assert(b >= 0);
  while (b) {
    if (b & 1)
      ret = ret * a % MOD;
    a = a * a % MOD;
    b >>= 1;
  }
  return ret;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.precision(10);
  cout << fixed;
  static ll inv[maxn + 555], invp[maxn + 555], p[maxn + 555];
  inv[1] = 1;
  for (int i = 2; i <= maxn; i++)
    inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
  p[0] = 1;
  for (int i = 1; i <= maxn; i++)
    p[i] = p[i - 1] * i % MOD;
  invp[0] = 1;
  for (int i = 1; i <= maxn; i++)
    invp[i] = invp[i - 1] * inv[i] % MOD;
  auto C = [&](int a, int b) -> ll {
    if (a < b)
      return 0;
    else
      return p[a] * invp[b] % MOD * invp[a - b] % MOD;
  };
  int n;
  string s;
  cin >> n >> s;
  ll ans = 0;
  int tot = n + (int)s.size();
  for (int i = (int)s.size(); i <= tot; i++) {
    // 枚举放i个a，剩下地方放b..z
    (ans += C(tot, i) * xpow(25, tot - i)) %= MOD;
  }
  cout << ans << endl;
  return 0;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MAX = 1000005;
const ll MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long pow(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % MOD;
    a = a * a % MOD;
    b >>= 1;
  }
  return res;
}

int main() {
  int k;
  string s;
  cin >> k >> s;
  int n = s.size();
  ll ans = 0;
  COMinit();
  rep(i, k + 1) {
    ll tmp = pow(25ll, (ll)i) * COM(i + n - 1, n - 1) % MOD;
    tmp *= pow(26ll, (ll)(k - i));
    tmp %= MOD;
    ans += tmp;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MAX = 2000005;
const ll MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long pow(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % MOD;
    a = a * a % MOD;
    b >>= 1;
  }
  return res;
}

int main() {
  int k;
  string s;
  cin >> k >> s;
  int n = s.size();
  ll ans = 0;
  COMinit();
  rep(i, k + 1) {
    ll tmp = pow(25ll, (ll)i) * COM(i + n - 1, n - 1) % MOD;
    tmp *= pow(26ll, (ll)(k - i));
    tmp %= MOD;
    ans += tmp;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}
Problem p02632 (C++)

Buggy submission (status: Time Limit Exceeded):
#pragma GCC optimize("O2")
#pragma GCC target("avx2")
// #include<bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int mod = 1e9 + 7;
const int IMAX = 2000010;
constexpr ll modpow(ll A, ll B) {
  ll kotae = 1;
  while (B > 0) {
    if (B & 1)
      kotae = kotae * A % mod;
    A = A * A % mod;
    B >>= 1;
  }
  return kotae;
}
class unko {
public:
  int inv[IMAX + 1];
  unko() : inv() {
    inv[0] = 1;
    inv[1] = 1;
    rep1(i, IMAX - 1) inv[i + 1] = ll(inv[i]) * i % mod;
    ll tmp = modpow(ll(inv[IMAX]) * IMAX % mod, mod - 2);
    for (int i = IMAX; i > 0; i--) {
      inv[i] = inv[i] * tmp % mod;
      tmp = tmp * i % mod;
    }
  }
} f;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int K;
  cin >> K;

  string S;
  cin >> S;

  int M = S.size();

  const ll are = 423076927;
  ll tmp = modpow(26, K);
  ll kotae = 0;
  rep(i, K + 1) {
    ce(f.inv[i]);
    tmp = tmp * f.inv[i] % mod;
    kotae += tmp;
    tmp = tmp * (M + i) % mod;
    tmp = tmp * are % mod;
  }

  co(kotae % mod);

  Would you please return 0;
}

Fixed submission:
#pragma GCC optimize("O2")
#pragma GCC target("avx2")
// #include<bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int mod = 1e9 + 7;
const int IMAX = 2000010;
constexpr ll modpow(ll A, ll B) {
  ll kotae = 1;
  while (B > 0) {
    if (B & 1)
      kotae = kotae * A % mod;
    A = A * A % mod;
    B >>= 1;
  }
  return kotae;
}
class unko {
public:
  int inv[IMAX + 1];
  unko() : inv() {
    inv[0] = 1;
    inv[1] = 1;
    rep1(i, IMAX - 1) inv[i + 1] = ll(inv[i]) * i % mod;
    ll tmp = modpow(ll(inv[IMAX]) * IMAX % mod, mod - 2);
    for (int i = IMAX; i > 0; i--) {
      inv[i] = inv[i] * tmp % mod;
      tmp = tmp * i % mod;
    }
  }
} f;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int K;
  cin >> K;

  string S;
  cin >> S;

  int M = S.size();

  const ll are = 423076927;
  ll tmp = modpow(26, K);
  ll kotae = 0;
  rep(i, K + 1) {
    tmp = tmp * f.inv[i] % mod;
    kotae += tmp;
    tmp = tmp * (M + i) % mod;
    tmp = tmp * are % mod;
  }

  co(kotae % mod);

  Would you please return 0;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
using ll = long long;
const ll MOD = 1000000007;
const ll MAX = 1100000;
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  repl(i, 2, MAX) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
ll COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 or k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll modpow(ll a, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return res;
}
int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  COMinit();

  int k;
  string s;
  cin >> k >> s;
  int n = s.size();
  ll ans = 0;
  rep(i, k + 1) {
    ll p = COM(n + k - i - 1, n - 1) * modpow(25, k - i) % MOD * modpow(26, i) %
           MOD;
    ans = (ans + p) % MOD;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
using ll = long long;
const ll MOD = 1000000007;
const ll MAX = 2100000;
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  repl(i, 2, MAX) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
ll COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 or k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll modpow(ll a, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return res;
}
int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  COMinit();

  int k;
  string s;
  cin >> k >> s;
  int n = s.size();
  ll ans = 0;
  rep(i, k + 1) {
    ll p = COM(n + k - i - 1, n - 1) * modpow(25, k - i) % MOD * modpow(26, i) %
           MOD;
    ans = (ans + p) % MOD;
  }
  cout << ans << endl;
  return 0;
}
Problem p02632 (C++)

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

#define N 1000001 // size of array
const ll MOD = 1e9 + 7;

ll fac[N], inv[N], finv[N];

void com_init() {
  fac[0] = 1;
  fac[1] = 1;
  finv[0] = 1;
  finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < N; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

ll combination(int a, int b) {
  if (a < b)
    return 0;
  if (a < 0 || b < 0)
    return 0;
  return fac[a] * (finv[b] * finv[a - b] % MOD) % MOD;
}

int main() {
  int K;
  string S;
  cin >> K >> S;
  int n = S.size();
  ll p = 1, ans = 0;
  com_init();
  for (int i = 0; i < K; i++) {
    p *= 25;
    p %= MOD;
  }
  for (int i = 0; i <= K; i++) {
    ans += combination(n + K - i - 1, n - 1) * p % MOD;
    ans %= MOD;
    p *= 26;
    p %= MOD;
    p *= inv[25];
    p %= MOD;
  }
  cout << ans << endl;
  return 0;
}

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

#define N 2000000 // size of array
const ll MOD = 1e9 + 7;

ll fac[N], inv[N], finv[N];

void com_init() {
  fac[0] = 1;
  fac[1] = 1;
  finv[0] = 1;
  finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < N; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

ll combination(int a, int b) {
  if (a < b)
    return 0;
  if (a < 0 || b < 0)
    return 0;
  return fac[a] * (finv[b] * finv[a - b] % MOD) % MOD;
}

int main() {
  int K;
  string S;
  cin >> K >> S;
  int n = S.size();
  ll p = 1, ans = 0;
  com_init();
  for (int i = 0; i < K; i++) {
    p *= 25;
    p %= MOD;
  }
  for (int i = 0; i <= K; i++) {
    ans += combination(n + K - i - 1, n - 1) * p % MOD;
    ans %= MOD;
    p *= 26;
    p %= MOD;
    p *= inv[25];
    p %= MOD;
  }
  cout << ans << endl;
  return 0;
}
Problem p02632 (C++)

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

const int64_t MOD = 1000000007;
int64_t ff[1000006];

int64_t fact(int n) {
  if (n == 0)
    return 1;
  if (n == 1)
    return 1;
  if (ff[n] != 0)
    return ff[n];
  ff[n] = (fact(n - 1) * n) % MOD;
  return ff[n] % MOD;
}

int64_t pm(int64_t a, int64_t b) {
  if (b == 0)
    return 1;
  if (b == 1)
    return a % MOD;
  int64_t v = pm(a, b / 2) % MOD;
  v = v * v % MOD;
  if (b % 2) {
    return v * a % MOD;
  }
  return v;
}

int main() {
  int64_t ans = 0;
  int N;
  int K;
  std::cin >> K;
  std::string s;
  std::cin >> s;
  N = s.size();

  int64_t st = N + K;
  for (; st >= N; --st) {
    int64_t v = pm(26, N + K - st) * pm(25, st - N) % MOD;
    v = v * fact(st - 1) % MOD;
    v = v * pm(fact(st - N), MOD - 2) % MOD;
    v = v * pm(fact(N - 1), MOD - 2) % MOD;
    ans += v;
    ans = ans % MOD;
  }

  printf("%lld\n", ans % MOD);
}


Fixed submission:
#include <bits/stdc++.h>

const int64_t MOD = 1000000007;
int64_t ff[2000006];

int64_t fact(int n) {
  if (n == 0)
    return 1;
  if (n == 1)
    return 1;
  if (ff[n] != 0)
    return ff[n];
  ff[n] = (fact(n - 1) * n) % MOD;
  return ff[n] % MOD;
}

int64_t pm(int64_t a, int64_t b) {
  if (b == 0)
    return 1;
  if (b == 1)
    return a % MOD;
  int64_t v = pm(a, b / 2) % MOD;
  v = v * v % MOD;
  if (b % 2) {
    return v * a % MOD;
  }
  return v;
}

int main() {
  int64_t ans = 0;
  int N;
  int K;
  std::cin >> K;
  std::string s;
  std::cin >> s;
  N = s.size();

  int64_t st = N + K;
  for (; st >= N; --st) {
    int64_t v = pm(26, N + K - st) * pm(25, st - N) % MOD;
    v = v * fact(st - 1) % MOD;
    v = v * pm(fact(st - N), MOD - 2) % MOD;
    v = v * pm(fact(N - 1), MOD - 2) % MOD;
    ans += v;
    ans = ans % MOD;
  }

  printf("%lld\n", ans % MOD);
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <iostream>

using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 1e6 + 10;

int fact[N], infact[N];

int qmi(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1)
      res = (ll)res * a % mod;
    a = (ll)a * a % mod;
    b >>= 1;
  }
  return res;
}

void init() {
  fact[0] = 1, infact[0] = 1;
  for (int i = 1; i < N; ++i) {
    fact[i] = (ll)fact[i - 1] * i % mod;
    infact[i] = (ll)infact[i - 1] * qmi(i, mod - 2) % mod;
  }
}

ll C(int a, int b) {
  return (ll)fact[a] * infact[b] % mod * (ll)infact[a - b] % mod;
}

int main() {
  int k;
  string s;
  cin >> k >> s;

  int len = s.length();
  int n = k + len;
  init(); // 预处理阶乘

  ll ans = 0;
  for (int i = len; i <= n; i++) {
    ll t =
        C(i - 1, len - 1) * qmi(25, i - len) % mod * (ll)qmi(26, n - i) % mod;
    ans = (ans % mod + t % mod) % mod;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>

using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 2e6 + 10;

int fact[N], infact[N];

int qmi(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1)
      res = (ll)res * a % mod;
    a = (ll)a * a % mod;
    b >>= 1;
  }
  return res;
}

void init() {
  fact[0] = 1, infact[0] = 1;
  for (int i = 1; i < N; ++i) {
    fact[i] = (ll)fact[i - 1] * i % mod;
    infact[i] = (ll)infact[i - 1] * qmi(i, mod - 2) % mod;
  }
}

ll C(int a, int b) {
  return (ll)fact[a] * infact[b] % mod * (ll)infact[a - b] % mod;
}

int main() {
  int k;
  string s;
  cin >> k >> s;

  int len = s.length();
  int n = k + len;
  init(); // 预处理阶乘

  ll ans = 0;
  for (int i = len; i <= n; i++) {
    ll t =
        C(i - 1, len - 1) * qmi(25, i - len) % mod * (ll)qmi(26, n - i) % mod;
    ans = (ans % mod + t % mod) % mod;
  }
  cout << ans << endl;
  return 0;
}
Problem p02632 (C++)

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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> P;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod = 1e9 + 7;
const ll inf = 1e16;

#define rep(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m - 1; i >= n; i--)
#define fi first
#define se second
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define eb(x) emplace_back(x)
#define all(x) x.begin(), x.end()
#define gll greater<ll>()

const ll nmax = 1000000;

ll fac[nmax], finv[nmax], inv[nmax];

void comint() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (ll i = 2; i < nmax; i++) {
    fac[i] = fac[i - 1] * i % mod;
    inv[i] = mod - inv[mod % i] * (mod / i) % mod;
    finv[i] = finv[i - 1] * inv[i] % mod;
  }
}

ll com(ll n, ll k) {
  if (n < k || n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

ll mod_pow(ll x, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

void solve() {
  ll k;
  string s;
  cin >> k >> s;
  ll n = s.size();
  comint();
  ll ans = 0;
  repr(i, n + k, n - 1) {
    ll r = n + k - 1 - i;
    ll tot = mod_pow(26, r) * mod_pow(25, k - r);
    tot %= mod;
    tot *= com(n + k - r - 1, n - 1);
    tot %= mod;
    ans += tot;
    ans %= mod;
  }

  cout << ans << endl;
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> P;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod = 1e9 + 7;
const ll inf = 1e16;

#define rep(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m - 1; i >= n; i--)
#define fi first
#define se second
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define eb(x) emplace_back(x)
#define all(x) x.begin(), x.end()
#define gll greater<ll>()

const ll nmax = 2000005;

ll fac[nmax], finv[nmax], inv[nmax];

void comint() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (ll i = 2; i < nmax; i++) {
    fac[i] = fac[i - 1] * i % mod;
    inv[i] = mod - inv[mod % i] * (mod / i) % mod;
    finv[i] = finv[i - 1] * inv[i] % mod;
  }
}

ll com(ll n, ll k) {
  if (n < k || n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

ll mod_pow(ll x, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

void solve() {
  ll k;
  string s;
  cin >> k >> s;
  ll n = s.size();
  comint();
  ll ans = 0;
  repr(i, n + k, n - 1) {
    ll r = n + k - 1 - i;
    ll tot = mod_pow(26, r) * mod_pow(25, k - r);
    tot %= mod;
    tot *= com(n + k - r - 1, n - 1);
    tot %= mod;
    ans += tot;
    ans %= mod;
  }

  cout << ans << endl;
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}
Problem p02632 (C++)

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

using namespace std;

using ll = long long;

const int N = 1e6 + 5;
const ll mod = 1e9 + 7;
int k, n;
string s;
ll f[N], inv[N];

ll pw(ll x, ll i) {
  ll b = 1;
  for (; i; i >>= 1, x = x * x % mod)
    if (i & 1)
      b = b * x % mod;
  return b;
}
ll ckn(int n, int k) { return f[n] * inv[k] % mod * inv[n - k] % mod; }

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  cin >> k >> s;
  n = s.size();
  s = ' ' + s;

  ll ans = 0;
  f[0] = 1;
  for (int i = 1; i <= n + k; ++i)
    f[i] = f[i - 1] * i % mod;
  inv[n + k] = pw(f[n + k], mod - 2);
  for (int i = n + k; i >= 1; --i)
    inv[i - 1] = inv[i] * i % mod;
  for (int i = 0; i <= k; ++i) {
    ll tmp = pw(25, k - i) * pw(26, i) % mod * ckn(k - i + n - 1, n - 1) % mod;
    ans = (ans + tmp) % mod;
  }
  cout << ans << '\n';
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const int N = 2e6 + 5;
const ll mod = 1e9 + 7;
int k, n;
string s;
ll f[N], inv[N];

ll pw(ll x, ll i) {
  ll b = 1;
  for (; i; i >>= 1, x = x * x % mod)
    if (i & 1)
      b = b * x % mod;
  return b;
}
ll ckn(int n, int k) { return f[n] * inv[k] % mod * inv[n - k] % mod; }

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  cin >> k >> s;
  n = s.size();
  s = ' ' + s;

  ll ans = 0;
  f[0] = 1;
  for (int i = 1; i <= n + k; ++i)
    f[i] = f[i - 1] * i % mod;
  inv[n + k] = pw(f[n + k], mod - 2);
  for (int i = n + k; i >= 1; --i)
    inv[i - 1] = inv[i] * i % mod;
  for (int i = 0; i <= k; ++i) {
    ll tmp = pw(25, k - i) * pw(26, i) % mod * ckn(k - i + n - 1, n - 1) % mod;
    ans = (ans + tmp) % mod;
  }
  cout << ans << '\n';
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define fir first
#define sec second
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<P, int> Q;

const int inf1 = 1e9 + 9;
const ll inf2 = 8e18 + 9;
const ll mol = 1e9 + 7;
const int maxn = 1e6 + 9;
const ll maxx = 1e5 + 9;

int n, len;
string s;
ll fac[maxn] = {1};

inline ll qpow(ll x, ll t) {
  ll res = 1;
  while (t) {
    if (t & 1)
      res = (res * x) % mol;
    t >>= 1;
    x = (x * x) % mol;
  }
  return res;
}
void init() {
  cin >> n >> s;
  len = s.size();
  for (int i = 1; i < maxn; i++)
    fac[i] = fac[i - 1] * i % mol;
}
inline ll inv(ll t) { return qpow(t, mol - 2); }
inline ll c(ll n, ll r) {
  if (!n || !r)
    return 1;
  return fac[n] * inv(fac[r]) % mol * inv(fac[n - r]) % mol;
}
int main() {
  init();
  ll ans = 0;
  for (int i = len; i <= len + n; i++) {
    ll tmp = c(i - 1, len - 1);
    tmp = (tmp * qpow(25, i - len)) % mol;
    tmp = (tmp * qpow(26, len + n - i)) % mol;
    ans = (ans + tmp) % mol;
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define fir first
#define sec second
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<P, int> Q;

const int inf1 = 1e9 + 9;
const ll inf2 = 8e18 + 9;
const ll mol = 1e9 + 7;
const int maxn = 2e6 + 9;
const ll maxx = 1e5 + 9;

int n, len;
string s;
ll fac[maxn] = {1};

inline ll qpow(ll x, ll t) {
  ll res = 1;
  while (t) {
    if (t & 1)
      res = (res * x) % mol;
    t >>= 1;
    x = (x * x) % mol;
  }
  return res;
}
void init() {
  cin >> n >> s;
  len = s.size();
  for (int i = 1; i < maxn; i++)
    fac[i] = fac[i - 1] * i % mol;
}
inline ll inv(ll t) { return qpow(t, mol - 2); }
inline ll c(ll n, ll r) {
  if (!n || !r)
    return 1;
  return fac[n] * inv(fac[r]) % mol * inv(fac[n - r]) % mol;
}
int main() {
  init();
  ll ans = 0;
  for (int i = len; i <= len + n; i++) {
    ll tmp = c(i - 1, len - 1);
    tmp = (tmp * qpow(25, i - len)) % mol;
    tmp = (tmp * qpow(26, len + n - i)) % mol;
    ans = (ans + tmp) % mol;
  }
  cout << ans << endl;
}
Problem p02632 (C++)

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

typedef long long ll;
const ll M = 1e9 + 7;

ll n, m, ans = 0, fac[1000010];
string s;

ll mpow(ll a, ll n) {
  int ret = 1;
  for (ll i = n; i; i >>= 1, a = a * a % M)
    if (i & 1)
      ret = ret * a % M;
  return ret;
}

int main() {
  cin >> n >> s;
  m = s.size();
  fac[0] = 1;
  for (int i = 1; i < m + n; i++)
    fac[i] = (fac[i - 1] * i) % M;
  for (int i = 0; i <= n; i++) {
    ll c =
        (fac[m + n - i - 1] * mpow((fac[m - 1] * fac[n - i]) % M, M - 2)) % M;
    ans = (ans + (mpow(26, i) * c) % M * mpow(25, n - i)) % M;
  }
  cout << ans;
}


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

typedef long long ll;
const ll M = 1e9 + 7;

ll n, m, ans = 0, fac[2000010];
string s;

ll mpow(ll a, ll n) {
  int ret = 1;
  for (ll i = n; i; i >>= 1, a = a * a % M)
    if (i & 1)
      ret = ret * a % M;
  return ret;
}

int main() {
  cin >> n >> s;
  m = s.size();
  fac[0] = 1;
  for (int i = 1; i < m + n; i++)
    fac[i] = (fac[i - 1] * i) % M;
  for (int i = 0; i <= n; i++) {
    ll c =
        (fac[m + n - i - 1] * mpow((fac[m - 1] * fac[n - i]) % M, M - 2)) % M;
    ans = (ans + (mpow(26, i) * c) % M * mpow(25, n - i)) % M;
  }
  cout << ans;
}
Problem p02632 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>

#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
ll N, K;
ll m;
string S;
ll d;
ll M = 1000000007;
vector<ll> fac(5000001);  // n!(mod M)
vector<ll> ifac(5000001); // k!^{M-2} (mod M)
// a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x,
        ll n) { // x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
  ll ans = 1;
  while (n != 0) {
    if (n & 1)
      ans = ans * x % M;
    x = x * x % M;
    n = n >> 1;
  }
  return ans;
}

ll comb(ll a, ll b) { // aCbをmod計算
  if (a == 0 && b == 0)
    return 1;
  if (a < b || a < 0)
    return 0;
  ll tmp = ifac[a - b] * ifac[b] % M;
  return tmp * fac[a] % M;
}
int main() {
  fac[0] = 1;
  ifac[0] = 1;
  for (ll i = 0; i < 5000000; i++) {
    fac[i + 1] = fac[i] * (i + 1) % M; // n!(mod M)
    ifac[i + 1] =
        ifac[i] * mpow(i + 1, M - 2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
  }
  cin >> K >> S;
  N = S.size();
  for (ll i = 0; i <= K; i++) {
    d = comb(i + N - 1, N - 1);
    d = (d * mpow(25, i)) % M;
    d = (d * mpow(26, (K - i))) % M;
    m = (m + d) % M;
  }
  cout << m << endl;
}


Fixed submission:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>

#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
ll N, K;
ll m;
string S;
ll d;
ll M = 1000000007;
vector<ll> fac(5000001);  // n!(mod M)
vector<ll> ifac(5000001); // k!^{M-2} (mod M)
// a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x,
        ll n) { // x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
  ll ans = 1;
  while (n != 0) {
    if (n & 1)
      ans = ans * x % M;
    x = x * x % M;
    n = n >> 1;
  }
  return ans;
}

ll comb(ll a, ll b) { // aCbをmod計算
  if (a == 0 && b == 0)
    return 1;
  if (a < b || a < 0)
    return 0;
  ll tmp = ifac[a - b] * ifac[b] % M;
  return tmp * fac[a] % M;
}
int main() {
  fac[0] = 1;
  ifac[0] = 1;
  for (ll i = 0; i < 2000000; i++) {
    fac[i + 1] = fac[i] * (i + 1) % M; // n!(mod M)
    ifac[i + 1] =
        ifac[i] * mpow(i + 1, M - 2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
  }
  cin >> K >> S;
  N = S.size();
  for (ll i = 0; i <= K; i++) {
    d = comb(i + N - 1, N - 1);
    d = (d * mpow(25, i)) % M;
    d = (d * mpow(26, (K - i))) % M;
    m = (m + d) % M;
  }
  cout << m << endl;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
const lli M = 1e9 + 7, N = 1e6 + 5;
lli fact[N];

lli binpow(lli a, lli b) {
  if (b == 0)
    return 1;
  lli res = binpow(a, b / 2);
  res = (res * res) % M;

  if (b % 2)
    return (res * a) % M;
  return res;
}

lli inv(lli a) { return binpow(a, M - 2); }

lli add(lli a, lli b) {
  lli res = a + b;
  if (res >= M)
    return res - M;
  return res;
}

lli mul(lli a, lli b) {
  lli res = a * b;
  if (res >= M)
    return res % M;
  return res;
}

lli sub(lli a, lli b) { return (a % M - b % M + M) % M; }

void pre() {
  fact[0] = 1;
  for (int i = 1; i < N; i++)
    fact[i] = mul(fact[i - 1], i);
}

lli ncr(lli n, lli r) { return mul(fact[n], inv(mul(fact[n - r], fact[r]))); }

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  pre();

  lli k;
  string s;
  cin >> k >> s;
  lli i, n = s.length(), ans = binpow(26, n + k);

  for (i = 0; i < n; i++)
    ans = sub(ans, mul(ncr(n + k, i), binpow(25, n + k - i)));
  cout << ans;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
const lli M = 1e9 + 7, N = 2e6 + 5;
lli fact[N];

lli binpow(lli a, lli b) {
  if (b == 0)
    return 1;
  lli res = binpow(a, b / 2);
  res = (res * res) % M;

  if (b % 2)
    return (res * a) % M;
  return res;
}

lli inv(lli a) { return binpow(a, M - 2); }

lli add(lli a, lli b) {
  lli res = a + b;
  if (res >= M)
    return res - M;
  return res;
}

lli mul(lli a, lli b) {
  lli res = a * b;
  if (res >= M)
    return res % M;
  return res;
}

lli sub(lli a, lli b) { return (a % M - b % M + M) % M; }

void pre() {
  fact[0] = 1;
  for (int i = 1; i < N; i++)
    fact[i] = mul(fact[i - 1], i);
}

lli ncr(lli n, lli r) { return mul(fact[n], inv(mul(fact[n - r], fact[r]))); }

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  pre();

  lli k;
  string s;
  cin >> k >> s;
  lli i, n = s.length(), ans = binpow(26, n + k);

  for (i = 0; i < n; i++)
    ans = sub(ans, mul(ncr(n + k, i), binpow(25, n + k - i)));
  cout << ans;
  return 0;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i < n; i++)
#define rev(i, n) for (int i = n - 1; i >= 0; i--)
#define all(v) v.begin(), v.end()
#define P pair<int, int>
#define len(s) (int)s.size()
#define pb push_back

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
constexpr int mod = 1e9 + 7;
constexpr int inf = 3e18;

int K;
string S;
int mod_pow(int x, int y, int m = mod) {
  int res = 1;
  while (y > 0) {
    if (y & 1)
      (res *= x) %= m;
    (x *= x) %= m;
    y >>= 1;
  }
  return res;
}
vector<int> perm, inv;
void init_perm() {
  int x = 1e6 + 1;
  perm.resize(x);
  inv.resize(x);
  perm[0] = 1;
  REP(i, x + 1) perm[i] = perm[i - 1] * i % mod;
  inv[x] = mod_pow(perm[x], mod - 2);
  for (int i = x - 1; i >= 0; i--) {
    inv[i] = inv[i + 1] * (i + 1) % mod;
  }
}
int nCk(int x, int y) {
  if (x < y)
    return 0;
  return perm[x] * inv[x - y] % mod * inv[y] % mod;
}
signed main() {
  init_perm();
  cin >> K >> S;
  int N = K + len(S), M = len(S);
  int ans = 0;
  for (int i = M; i <= N; i++) {
    int p = nCk(N, i);
    int q = mod_pow(25, N - i);
    ans += p * q % mod;
    ans %= mod;
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i < n; i++)
#define rev(i, n) for (int i = n - 1; i >= 0; i--)
#define all(v) v.begin(), v.end()
#define P pair<int, int>
#define len(s) (int)s.size()
#define pb push_back

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
constexpr int mod = 1e9 + 7;
constexpr int inf = 3e18;

int K;
string S;
int mod_pow(int x, int y, int m = mod) {
  int res = 1;
  while (y > 0) {
    if (y & 1)
      (res *= x) %= m;
    (x *= x) %= m;
    y >>= 1;
  }
  return res;
}
vector<int> perm, inv;
void init_perm() {
  int x = 2e6 + 1;
  perm.resize(x);
  inv.resize(x);
  perm[0] = 1;
  REP(i, x + 1) perm[i] = perm[i - 1] * i % mod;
  inv[x] = mod_pow(perm[x], mod - 2);
  for (int i = x - 1; i >= 0; i--) {
    inv[i] = inv[i + 1] * (i + 1) % mod;
  }
}
int nCk(int x, int y) {
  if (x < y)
    return 0;
  return perm[x] * inv[x - y] % mod * inv[y] % mod;
}
signed main() {
  init_perm();
  cin >> K >> S;
  int N = K + len(S), M = len(S);
  int ans = 0;
  for (int i = M; i <= N; i++) {
    int p = nCk(N, i);
    int q = mod_pow(25, N - i);
    ans += p * q % mod;
    ans %= mod;
  }
  cout << ans << endl;
}
Problem p02632 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
ll n, m;
char str[1000010];
ll md = 1e9 + 7;
ll inv[2000010];
ll ksm[2000010];
ll ksmi(ll x, ll y) {
  ksm[0] = x;
  for (int i = 1; i <= 60; i++)
    ksm[i] = (ksm[i - 1] * ksm[i - 1]) % md;
  ll res = 1;
  for (int i = 0; i <= 60; i++)
    if (y & (1ll << i))
      res = (res * ksm[i]) % md;
  return res;
}
int main() {
  scanf("%lld%s", &n, &str);
  string s = str;
  m = s.size(), n += m;
  for (int i = 1; i <= n; i++)
    inv[i] = ksmi(i, md - 2);
  vector<ll> com;
  ll t = 1;
  for (ll i = m - 1; i < n; i++) {
    // cout <<t<<" ##\n";
    if (!(m - 1))
      com.push_back(1);
    else {
      com.push_back(t);
      t = (t * inv[i - (m - 1) + 1]) % md;
      t = (t * (i + 1)) % md;
    }
  }
  // for (int i=0;i<com.size();i++) cout <<com[i]<<" ";
  // cout <<"\n";
  t = 1;
  for (int i = 0; i < com.size(); i++)
    com[i] = (com[i] * t) % md, t = (t * 25) % md;
  ll res = 0;
  for (int i = 0; i < com.size(); i++)
    res = (((res * 26) % md) + com[i]) % md;
  printf("%lld", res);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
ll n, m;
char str[1000010];
ll md = 1e9 + 7;
ll inv[2000010];
ll ksm[2000010];
ll ksmi(ll x, ll y) {
  ksm[0] = x;
  for (int i = 1; i <= 60; i++)
    ksm[i] = (ksm[i - 1] * ksm[i - 1]) % md;
  ll res = 1;
  for (int i = 0; i <= 60; i++)
    if (y & (1ll << i))
      res = (res * ksm[i]) % md;
  return res;
}
int main() {
  scanf("%lld%s", &n, &str);
  string s = str;
  m = s.size(), n += m;
  for (int i = 1; i < n - (m - 1) + 1; i++)
    inv[i] = ksmi(i, md - 2);
  vector<ll> com;
  ll t = 1;
  for (ll i = m - 1; i < n; i++) {
    // cout <<t<<" ##\n";
    if (!(m - 1))
      com.push_back(1);
    else {
      com.push_back(t);
      t = (t * inv[i - (m - 1) + 1]) % md;
      t = (t * (i + 1)) % md;
    }
  }
  // for (int i=0;i<com.size();i++) cout <<com[i]<<" ";
  // cout <<"\n";
  t = 1;
  for (int i = 0; i < com.size(); i++)
    com[i] = (com[i] * t) % md, t = (t * 25) % md;
  ll res = 0;
  for (int i = 0; i < com.size(); i++)
    res = (((res * 26) % md) + com[i]) % md;
  printf("%lld", res);
  return 0;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = {1, 0, -1, 0}, dj[4] = {0, 1, 0, -1};

#define N 200007
ll fac[N], inv[N], finv[N];

void cominit(int n) {
  int i;
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (i = 2; i < n + 2; i++) {
    fac[i] = fac[i - 1] * i % mod;
    inv[i] = mod - inv[mod % i] * (mod / i) % mod;
    finv[i] = finv[i - 1] * inv[i] % mod;
  }
  return;
}

ll com(int n, int r) {
  if (n < r)
    return 0;
  if (n < 0 || r < 0)
    return 0;
  if (r == 0 || r == n)
    return 1;
  return (fac[n] * finv[r]) % mod * finv[n - r] % mod;
}

ll ml_pow(ll n, ll k, int p) {
  ll y, res;

  res = 1;
  y = n;
  while (k > 0) {
    if (k % 2 == 1) {
      res = res * y % p;
    }
    y = y * y % p;
    k /= 2;
  }

  return res;
}

int main(void) {
  int n, k, i, ans;
  string s;

  scanf("%d", &k);
  cin >> s;

  n = s.size();

  cominit(n + k);

  ans = 0;
  for (i = n; i <= n + k; i++) {
    ans = (ans + com(i - 1, n - 1) * ml_pow(25, i - n, mod) % mod *
                     ml_pow(26, n + k - i, mod) % mod) %
          mod;
  }

  printf("%d\n", ans);

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = {1, 0, -1, 0}, dj[4] = {0, 1, 0, -1};

#define N 2000007
ll fac[N], inv[N], finv[N];

void cominit(int n) {
  int i;
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (i = 2; i < n + 2; i++) {
    fac[i] = fac[i - 1] * i % mod;
    inv[i] = mod - inv[mod % i] * (mod / i) % mod;
    finv[i] = finv[i - 1] * inv[i] % mod;
  }
  return;
}

ll com(int n, int r) {
  if (n < r)
    return 0;
  if (n < 0 || r < 0)
    return 0;
  if (r == 0 || r == n)
    return 1;
  return (fac[n] * finv[r]) % mod * finv[n - r] % mod;
}

ll ml_pow(ll n, ll k, int p) {
  ll y, res;

  res = 1;
  y = n;
  while (k > 0) {
    if (k % 2 == 1) {
      res = res * y % p;
    }
    y = y * y % p;
    k /= 2;
  }

  return res;
}

int main(void) {
  int n, k, i, ans;
  string s;

  scanf("%d", &k);
  cin >> s;

  n = s.size();

  cominit(n + k);

  ans = 0;
  for (i = n; i <= n + k; i++) {
    ans = (ans + com(i - 1, n - 1) * ml_pow(25, i - n, mod) % mod *
                     ml_pow(26, n + k - i, mod) % mod) %
          mod;
  }

  printf("%d\n", ans);

  return 0;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1 << 20, mod = 1e9 + 7;
int fact[maxn], inv[maxn];
void pre() {
  for (int i = 0; i < maxn; i++)
    if (i < 2)
      fact[i] = inv[i] = 1;
    else
      fact[i] = i, inv[i] = mod - (mod / i) * 1ll * inv[mod % i] % mod;
  for (int i = 1; i < maxn; i++)
    fact[i] = fact[i] * 1ll * fact[i - 1] % mod,
    inv[i] = inv[i] * 1ll * inv[i - 1] % mod;
}
int bp(int a, int p) {
  int r = 1;
  while (p) {
    if (p & 1)
      r = r * 1ll * a % mod;
    a = a * 1ll * a % mod, p >>= 1;
  }
  return r;
}
int nck(int i, int j) {
  if (i < j || j < 0)
    return 0;
  int t = fact[i] * 1ll * inv[j] % mod;
  return t * 1ll * inv[i - j] % mod;
}
int get(int i, int j) {
  int t = bp(25, i - j);
  return t * 1ll * nck(i, j) % mod;
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  pre();
  int ans = 0, n, k;
  string s;
  cin >> k >> s;
  n = s.size();
  for (int i = n; i <= n + k; i++)
    ans = (ans + get(n + k, i)) % mod;
  cout << ans;
  return 0;
}
// cacyaa
// 128 + 2 + 128*


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1 << 22, mod = 1e9 + 7;
int fact[maxn], inv[maxn];
void pre() {
  for (int i = 0; i < maxn; i++)
    if (i < 2)
      fact[i] = inv[i] = 1;
    else
      fact[i] = i, inv[i] = mod - (mod / i) * 1ll * inv[mod % i] % mod;
  for (int i = 1; i < maxn; i++)
    fact[i] = fact[i] * 1ll * fact[i - 1] % mod,
    inv[i] = inv[i] * 1ll * inv[i - 1] % mod;
}
int bp(int a, int p) {
  int r = 1;
  while (p) {
    if (p & 1)
      r = r * 1ll * a % mod;
    a = a * 1ll * a % mod, p >>= 1;
  }
  return r;
}
int nck(int i, int j) {
  if (i < j || j < 0)
    return 0;
  int t = fact[i] * 1ll * inv[j] % mod;
  return t * 1ll * inv[i - j] % mod;
}
int get(int i, int j) {
  int t = bp(25, i - j);
  return t * 1ll * nck(i, j) % mod;
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  pre();
  int ans = 0, n, k;
  string s;
  cin >> k >> s;
  n = s.size();
  for (int i = n; i <= n + k; i++)
    ans = (ans + get(n + k, i)) % mod;
  cout << ans;
  return 0;
}
// cacyaa
// 128 + 2 + 128*
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
ll k;
char s[1000010];
ll fac[1000010], ifac[1000010], inv[1000010];
ll n;
ll ans;
ll ksm(ll a, ll b, ll m) {
  ll ret = 1;
  while (b) {
    if (b & 1)
      ret = (ret * a) % m;
    a = (a * a) % m;
    b >>= 1;
  }
  return ret;
}
ll C(ll i, ll j) { return fac[i] * ifac[j] % mod * ifac[i - j] % mod; }
int main() {
  scanf("%lld", &k);
  scanf("%s", s + 1);
  n = strlen(s + 1);
  fac[0] = ifac[0] = inv[1] = 1;
  for (ll i = 2; i <= n + k; i++) {
    inv[i] = (mod - mod / i) * inv[mod % i] % mod;
  }
  for (ll i = 1; i <= n + k; i++) {
    fac[i] = fac[i - 1] * i % mod;
    ifac[i] = ifac[i - 1] * inv[i] % mod;
  }
  for (ll i = 0; i <= k; i++) {
    ans = (ans + ksm(26, i, mod) * C(n + k - i - 1, n - 1) % mod *
                     ksm(25, k - i, mod)) %
          mod;
  }
  printf("%lld", ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
ll k;
char s[1000010];
ll fac[2000010], ifac[2000010], inv[2000010];
ll n;
ll ans;
ll ksm(ll a, ll b, ll m) {
  ll ret = 1;
  while (b) {
    if (b & 1)
      ret = (ret * a) % m;
    a = (a * a) % m;
    b >>= 1;
  }
  return ret;
}
ll C(ll i, ll j) { return fac[i] * ifac[j] % mod * ifac[i - j] % mod; }
int main() {
  scanf("%lld", &k);
  scanf("%s", s + 1);
  n = strlen(s + 1);
  fac[0] = ifac[0] = inv[1] = 1;
  for (ll i = 2; i <= n + k; i++) {
    inv[i] = (mod - mod / i) * inv[mod % i] % mod;
  }
  for (ll i = 1; i <= n + k; i++) {
    fac[i] = fac[i - 1] * i % mod;
    ifac[i] = ifac[i - 1] * inv[i] % mod;
  }
  for (ll i = 0; i <= k; i++) {
    ans = (ans + ksm(26, i, mod) * C(n + k - i - 1, n - 1) % mod *
                     ksm(25, k - i, mod)) %
          mod;
  }
  printf("%lld", ans);
  return 0;
}
Problem p02632 (C++)

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

const int MOD = 1e9 + 7;
const int MAX = 1e6 + 5;

int fact[MAX];
int inv[MAX];

int Power(int n, int x) {
  if (x == 0) {
    return 1;
  } else if (x & 1) {
    return 1ll * n * Power(n, x - 1) % MOD;
  } else {
    int res = Power(n, x / 2);
    return 1ll * res * res % MOD;
  }
}

int C(int n, int r) {
  if (r > n || r < 0) {
    return 0;
  }
  return 1ll * fact[n] * inv[r] % MOD * inv[n - r] % MOD;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);

  fact[0] = inv[0] = 1;
  for (int i = 1; i < MAX; i++) {
    fact[i] = 1ll * i * fact[i - 1] % MOD;
    inv[i] = Power(fact[i], MOD - 2);
  }

  int K;
  cin >> K;
  string S;
  cin >> S;
  int ans = 0;
  for (int i = 0; i <= K; i++) {
    ans += 1ll * Power(26, i) * Power(25, K - i) % MOD *
           C(K - i + int(S.size()) - 1, int(S.size()) - 1) % MOD;
    if (ans >= MOD) {
      ans -= MOD;
    }
  }
  cout << ans << "\n";
  return 0;
}


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

const int MOD = 1e9 + 7;
const int MAX = 3e6 + 5;

int fact[MAX];
int inv[MAX];

int Power(int n, int x) {
  if (x == 0) {
    return 1;
  } else if (x & 1) {
    return 1ll * n * Power(n, x - 1) % MOD;
  } else {
    int res = Power(n, x / 2);
    return 1ll * res * res % MOD;
  }
}

int C(int n, int r) {
  if (r > n || r < 0) {
    return 0;
  }
  return 1ll * fact[n] * inv[r] % MOD * inv[n - r] % MOD;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);

  fact[0] = inv[0] = 1;
  for (int i = 1; i < MAX; i++) {
    fact[i] = 1ll * i * fact[i - 1] % MOD;
    inv[i] = Power(fact[i], MOD - 2);
  }

  int K;
  cin >> K;
  string S;
  cin >> S;
  int ans = 0;
  for (int i = 0; i <= K; i++) {
    ans += 1ll * Power(26, i) * Power(25, K - i) % MOD *
           C(K - i + int(S.size()) - 1, int(S.size()) - 1) % MOD;
    if (ans >= MOD) {
      ans -= MOD;
    }
  }
  cout << ans << "\n";
  return 0;
}