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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll N = 1e6 + 30, Mod = 1e9 + 7;
const ll SQ = 330;

ll F[N], I[N];
ll mul(ll a, ll b) { return (a * b) % Mod; }
ll sum(ll a, ll b) { return (a + b + Mod) % Mod; }
ll Pow(ll a, ll b) {
  ll res = 1;
  for (; b; b >>= 1, a = mul(a, a))
    if (b & 1)
      res = mul(res, a);
  return res;
}
ll C(ll r, ll n) {
  if (r < 0 || r > n)
    return 0;
  return mul(F[n], mul(I[r], I[n - r]));
}
ll inv(ll x) { return Pow(x, Mod - 2); }
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  F[0] = 1;
  for (int i = 1; i < N; i++)
    F[i] = mul(i, F[i - 1]);
  I[N - 1] = Pow(F[N - 1], Mod - 2);
  for (int i = N - 2; ~i; i--)
    I[i] = mul(i + 1, I[i + 1]);
  ll ans = 0;
  ll k;
  cin >> k;
  string s;
  cin >> s;
  ll n = s.size();
  for (int i = 0; i <= k; i++) {
    ll res = 0;
    res = C(n - 1, k + n - i - 1);
    res = mul(res, Pow(25, k - i));
    res = mul(res, Pow(26, i));
    ans = sum(ans, res);
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll N = 2e6 + 30, Mod = 1e9 + 7;
const ll SQ = 330;

ll F[N], I[N];
ll mul(ll a, ll b) { return (a * b) % Mod; }
ll sum(ll a, ll b) { return (a + b + Mod) % Mod; }
ll Pow(ll a, ll b) {
  ll res = 1;
  for (; b; b >>= 1, a = mul(a, a))
    if (b & 1)
      res = mul(res, a);
  return res;
}
ll C(ll r, ll n) {
  if (r < 0 || r > n)
    return 0;
  return mul(F[n], mul(I[r], I[n - r]));
}
ll inv(ll x) { return Pow(x, Mod - 2); }
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  F[0] = 1;
  for (int i = 1; i < N; i++)
    F[i] = mul(i, F[i - 1]);
  I[N - 1] = Pow(F[N - 1], Mod - 2);
  for (int i = N - 2; ~i; i--)
    I[i] = mul(i + 1, I[i + 1]);
  ll ans = 0;
  ll k;
  cin >> k;
  string s;
  cin >> s;
  ll n = s.size();
  for (int i = 0; i <= k; i++) {
    ll res = 0;
    res = C(n - 1, k + n - i - 1);
    res = mul(res, Pow(25, k - i));
    res = mul(res, Pow(26, i));
    ans = sum(ans, res);
  }
  cout << ans << endl;
}
Problem p02632 (C++)

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

// BE CAREFUL WITH HASH TABLE & UNORDERED MAP
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;

#define MOD 1000000007
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, b) FOR(i, 0, b)
#define RFO(i, a, b) for (int i = (b - 1); i >= (a); i--)
#define RF0(i, b) RFO(i, 0, b)
#define lli long long int
#define pii pair<int, int>
#define add(a, b) ((int)(((lli)(a) + (b)) % MOD))
#define mul(a, b) ((int)(((lli)(a) * (b)) % MOD))
#define PB emplace_back

// ifstream cin ("cinput.in");
// ofstream cout ("coutput.out");

int K;
string S;
int fact[2000000];

int modexp(int a, int e) {
  int ans = 1;
  int cur = a;
  while (e) {
    if (e & 1) {
      ans = mul(ans, cur);
      e--;
    }
    e /= 2;
    cur = mul(cur, cur);
  }
  return ans;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> K >> S;
  fact[0] = 1;
  FOR(i, 1, K + S.size() + 1) fact[i] = mul(fact[i - 1], i);
  int ans = 0;
  FOR(av, S.size(), K + S.size() + 1) {
    int nck =
        mul(fact[av - 1],
            modexp(mul(fact[S.size() - 1], fact[av - S.size()]), MOD - 2));
    int p1 = modexp(25, av - S.size());
    int p2 = modexp(26, K + S.size() - av);
    ans = add(ans, mul(mul(p1, p2), nck));
  }
  cout << ans << '\n';
}

Fixed submission:
#include <fstream>
#include <iostream>

// BE CAREFUL WITH HASH TABLE & UNORDERED MAP
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;

#define MOD 1000000007
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, b) FOR(i, 0, b)
#define RFO(i, a, b) for (int i = (b - 1); i >= (a); i--)
#define RF0(i, b) RFO(i, 0, b)
#define lli long long int
#define pii pair<int, int>
#define add(a, b) ((int)(((lli)(a) + (b)) % MOD))
#define mul(a, b) ((int)(((lli)(a) * (b)) % MOD))
#define PB emplace_back

// ifstream cin ("cinput.in");
// ofstream cout ("coutput.out");

int K;
string S;
int fact[2000001];

int modexp(int a, int e) {
  int ans = 1;
  int cur = a;
  while (e) {
    if (e & 1) {
      ans = mul(ans, cur);
      e--;
    }
    e /= 2;
    cur = mul(cur, cur);
  }
  return ans;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> K >> S;
  fact[0] = 1;
  FOR(i, 1, K + S.size() + 1) fact[i] = mul(fact[i - 1], i);
  int ans = 0;
  FOR(av, S.size(), K + S.size() + 1) {
    int nck =
        mul(fact[av - 1],
            modexp(mul(fact[S.size() - 1], fact[av - S.size()]), MOD - 2));
    int p1 = modexp(25, av - S.size());
    int p2 = modexp(26, K + S.size() - av);
    ans = add(ans, mul(mul(p1, p2), nck));
  }
  cout << ans << '\n';
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
const int MAX = 200100;
const int 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 modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
const int MAX = 2000100;
const int 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 modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10, mod = 1e9 + 7;
typedef long long ll;
ll fact[maxn], inv[maxn];
ll exp(ll a, ll b) {
  ll res = 1LL;
  for (; b; b >>= 1, a = (a * a) % mod)
    if (b & 1)
      res = (res * a) % mod;
  return res;
}
void precalc() {
  fact[0] = 1LL;
  for (int i = 1; i < maxn; i++)
    fact[i] = (fact[i - 1] * i) % mod;
  inv[maxn - 1] = exp(fact[maxn - 1], mod - 2);
  for (int i = maxn - 2; i >= 0; i--)
    inv[i] = (inv[i + 1] * (i + 1)) % mod;
}
ll ncr(ll n, ll r) {
  if (n < r)
    return 0LL;
  return ((fact[n] * inv[n - r]) % mod * inv[r]) % mod;
}
int main() {
  precalc();
  ll k;
  cin >> k;
  string s;
  cin >> s;
  ll n = (int)s.size();
  ll l = n + k;
  ll ans = 0LL;
  for (ll i = n; i <= l; i++)
    ans = (ans + ((ncr(i - 1, n - 1) * exp(25, i - n)) % mod * exp(26, l - i)) %
                     mod) %
          mod;
  cout << ans << "\n";
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6 + 10, mod = 1e9 + 7;
typedef long long ll;
ll fact[maxn], inv[maxn];
ll exp(ll a, ll b) {
  ll res = 1LL;
  for (; b; b >>= 1, a = (a * a) % mod)
    if (b & 1)
      res = (res * a) % mod;
  return res;
}
void precalc() {
  fact[0] = 1LL;
  for (int i = 1; i < maxn; i++)
    fact[i] = (fact[i - 1] * i) % mod;
  inv[maxn - 1] = exp(fact[maxn - 1], mod - 2);
  for (int i = maxn - 2; i >= 0; i--)
    inv[i] = (inv[i + 1] * (i + 1)) % mod;
}
ll ncr(ll n, ll r) {
  if (n < r)
    return 0LL;
  return ((fact[n] * inv[n - r]) % mod * inv[r]) % mod;
}
int main() {
  precalc();
  ll k;
  cin >> k;
  string s;
  cin >> s;
  ll n = (int)s.size();
  ll l = n + k;
  ll ans = 0LL;
  for (ll i = n; i <= l; i++)
    ans = (ans + ((ncr(i - 1, n - 1) * exp(25, i - n)) % mod * exp(26, l - i)) %
                     mod) %
          mod;
  cout << ans << "\n";
}
Problem p02632 (C++)

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

const long long MOD = 1000000007;
using ll = long long;

const int MAX = 1010000;

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;
}

// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

void solve(long long K, std::string S) {
  ll ans = 0;
  COMinit();
  for (int i = 0; i <= K; i++) {
    ans += (COM(K - i + (int)S.size() - 1, (int)S.size() - 1) *
            modpow(26, i, MOD)) %
           MOD * modpow(25, K - i, MOD);
    ans %= MOD;
  }
  cout << ans << endl;
}

int main() {
  long long K;
  scanf("%lld", &K);
  std::string S;
  std::cin >> S;
  solve(K, S);
  return 0;
}


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

const long long MOD = 1000000007;
using ll = long long;

const int MAX = 2010000;

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;
}

// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

void solve(long long K, std::string S) {
  ll ans = 0;
  COMinit();
  for (int i = 0; i <= K; i++) {
    ans += (COM(K - i + (int)S.size() - 1, (int)S.size() - 1) *
            modpow(26, i, MOD)) %
           MOD * modpow(25, K - i, MOD);
    ans %= MOD;
  }
  cout << ans << endl;
}

int main() {
  long long K;
  scanf("%lld", &K);
  std::string S;
  std::cin >> S;
  solve(K, S);
  return 0;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
// I SELL YOU...!
#include <algorithm>
#include <chrono>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using TP = tuple<ll, ll, ll>;
void init_io() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
#define MAX 1100000
#define MOD 1000000007

ll fac[MAX], finv[MAX], inv[MAX];
ll pv0[MAX], pv1[MAX];

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;
}

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  pv0[0] = 1;
  pv0[1] = 25;
  pv1[0] = 1;
  pv1[1] = 26;
  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;
    pv0[i] = (pv0[i - 1] * 25) % MOD;
    pv1[i] = (pv1[i - 1] * 26) % MOD;
  }
}

signed main() {
  COMinit();
  init_io();
  ll k, n, all = 0, c = 1, ans = 0;
  string s;
  cin >> k >> s;
  n = s.size();
  all = n + k;
  for (ll i = all; i >= n; i--) {
    ll tmp = (pv0[i - n] * pv1[all - i]) % MOD;
    tmp *= COM(i - 1, n - 1);
    tmp %= MOD;
    ans += tmp;
    ans %= MOD;
  }
  cout << ans << endl;
}


Fixed submission:
// I SELL YOU...!
#include <algorithm>
#include <chrono>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using TP = tuple<ll, ll, ll>;
void init_io() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
#define MAX 3100000
#define MOD 1000000007

ll fac[MAX], finv[MAX], inv[MAX];
ll pv0[MAX], pv1[MAX];

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;
}

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  pv0[0] = 1;
  pv0[1] = 25;
  pv1[0] = 1;
  pv1[1] = 26;
  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;
    pv0[i] = (pv0[i - 1] * 25) % MOD;
    pv1[i] = (pv1[i - 1] * 26) % MOD;
  }
}

signed main() {
  COMinit();
  init_io();
  ll k, n, all = 0, c = 1, ans = 0;
  string s;
  cin >> k >> s;
  n = s.size();
  all = n + k;
  for (ll i = all; i >= n; i--) {
    ll tmp = (pv0[i - n] * pv1[all - i]) % MOD;
    tmp *= COM(i - 1, n - 1);
    tmp %= MOD;
    ans += tmp;
    ans %= MOD;
  }
  cout << ans << endl;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long int
#define uu first
#define vv second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define INF 1e9
#define fastRead                                                               \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
using namespace std;

const int MAX = 1e6 + 6;
const ll MOD = 1e9 + 7;

ll fact[MAX], invFact[MAX];

ll bigMod(ll a, ll b) {

  if (b == 0)
    return 1LL;
  ll ret = bigMod(a, b / 2);
  ret = (ret * ret) % MOD;
  if (b & 1)
    ret = (ret * a) % MOD;
  return ret;
}
ll invMod(ll x) { return bigMod(x, MOD - 2); }
void pre() {

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

  invFact[MAX - 1] = invMod(fact[MAX - 1]);

  for (int i = MAX - 2; i >= 0; i--) {
    invFact[i] = (invFact[i + 1] * (i + 1)) % MOD;
  }
  //    for(int i =0 ; i < 5; i++ ) cout<<invFact[i]<<" ";
}

ll ncr(ll n, ll r) {

  ll lob = fact[n];

  ll hor = (invFact[r] * invFact[n - r]) % MOD;

  return (lob * hor) % MOD;
}

int main() {
  fastRead;
  pre();
  int k;
  string s;
  cin >> k >> s;
  int n = s.size();
  int tot = n + k;
  ll ans = bigMod(26, tot);

  for (int i = 0; i < n; i++) {

    ll tmp = (ncr(tot, i) * bigMod(25, tot - i)) % MOD;
    ans = (ans - tmp) % MOD;
    ans = (ans + MOD) % MOD;
  }
  cout << ans << '\n';
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long int
#define uu first
#define vv second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define INF 1e9
#define fastRead                                                               \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
using namespace std;

const int MAX = 2e6 + 6;
const ll MOD = 1e9 + 7;

ll fact[MAX], invFact[MAX];

ll bigMod(ll a, ll b) {

  if (b == 0)
    return 1LL;
  ll ret = bigMod(a, b / 2);
  ret = (ret * ret) % MOD;
  if (b & 1)
    ret = (ret * a) % MOD;
  return ret;
}
ll invMod(ll x) { return bigMod(x, MOD - 2); }
void pre() {

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

  invFact[MAX - 1] = invMod(fact[MAX - 1]);

  for (int i = MAX - 2; i >= 0; i--) {
    invFact[i] = (invFact[i + 1] * (i + 1)) % MOD;
  }
  //    for(int i =0 ; i < 5; i++ ) cout<<invFact[i]<<" ";
}

ll ncr(ll n, ll r) {

  ll lob = fact[n];

  ll hor = (invFact[r] * invFact[n - r]) % MOD;

  return (lob * hor) % MOD;
}

int main() {
  fastRead;
  pre();
  int k;
  string s;
  cin >> k >> s;
  int n = s.size();
  int tot = n + k;
  ll ans = bigMod(26, tot);

  for (int i = 0; i < n; i++) {

    ll tmp = (ncr(tot, i) * bigMod(25, tot - i)) % MOD;
    ans = (ans - tmp) % MOD;
    ans = (ans + MOD) % MOD;
  }
  cout << ans << '\n';
  return 0;
}
Problem p02632 (C++)

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

struct fastio {
  fastio() {
    ios::sync_with_stdio(false);
    cout << setprecision(10) << fixed;
    cin.tie(0);
  }
};

fastio _fast_io;

const int mod = 1e9 + 7;
int k;
string s;
const int N = 1e6 + 1;
ll fac[N];
ll inv[N];

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

void init() {
  fac[0] = 1;
  for (int i = 1; i < N; ++i) {
    fac[i] = fac[i - 1] * i % mod;
  }
  inv[N - 1] = power(fac[N - 1], mod - 2);
  for (int i = N - 2; i >= 0; --i) {
    inv[i] = inv[i + 1] * (i + 1) % mod;
  }
}

ll C(ll a, ll b) { return fac[a] * inv[b] % mod * inv[a - b] % mod; }

int main() {
  init();
  cin >> k >> s;
  int n = s.length();
  ll res = 0;
  ll sum = k + n;
  for (int i = 0; i <= k; ++i) {
    res = (res + power(26, i) * C(sum - 1 - i, n - 1) % mod * power(25, k - i) %
                     mod) %
          mod;
  }
  cout << res << endl;
  return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

struct fastio {
  fastio() {
    ios::sync_with_stdio(false);
    cout << setprecision(10) << fixed;
    cin.tie(0);
  }
};

fastio _fast_io;

const int mod = 1e9 + 7;
int k;
string s;
const int N = 1e6 * 2 + 10;
ll fac[N];
ll inv[N];

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

void init() {
  fac[0] = 1;
  for (int i = 1; i < N; ++i) {
    fac[i] = fac[i - 1] * i % mod;
  }
  inv[N - 1] = power(fac[N - 1], mod - 2);
  for (int i = N - 2; i >= 0; --i) {
    inv[i] = inv[i + 1] * (i + 1) % mod;
  }
}

ll C(ll a, ll b) { return fac[a] * inv[b] % mod * inv[a - b] % mod; }

int main() {
  init();
  cin >> k >> s;
  int n = s.length();
  ll res = 0;
  ll sum = k + n;
  for (int i = 0; i <= k; ++i) {
    res = (res + power(26, i) * C(sum - 1 - i, n - 1) % mod * power(25, k - i) %
                     mod) %
          mod;
  }
  cout << res << endl;
  return 0;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define MSET(x, y) memset(x, y, sizeof(x))
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 3000005
#define ll long long
#define ld long double
#define INF 1e18
#define endl "\n"
#define fastio                                                                 \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
using namespace std;
ll MOD = 1000000007;
string yes = "YES\n";
string no = "NO\n";
#define PI 3.1415926535

ll k;
string s;

ll power(ll x, ll y, ll p) {
  ll res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1; // y = y/2
    x = (x * x) % p;
  }
  return res;
}
ll fac[M], invfac[M];

ll pre() {
  fac[0] = 1;
  for (ll i = 1; i < M; i++)
    fac[i] = (fac[i - 1] * i) % MOD;
  invfac[M - 1] = power(fac[M - 1], MOD - 2, MOD);
  for (ll i = M - 2; i >= 0; i--) {
    invfac[i] = (invfac[i + 1] * (i + 1)) % MOD;
  }
}

ll ncr(ll n, ll r, ll p) {
  if (r < 0 or r > n)
    return 0;
  return ((((fac[n] * invfac[r]) % p) * invfac[n - r]) % p);
}

int32_t main() {
  fastio;
  cin >> k;
  cin >> s;
  ll n = s.size();
  pre();
  ll ans = 0;
  for (ll i = 0; i <= k; i++) {
    ans += ((((ncr(n + k - i - 1, n - 1, MOD) * power(25, k - i, MOD)) % MOD) *
             power(26, i, MOD) % MOD) %
            MOD);
    ans %= MOD;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define MSET(x, y) memset(x, y, sizeof(x))
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 3000005
#define ll long long
#define ld long double
#define INF 1e18
#define endl "\n"
#define fastio                                                                 \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
using namespace std;
ll MOD = 1000000007;
string yes = "YES\n";
string no = "NO\n";
#define PI 3.1415926535

ll k;
string s;

ll power(ll x, ll y, ll p) {
  ll res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1; // y = y/2
    x = (x * x) % p;
  }
  return res;
}
ll fac[M], invfac[M];

void pre() {
  fac[0] = 1;
  for (ll i = 1; i < M; i++)
    fac[i] = (fac[i - 1] * i) % MOD;
  invfac[M - 1] = power(fac[M - 1], MOD - 2, MOD);
  for (ll i = M - 2; i >= 0; i--) {
    invfac[i] = (invfac[i + 1] * (i + 1)) % MOD;
  }
}

ll ncr(ll n, ll r, ll p) {
  if (r < 0 or r > n)
    return 0;
  return ((((fac[n] * invfac[r]) % p) * invfac[n - r]) % p);
}

int32_t main() {
  fastio;
  cin >> k;
  cin >> s;
  ll n = s.size();
  pre();
  ll ans = 0;
  for (ll i = 0; i <= k; i++) {
    ans += ((((ncr(n + k - i - 1, n - 1, MOD) * power(25, k - i, MOD)) % MOD) *
             power(26, i, MOD) % MOD) %
            MOD);
    ans %= MOD;
  }
  cout << ans << endl;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
const int MOD = 1000000007;
const int BUF = 1000005;

int factorial[BUF];

int add(int a, int b) { return (1LL * a + b) % MOD; }

int mul(int a, int b) { return 1LL * a * b % MOD; }

int modpow(int p, int n) {
  if (n == 0)
    return 1;
  int t = modpow(p, n / 2);
  return n & 1 ? mul(t, mul(t, p)) : mul(t, t);
}

int inv(int v) { return modpow(v, MOD - 2); }

int nCk(int n, int k) {
  return mul(factorial[n], mul(inv(factorial[k]), inv(factorial[n - k])));
}

int nHk(int n, int k) { return nCk(n + k - 1, k); }

int K;
int sLeng;

void read() {
  string dummy;
  cin >> K >> dummy;
  sLeng = dummy.size();
}

void work() {
  int ans = 0;
  for (int i = 0; i <= K; ++i) {
    ans = add(ans, mul(nHk(sLeng, i), mul(modpow(25, i), modpow(26, K - i))));
  }
  cout << ans << endl;
}

int main() {
  factorial[0] = 1;
  for (int i = 1; i < BUF; ++i) {
    factorial[i] = mul(i, factorial[i - 1]);
  }

  read();
  work();

  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;
const int MOD = 1000000007;
const int BUF = 2000005;

int factorial[BUF];

int add(int a, int b) { return (1LL * a + b) % MOD; }

int mul(int a, int b) { return 1LL * a * b % MOD; }

int modpow(int p, int n) {
  if (n == 0)
    return 1;
  int t = modpow(p, n / 2);
  return n & 1 ? mul(t, mul(t, p)) : mul(t, t);
}

int inv(int v) { return modpow(v, MOD - 2); }

int nCk(int n, int k) {
  return mul(factorial[n], mul(inv(factorial[k]), inv(factorial[n - k])));
}

int nHk(int n, int k) { return nCk(n + k - 1, k); }

int K;
int sLeng;

void read() {
  string dummy;
  cin >> K >> dummy;
  sLeng = dummy.size();
}

void work() {
  int ans = 0;
  for (int i = 0; i <= K; ++i) {
    ans = add(ans, mul(nHk(sLeng, i), mul(modpow(25, i), modpow(26, K - i))));
  }
  cout << ans << endl;
}

int main() {
  factorial[0] = 1;
  for (int i = 1; i < BUF; ++i) {
    factorial[i] = mul(i, factorial[i - 1]);
  }

  read();
  work();

  return 0;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int const nax = 1e3 + 10;
const int mod = 1000000007; //
void plusle(int &a, int b) {
  if ((a += b) >= mod)
    a -= mod;
}
void minun(int &a, int b) {
  if ((a -= b) < 0)
    a += mod;
}
int add(int a, int b) { return ((a += b) >= mod) ? a - mod : a; }
int sub(int a, int b) { return ((a -= b) < 0) ? a + mod : a; }
int mul(int a, int b) { return 1LL * a * b % mod; }
int power(int a, int b) {
  int res = 1;
  for (; b > 0; b >>= 1, a = mul(a, a))
    if (b & 1)
      res = mul(res, a);
  return res;
}

const int Mx = 2e6 + 10;
int fac[Mx], invf[Mx];
void prefact() {
  fac[0] = 1;
  for (int i = 1; i < Mx; i++) {
    fac[i] = mul(fac[i - 1], i);
  }
  invf[Mx - 1] = power(fac[Mx - 1], mod - 2);
  for (int i = Mx - 2; i >= 0; i--) {
    invf[i] = mul(invf[i + 1], i + 1);
  }
}

int ncr(int N, int R) {
  if (R > N)
    return 0;
  if (R == 0 || R == N)
    return 1;
  return mul(fac[N], mul(invf[N - R], invf[R]));
}

int k;
char s[nax];

int main() {
  prefact();
  scanf("%d", &k);

  scanf("%s", s + 1);

  int n = strlen(s + 1);

  int ans = 0;
  for (int i = 0; i <= k; ++i) {
    plusle(ans, mul(ncr(n + k, i), power(25, i)));
  }

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


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int const nax = 2e6 + 10;
const int mod = 1000000007; //
void plusle(int &a, int b) {
  if ((a += b) >= mod)
    a -= mod;
}
void minun(int &a, int b) {
  if ((a -= b) < 0)
    a += mod;
}
int add(int a, int b) { return ((a += b) >= mod) ? a - mod : a; }
int sub(int a, int b) { return ((a -= b) < 0) ? a + mod : a; }
int mul(int a, int b) { return 1LL * a * b % mod; }
int power(int a, int b) {
  int res = 1;
  for (; b > 0; b >>= 1, a = mul(a, a))
    if (b & 1)
      res = mul(res, a);
  return res;
}

const int Mx = 2e6 + 10;
int fac[Mx], invf[Mx];
void prefact() {
  fac[0] = 1;
  for (int i = 1; i < Mx; i++) {
    fac[i] = mul(fac[i - 1], i);
  }
  invf[Mx - 1] = power(fac[Mx - 1], mod - 2);
  for (int i = Mx - 2; i >= 0; i--) {
    invf[i] = mul(invf[i + 1], i + 1);
  }
}

int ncr(int N, int R) {
  if (R > N)
    return 0;
  if (R == 0 || R == N)
    return 1;
  return mul(fac[N], mul(invf[N - R], invf[R]));
}

int k;
char s[nax];

int main() {
  prefact();
  scanf("%d", &k);

  scanf("%s", s + 1);

  int n = strlen(s + 1);

  int ans = 0;
  for (int i = 0; i <= k; ++i) {
    plusle(ans, mul(ncr(n + k, i), power(25, i)));
  }

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const int N = 1e6 + 10;
const int mod = 1e9 + 7;

ll fac[N], inv[N];

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

void init() {
  fac[0] = 1;
  for (int i = 1; i < N; i++)
    fac[i] = fac[i - 1] * i % mod;
  inv[N - 1] = binpow(fac[N - 1], mod - 2);
  for (int i = N - 2; i >= 0; i--)
    inv[i] = inv[i + 1] * (i + 1) % mod;
}

ll C(ll n, ll m) { return fac[n] * inv[m] % mod * inv[n - m] % mod; }

int main() {
  init();
  int k;
  string s;
  cin >> k >> s;
  int n = k + s.size();
  ll ans = 0;
  for (int i = s.size(); i <= n; i++)
    ans += C(n, i) * binpow(25, n - i) % mod, ans %= mod;
  cout << ans << "\n";
}

Fixed submission:
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const int N = 2e6 + 10;
const int mod = 1e9 + 7;

ll fac[N], inv[N];

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

void init() {
  fac[0] = 1;
  for (int i = 1; i < N; i++)
    fac[i] = fac[i - 1] * i % mod;
  inv[N - 1] = binpow(fac[N - 1], mod - 2);
  for (int i = N - 2; i >= 0; i--)
    inv[i] = inv[i + 1] * (i + 1) % mod;
}

ll C(ll n, ll m) { return fac[n] * inv[m] % mod * inv[n - m] % mod; }

int main() {
  init();
  int k;
  string s;
  cin >> k >> s;
  int n = k + s.size();
  ll ans = 0;
  for (int i = s.size(); i <= n; i++)
    ans += C(n, i) * binpow(25, n - i) % mod, ans %= mod;
  cout << ans << "\n";
}
Problem p02632 (C++)

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

constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int MAX = 510000;

vector<long> fact(MAX), finv(MAX), inve(MAX);

void init() {
  fact.at(0) = fact.at(1) = 1;
  finv.at(0) = finv.at(1) = 1;
  inve.at(1) = 1;
  for (int i = 2; i < MAX; i++) {
    fact.at(i) = fact.at(i - 1) * i % MOD;
    inve.at(i) = MOD - inve.at(MOD % i) * (MOD / i) % MOD;
    finv.at(i) = finv.at(i - 1) * inve.at(i) % MOD;
  }
}

long com(long n, long r) {
  if (n < r || n < 0 || r < 0)
    return 0;
  return fact.at(n) * (finv.at(r) * finv.at(n - r) % MOD) % MOD;
}

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

int main() {
  init();
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N;
  string S;
  cin >> N >> S;
  int M = S.size();
  N += M;
  long ans = 0;
  for (int i = M; i <= N; i++) {
    long tmp = com(i - 1, M - 1);
    (tmp *= mpow(25, i - M)) %= MOD;
    (tmp *= mpow(26, N - i)) %= MOD;
    (ans += tmp) %= MOD;
  }
  cout << ans << "\n";
}

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

constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int MAX = 3000000;

vector<long> fact(MAX), finv(MAX), inve(MAX);

void init() {
  fact.at(0) = fact.at(1) = 1;
  finv.at(0) = finv.at(1) = 1;
  inve.at(1) = 1;
  for (int i = 2; i < MAX; i++) {
    fact.at(i) = fact.at(i - 1) * i % MOD;
    inve.at(i) = MOD - inve.at(MOD % i) * (MOD / i) % MOD;
    finv.at(i) = finv.at(i - 1) * inve.at(i) % MOD;
  }
}

long com(long n, long r) {
  if (n < r || n < 0 || r < 0)
    return 0;
  return fact.at(n) * (finv.at(r) * finv.at(n - r) % MOD) % MOD;
}

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

int main() {
  init();
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N;
  string S;
  cin >> N >> S;
  int M = S.size();
  N += M;
  long ans = 0;
  for (int i = M; i <= N; i++) {
    long tmp = com(i - 1, M - 1);
    (tmp *= mpow(25, i - M)) %= MOD;
    (tmp *= mpow(26, N - i)) %= MOD;
    (ans += tmp) %= MOD;
  }
  cout << ans << "\n";
}
Problem p02632 (C++)

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

#define fi first
#define se second
#define SZ(x) (int)x.size()
#define ll long long
#define pb push_back
#define pq priority_queue
#define pii pair<int, int>
#define mod 1000000007
#define inf 0x3f3f3f3f
#define debug(x) cerr << #x << "=" << x << '\n'
#define rep(i, a, b) for (int i = a; i < (b); i++)

const int maxn = 1e6 + 10;

int n, m;
ll fac[maxn];

ll p0w(ll base, int p) {
  ll res = 1;
  while (p) {
    if (p % 2 == 1)
      res *= base, res %= mod;
    base = base * base % mod;
    p >>= 1;
  }
  return res;
}

ll C(int x, int y) {
  return fac[x] * p0w(fac[x - y], mod - 2) % mod * p0w(fac[y], mod - 2) % mod;
}

int main() {
  std::ios::sync_with_stdio(false);
  fac[0] = 1;
  rep(i, 1, maxn) fac[i] = fac[i - 1] * (ll)i % mod;
  cin >> n;
  string s;
  cin >> s;
  n += SZ(s);
  int m = SZ(s);
  ll ans = 0;
  for (int i = m; i <= n; i++) {
    ans += C(i - 1, m - 1) * p0w(25, i - m) % mod * p0w(26, n - i) % mod;
    ans %= mod;
  }
  cout << ans;
  return 0;
}


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

#define fi first
#define se second
#define SZ(x) (int)x.size()
#define ll long long
#define pb push_back
#define pq priority_queue
#define pii pair<int, int>
#define mod 1000000007
#define inf 0x3f3f3f3f
#define debug(x) cerr << #x << "=" << x << '\n'
#define rep(i, a, b) for (int i = a; i < (b); i++)

const int maxn = 3e6 + 10;

int n, m;
ll fac[maxn];

ll p0w(ll base, int p) {
  ll res = 1;
  while (p) {
    if (p % 2 == 1)
      res *= base, res %= mod;
    base = base * base % mod;
    p >>= 1;
  }
  return res;
}

ll C(int x, int y) {
  return fac[x] * p0w(fac[x - y], mod - 2) % mod * p0w(fac[y], mod - 2) % mod;
}

int main() {
  std::ios::sync_with_stdio(false);
  fac[0] = 1;
  rep(i, 1, maxn) fac[i] = fac[i - 1] * (ll)i % mod;
  cin >> n;
  string s;
  cin >> s;
  n += SZ(s);
  int m = SZ(s);
  ll ans = 0;
  for (int i = m; i <= n; i++) {
    ans += C(i - 1, m - 1) * p0w(25, i - m) % mod * p0w(26, n - i) % mod;
    ans %= mod;
  }
  cout << ans;
  return 0;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int N = 1000000 + 5, yzh = 1e9 + 7;

int k, n, fac[N], ifac[N];
char ch[N];

int quick_pow(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1)
      ans = 1ll * a * ans % yzh;
    b >>= 1, a = 1ll * a * a % yzh;
  }
  return ans;
}
int C(int n, int m) { return 1ll * fac[n] * ifac[m] % yzh * ifac[n - m] % yzh; }
int main() {
  scanf("%d%s", &k, ch + 1);
  n = strlen(ch + 1);
  ifac[0] = ifac[1] = fac[0] = 1;
  for (int i = 2; i <= n + k; i++)
    ifac[i] = -1ll * yzh / i * ifac[yzh % i] % yzh;
  for (int i = 1; i <= n + k; i++) {
    fac[i] = 1ll * fac[i - 1] * i % yzh;
    ifac[i] = 1ll * ifac[i] * ifac[i - 1] % yzh;
  }
  int ans = 0;
  for (int i = 0; i <= k; i++)
    (ans += 1ll * quick_pow(25, k - i) * quick_pow(26, i) % yzh *
            C(n + k - i - 1, n - 1) % yzh) %= yzh;
  printf("%d\n", (ans + yzh) % yzh);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 2000000 + 5, yzh = 1e9 + 7;

int k, n, fac[N], ifac[N];
char ch[N];

int quick_pow(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1)
      ans = 1ll * a * ans % yzh;
    b >>= 1, a = 1ll * a * a % yzh;
  }
  return ans;
}
int C(int n, int m) { return 1ll * fac[n] * ifac[m] % yzh * ifac[n - m] % yzh; }
int main() {
  scanf("%d%s", &k, ch + 1);
  n = strlen(ch + 1);
  ifac[0] = ifac[1] = fac[0] = 1;
  for (int i = 2; i <= n + k; i++)
    ifac[i] = -1ll * yzh / i * ifac[yzh % i] % yzh;
  for (int i = 1; i <= n + k; i++) {
    fac[i] = 1ll * fac[i - 1] * i % yzh;
    ifac[i] = 1ll * ifac[i] * ifac[i - 1] % yzh;
  }
  int ans = 0;
  for (int i = 0; i <= k; i++)
    (ans += 1ll * quick_pow(25, k - i) * quick_pow(26, i) % yzh *
            C(n + k - i - 1, n - 1) % yzh) %= yzh;
  printf("%d\n", (ans + yzh) % yzh);
  return 0;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
#define MAX 1000001
ll 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;
  }
}
ll COM(ll n, ll k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll modpow(ll a, ll n, ll mod = MOD) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
int main() {
  ll k;
  cin >> k;
  string s;
  cin >> s;
  ll n = s.size();
  ll ans = 0;
  COMinit();
  for (int i = 0; i <= k; i++) {
    ans +=
        (COM(k + n - i - 1, n - 1) * modpow(25, k - i) % MOD) * modpow(26, i);
    ans %= MOD;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
#define MAX 2000001
ll 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;
  }
}
ll COM(ll n, ll k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll modpow(ll a, ll n, ll mod = MOD) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
int main() {
  ll k;
  cin >> k;
  string s;
  cin >> s;
  ll n = s.size();
  ll ans = 0;
  COMinit();
  for (int i = 0; i <= k; i++) {
    ans +=
        (COM(k + n - i - 1, n - 1) * modpow(25, k - i) % MOD) * modpow(26, i);
    ans %= MOD;
  }
  cout << ans << endl;
}
Problem p02632 (C++)

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

const int mod = 1e9 + 7;

long long mpow(long long a, int n) {
  if (n == 0)
    return 1;
  if (n == 1)
    return a;
  if (n % 2)
    return (a * (mpow(a, n - 1) % mod)) % mod;
  else {
    long long tmp = mpow(a, n / 2) % mod;
    return tmp * tmp % mod;
  }
}

const int MAX = 1000001;
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 nCk(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;
}

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

  COMinit();

  long long ans = 0;
  for (int i = 0; i <= k; i++) {
    ans = (ans + mpow(26, i) * mpow(25, k - i) % mod *
                     (nCk(s.size() + k - 1 - i, s.size() - 1)) % mod) %
          mod;
  }

  cout << ans << endl;
  return 0;
}


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

const int mod = 1e9 + 7;

long long mpow(long long a, int n) {
  if (n == 0)
    return 1;
  if (n == 1)
    return a;
  if (n % 2)
    return (a * (mpow(a, n - 1) % mod)) % mod;
  else {
    long long tmp = mpow(a, n / 2) % mod;
    return tmp * tmp % mod;
  }
}

const int MAX = 2000006;
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 nCk(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;
}

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

  COMinit();

  long long ans = 0;
  for (int i = 0; i <= k; i++) {
    ans = (ans + mpow(26, i) * mpow(25, k - i) % mod *
                     (nCk(s.size() + k - 1 - i, s.size() - 1)) % mod) %
          mod;
  }

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define Sz(a) ((int)(a).size())
const int maxn = 1000009;
const int MOD = 1e9 + 7;
int64_t fac[maxn], invfac[maxn];
int64_t pw(int64_t a, int64_t b) {
  int64_t c = 1;
  while (b) {
    if (b & 1ll)
      c = c * a % MOD;
    b >>= 1;
    a = a * a % MOD;
  }
  return c;
}
int64_t C(int a, int b) {
  return fac[a] * invfac[b] % MOD * invfac[a - b] % MOD;
}
int main() {
#ifdef LOCAL
  freopen("a.in", "r", stdin);
#endif
  ios_base::sync_with_stdio(false), cout.tie(0), cin.tie(0);
  fac[0] = 1;
  for (int i = 1; i < maxn; ++i)
    fac[i] = fac[i - 1] * i % MOD;
  invfac[maxn - 1] = pw(fac[maxn - 1], MOD - 2);
  for (int i = maxn - 2; i >= 0; --i)
    invfac[i] = invfac[i + 1] * (i + 1) % MOD;
  int K, n;
  string s;
  cin >> K >> s;
  n = Sz(s);
  int64_t ans = 1, deg = 1;
  for (int i = 0; i < K; ++i) {
    deg = deg * 25 % MOD;
    ans = (ans * 26 + C(n + i, n - 1) * deg) % MOD;
  }
  cout << ans << "\n";

  return 0;
}
// 2020.06.23 19:49:09


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define Sz(a) ((int)(a).size())
const int maxn = 2000009;
const int MOD = 1e9 + 7;
int64_t fac[maxn], invfac[maxn];
int64_t pw(int64_t a, int64_t b) {
  int64_t c = 1;
  while (b) {
    if (b & 1ll)
      c = c * a % MOD;
    b >>= 1;
    a = a * a % MOD;
  }
  return c;
}
int64_t C(int a, int b) {
  return fac[a] * invfac[b] % MOD * invfac[a - b] % MOD;
}
int main() {
#ifdef LOCAL
  freopen("a.in", "r", stdin);
#endif
  ios_base::sync_with_stdio(false), cout.tie(0), cin.tie(0);
  fac[0] = 1;
  for (int i = 1; i < maxn; ++i)
    fac[i] = fac[i - 1] * i % MOD;
  invfac[maxn - 1] = pw(fac[maxn - 1], MOD - 2);
  for (int i = maxn - 2; i >= 0; --i)
    invfac[i] = invfac[i + 1] * (i + 1) % MOD;
  int K, n;
  string s;
  cin >> K >> s;
  n = Sz(s);
  int64_t ans = 1, deg = 1;
  for (int i = 0; i < K; ++i) {
    deg = deg * 25 % MOD;
    ans = (ans * 26 + C(n + i, n - 1) * deg) % MOD;
  }
  cout << ans << "\n";

  return 0;
}
// 2020.06.23 19:49:09
Problem p02632 (C++)

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

#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define REPV(iter, v)                                                          \
  for (auto(iter) = (v).begin(); (iter) != (v).end(); ++(iter))
#define ALL(v) (v).begin(), (v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

const ll MAX = 510000;

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

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (ll 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;
  }
}

// 二項係数計算
ll COM(ll n, ll k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  ll K;
  cin >> K;
  string S;
  cin >> S;
  ll N = S.size();
  COMinit();

  vector<ll> p25(K + 1), p26(K + 1);
  p25[0] = 1;
  p26[0] = 1;
  REP(i, K) {
    p25[i + 1] = (p25[i] * 25) % MOD;
    p26[i + 1] = (p26[i] * 26) % MOD;
  }
  ll ans = 0;
  REP(i, K + 1) {
    ll t;
    t = (p25[K - i] * p26[i]) % MOD;
    t = (t * (COM(K - i + N - 1, N - 1))) % MOD;
    ans = (ans + t) % MOD;
  }
  cout << ans << endl;
}


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

#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define REPV(iter, v)                                                          \
  for (auto(iter) = (v).begin(); (iter) != (v).end(); ++(iter))
#define ALL(v) (v).begin(), (v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

const ll MAX = 2000001;

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

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (ll 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;
  }
}

// 二項係数計算
ll COM(ll n, ll k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  ll K;
  cin >> K;
  string S;
  cin >> S;
  ll N = S.size();
  COMinit();

  vector<ll> p25(K + 1), p26(K + 1);
  p25[0] = 1;
  p26[0] = 1;
  REP(i, K) {
    p25[i + 1] = (p25[i] * 25) % MOD;
    p26[i + 1] = (p26[i] * 26) % MOD;
  }
  ll ans = 0;
  REP(i, K + 1) {
    ll t;
    t = (p25[K - i] * p26[i]) % MOD;
    t = (t * (COM(K - i + N - 1, N - 1))) % MOD;
    ans = (ans + t) % MOD;
  }
  cout << ans << endl;
}
Problem p02632 (C++)

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

#define int long long

using namespace std;

const int MOD = 1e9 + 7;

const int MAXN = 1e6 + 100;

int qpow(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1)
      res = res * a % MOD;
    a = a * a % MOD;
    b /= 2;
  }
  return res;
}

int inv(int x) { return qpow(x, MOD - 2); }

int fact[MAXN];

int comb(int n, int k) {
  return fact[n] * inv(fact[n - k] * fact[k] % MOD) % MOD;
}

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  fact[0] = 1;
  for (int i = 1; i < MAXN; i++)
    fact[i] = fact[i - 1] * i % MOD;

  int K;
  string S;

  cin >> K >> S;

  int N = S.size();

  int tot = qpow(26, K + N);

  for (int i = 0; i < N; i++) {
    tot = (tot + MOD - comb(N + K, i) * qpow(25, N + K - i) % MOD) % MOD;
  }

  cout << tot << '\n';

  return 0;
}

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

#define int long long

using namespace std;

const int MOD = 1e9 + 7;

const int MAXN = 2e6 + 100;

int qpow(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1)
      res = res * a % MOD;
    a = a * a % MOD;
    b /= 2;
  }
  return res;
}

int inv(int x) { return qpow(x, MOD - 2); }

int fact[MAXN];

int comb(int n, int k) {
  return fact[n] * inv(fact[n - k] * fact[k] % MOD) % MOD;
}

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  fact[0] = 1;
  for (int i = 1; i < MAXN; i++)
    fact[i] = fact[i - 1] * i % MOD;

  int K;
  string S;

  cin >> K >> S;

  int N = S.size();

  int tot = qpow(26, K + N);

  for (int i = 0; i < N; i++) {
    tot = (tot + MOD - comb(N + K, i) * qpow(25, N + K - i) % MOD) % MOD;
  }

  cout << tot << '\n';

  return 0;
}