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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define MOD 1000000007
#define N 200123
#define ll long long

using namespace std;

char cs[N];
int k, n, m;
string s;
ll fat[N], inv_fat[N], p[N], z[N];

ll gcd(ll a, ll b, ll &x, ll &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  ll x1, y1;
  ll g = gcd(b, a % b, x1, y1);
  x = y1;
  y = x1 - ((a / b) * y1);
  return g;
}

ll inv(ll a) {
  ll x, y;
  gcd(a, MOD, x, y);
  return (x + MOD) % MOD;
}

ll C(int a, int b) {
  return (((fat[a] * inv_fat[b]) % MOD) * inv_fat[a - b]) % MOD;
}

ll partial, ans;

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

  n = strlen(cs);
  fat[0] = inv_fat[0] = p[0] = z[0] = 1;
  for (int i = 1; i <= n + k + 5; ++i) {
    fat[i] = (fat[i - 1] * i) % MOD;
    inv_fat[i] = inv(fat[i]);
    p[i] = (p[i - 1] * 25LL) % MOD;
    z[i] = (z[i - 1] * 26LL) % MOD;
  }

  m = n - 1;
  for (int i = n; i <= n + k; ++i) {
    partial = (C(i - 1, m) * p[i - m - 1]) % MOD;
    // printf("%d %d %lld\n",i - 1, m,  C(i - 1, m));

    ans = (ans + ((partial * z[n + k - i]) % MOD)) % MOD;

    // printf("%d %lld\n", n + k - i, z[n + k - i]);
  }

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

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define MOD 1000000007
#define N 2000123
#define ll long long

using namespace std;

char cs[N];
int k, n, m;
string s;
ll fat[N], inv_fat[N], p[N], z[N];

ll gcd(ll a, ll b, ll &x, ll &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  ll x1, y1;
  ll g = gcd(b, a % b, x1, y1);
  x = y1;
  y = x1 - ((a / b) * y1);
  return g;
}

ll inv(ll a) {
  ll x, y;
  gcd(a, MOD, x, y);
  return (x + MOD) % MOD;
}

ll C(int a, int b) {
  return (((fat[a] * inv_fat[b]) % MOD) * inv_fat[a - b]) % MOD;
}

ll partial, ans;

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

  n = strlen(cs);
  fat[0] = inv_fat[0] = p[0] = z[0] = 1;
  for (int i = 1; i <= n + k + 5; ++i) {
    fat[i] = (fat[i - 1] * i) % MOD;
    inv_fat[i] = inv(fat[i]);
    p[i] = (p[i - 1] * 25LL) % MOD;
    z[i] = (z[i - 1] * 26LL) % MOD;
  }

  m = n - 1;
  for (int i = n; i <= n + k; ++i) {
    partial = (C(i - 1, m) * p[i - m - 1]) % MOD;
    // printf("%d %d %lld\n",i - 1, m,  C(i - 1, m));

    ans = (ans + ((partial * z[n + k - i]) % MOD)) % MOD;

    // printf("%d %lld\n", n + k - i, z[n + k - i]);
  }

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

  return 0;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template <typename T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef tuple<ll, ll, ll> tlll;
typedef tuple<int, int, int> tiii;
const ll mod = 1e9 + 7;
const int inf = 1 << 30;

const int MAX = 200001; // nCrのnのMAX+1
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(int n, int k) { // 1≦k≦n≦10^7
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
// Add cominit(); in main function.

ll rui(ll a, ll n) {
  ll ans = 1;
  while (n > 0) {
    if (n & 1)
      ans = ans * a % mod;
    a = a * a % mod;
    n /= 2;
  }
  return ans;
}

int main() {
  cominit();
  int k;
  cin >> k;
  string s;
  cin >> s;
  int n = s.size();
  k = k + n;
  ll ans = 0;
  for (int i = n; i <= k; i++) {
    ans += rui(26, k - i) * com(i - 1, n - 1) % mod * rui(25, i - n) % mod;
    ans %= mod;
  }
  cout << ans << endl;
}

Fixed submission:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template <typename T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef tuple<ll, ll, ll> tlll;
typedef tuple<int, int, int> tiii;
const ll mod = 1e9 + 7;
const int inf = 1 << 30;

const int MAX = 2e6 + 1; // nCrのnのMAX+1
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(int n, int k) { // 1≦k≦n≦10^7
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
// Add cominit(); in main function.

ll rui(ll a, ll n) {
  ll ans = 1;
  while (n > 0) {
    if (n & 1)
      ans = ans * a % mod;
    a = a * a % mod;
    n /= 2;
  }
  return ans;
}

int main() {
  cominit();
  int k;
  cin >> k;
  string s;
  cin >> s;
  int n = s.size();
  k = k + n;
  ll ans = 0;
  for (int i = n; i <= k; i++) {
    ans += rui(26, k - i) * com(i - 1, n - 1) % mod * rui(25, i - n) % mod;
    ans %= mod;
  }
  cout << ans << endl;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <cstring>
using namespace std;

const int md = 1000000007;

const int N = 1000000;
int fact[N + 1], factinv[N + 1];

inline int add(int a, int b) {
  a += b;
  if (a >= md)
    a -= md;
  return a;
}
inline int mul(int a, int b) { return (int)((long long)a * b % md); }
inline int po(int a, int b) {
  int r = 1;
  while (b) {
    if (b & 1)
      r = mul(r, a);
    a = mul(a, a);
    b >>= 1;
  }
  return r;
}
inline int inv(int a) { return po(a, md - 2); }
inline int di(int a, int b) { return mul(a, inv(b)); }
void init() {
  fact[0] = factinv[0] = 1;
  for (int i = 1; i <= N; ++i) {
    fact[i] = mul(fact[i - 1], i);
    factinv[i] = inv(fact[i]);
  }
}
inline int Cnk(int a, int b) {
  return mul(fact[a], mul(factinv[b], factinv[a - b]));
}

char s[N + 1];

int main() {
  init();
  int n;
  scanf("%d%s", &n, s);
  int k = strlen(s);
  int ans = 0;
  for (int i = k; i <= n + k; ++i)
    ans =
        add(ans, mul(po(26, n + k - i), mul(Cnk(i - 1, k - 1), po(25, i - k))));
  printf("%d\n", ans);
  return 0;
}


Fixed submission:
#include <cstdio>
#include <cstring>
using namespace std;

const int md = 1000000007;

const int N = 2000000;
int fact[N + 1], factinv[N + 1];

inline int add(int a, int b) {
  a += b;
  if (a >= md)
    a -= md;
  return a;
}
inline int mul(int a, int b) { return (int)((long long)a * b % md); }
inline int po(int a, int b) {
  int r = 1;
  while (b) {
    if (b & 1)
      r = mul(r, a);
    a = mul(a, a);
    b >>= 1;
  }
  return r;
}
inline int inv(int a) { return po(a, md - 2); }
inline int di(int a, int b) { return mul(a, inv(b)); }
void init() {
  fact[0] = factinv[0] = 1;
  for (int i = 1; i <= N; ++i) {
    fact[i] = mul(fact[i - 1], i);
    factinv[i] = inv(fact[i]);
  }
}
inline int Cnk(int a, int b) {
  return mul(fact[a], mul(factinv[b], factinv[a - b]));
}

char s[N + 1];

int main() {
  init();
  int n;
  scanf("%d%s", &n, s);
  int k = strlen(s);
  int ans = 0;
  for (int i = k; i <= n + k; ++i)
    ans =
        add(ans, mul(po(26, n + k - i), mul(Cnk(i - 1, k - 1), po(25, i - k))));
  printf("%d\n", ans);
  return 0;
}
Problem p02632 (C++)

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

const int MOD = 1e9 + 7;
const int MAX_N = 1e6 + 10;
int K;
string S;

ll fact[MAX_N];
ll invf[MAX_N];

ll powmod(ll x, int y) {
  ll res = 1;
  while (y) {
    if (y & 1)
      (res *= x) %= MOD;
    (x *= x) %= MOD;
    y >>= 1;
  }
  return res;
}

ll nCk(int n, int k) {
  if (k < 0 || k > n)
    return 0;
  return (((fact[n] * invf[n - k]) % MOD) * invf[k]) % MOD;
}

void solve() {
  fact[0] = 1;
  for (int i = 1; i < MAX_N; ++i)
    fact[i] = 1LL * i * fact[i - 1] % MOD;
  invf[MAX_N - 1] = powmod(fact[MAX_N - 1], MOD - 2);
  for (int i = MAX_N - 2; i >= 0; --i)
    invf[i] = 1LL * invf[i + 1] * (i + 1) % MOD;

  ll res = 0;
  const int n = S.length();
  for (int len = 0; len < n; ++len) {
    (res += 1LL * nCk(n + K, len) * powmod(25, n + K - len) % MOD) %= MOD;
  }
  ll ans = (powmod(26, n + K) - res + MOD) % MOD;
  cout << ans;
}

int main() {
  cin >> K >> S;
  solve();
  return 0;
}

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

const int MOD = 1e9 + 7;
const int MAX_N = 2e6 + 10;
int K;
string S;

ll fact[MAX_N];
ll invf[MAX_N];

ll powmod(ll x, int y) {
  ll res = 1;
  while (y) {
    if (y & 1)
      (res *= x) %= MOD;
    (x *= x) %= MOD;
    y >>= 1;
  }
  return res;
}

ll nCk(int n, int k) {
  if (k < 0 || k > n)
    return 0;
  return (((fact[n] * invf[n - k]) % MOD) * invf[k]) % MOD;
}

void solve() {
  fact[0] = 1;
  for (int i = 1; i < MAX_N; ++i)
    fact[i] = 1LL * i * fact[i - 1] % MOD;
  invf[MAX_N - 1] = powmod(fact[MAX_N - 1], MOD - 2);
  for (int i = MAX_N - 2; i >= 0; --i)
    invf[i] = 1LL * invf[i + 1] * (i + 1) % MOD;

  ll res = 0;
  const int n = S.length();
  for (int len = 0; len < n; ++len) {
    (res += 1LL * nCk(n + K, len) * powmod(25, n + K - len) % MOD) %= MOD;
  }
  ll ans = (powmod(26, n + K) - res + MOD) % MOD;
  cout << ans;
}

int main() {
  cin >> K >> S;
  solve();
  return 0;
}
Problem p02632 (C++)

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

using namespace std;
using ll = long long;
using ld = long double;

const int MAX = 510000;
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;
}

// #define int long long
// signed main(){
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int k;
  string s;
  cin >> k >> s;

  COMinit();

  ll ts[k + 1];
  ll tf[k + 1];
  ts[0] = 1;
  tf[0] = 1;
  for (int i = 0; i < k; i++) {
    ts[i + 1] = (ts[i] * 26) % MOD;
    tf[i + 1] = (tf[i] * 25) % MOD;
  }

  ll ans = 0;
  int n = s.size() + k;

  for (int i = 0; i <= k; i++) {
    ll add = ((ts[i] * tf[k - i]) % MOD) * COM(n - i - 1, n - k - 1);
    ans += (add % MOD);
  }
  cout << ans % MOD << "\n";
  return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;

const int MAX = 5100000;
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;
}

// #define int long long
// signed main(){
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int k;
  string s;
  cin >> k >> s;

  COMinit();

  ll ts[k + 1];
  ll tf[k + 1];
  ts[0] = 1;
  tf[0] = 1;
  for (int i = 0; i < k; i++) {
    ts[i + 1] = (ts[i] * 26) % MOD;
    tf[i + 1] = (tf[i] * 25) % MOD;
  }

  ll ans = 0;
  int n = s.size() + k;

  for (int i = 0; i <= k; i++) {
    ll add = ((ts[i] * tf[k - i]) % MOD) * COM(n - i - 1, n - k - 1);
    ans += (add % MOD);
  }
  cout << ans % MOD << "\n";
  return 0;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits.h>
#include <map>
#include <set>
#include <utility>
#include <vector>
using namespace std;
using P = pair<int, int>;
using ll = long long;
constexpr int MOD = 1000000007;
constexpr int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
bool COMinited = false;
long long COM(int n, int k) {
  if (COMinited == false) {
    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;
    }
    COMinited = true;
  }
  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 = MOD) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); }
int main() {
  int k;
  cin >> k;
  string s;
  cin >> s;
  int t = s.size();
  int ret = 0;
  for (int i = t; i <= k + t; i++) {
    ret += modpow(25, k + t - i) * COM(k + t, i) % MOD;
    ret %= MOD;
  }
  cout << ret << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits.h>
#include <map>
#include <set>
#include <utility>
#include <vector>
using namespace std;
using P = pair<int, int>;
using ll = long long;
constexpr int MOD = 1000000007;
constexpr int MAX = 2000100;
long long fac[MAX], finv[MAX], inv[MAX];
bool COMinited = false;
long long COM(int n, int k) {
  if (COMinited == false) {
    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;
    }
    COMinited = true;
  }
  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 = MOD) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); }
int main() {
  int k;
  cin >> k;
  string s;
  cin >> s;
  int t = s.size();
  int ret = 0;
  for (int i = t; i <= k + t; i++) {
    ret += modpow(25, k + t - i) * COM(k + t, i) % MOD;
    ret %= MOD;
  }
  cout << ret << endl;
}
Problem p02632 (C++)

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

ll pd[1000010];
ll rd[1000010];
ll Ep(int x, int y) {
  if (y == 0)
    return 1;
  if (y == 1)
    return x;
  ll r = Ep(x, y / 2);
  if (y % 2 == 1)
    return r * r % MOD * x % MOD;
  else
    return r * r % MOD;
}
ll Ftl(ll x) {
  if (x == 1 || x == 0)
    return 1;
  if (pd[x] != 0)
    return pd[x];
  return pd[x] = Ftl(x - 1) * x % MOD;
}
ll rFtl(ll x) {
  if (x == 1 || x == 0)
    return 1;
  if (rd[x] != 0)
    return rd[x];
  return rd[x] = rFtl(x - 1) * Ep(x, MOD - 2) % MOD;
}
ll comb(ll m, ll n) {
  if (m < n)
    return 0;
  return Ftl(m) * rFtl(n) % MOD * rFtl(m - n) % MOD;
}

int main() {
  int k;
  string s;
  cin >> k >> s;
  int k2 = s.size();
  ll ans = 0;
  for (int i = 0; i <= k; ++i) {
    ans += Ep(26, k - i) * Ep(25, i) % MOD * comb(k2 + i - 1, i) % MOD;
    ans %= MOD;
    // cout << ans << endl;
  }
  cout << ans << endl;
}

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

ll pd[2000010];
ll rd[2000010];
ll Ep(int x, int y) {
  if (y == 0)
    return 1;
  if (y == 1)
    return x;
  ll r = Ep(x, y / 2);
  if (y % 2 == 1)
    return r * r % MOD * x % MOD;
  else
    return r * r % MOD;
}
ll Ftl(ll x) {
  if (x == 1 || x == 0)
    return 1;
  if (pd[x] != 0)
    return pd[x];
  return pd[x] = Ftl(x - 1) * x % MOD;
}
ll rFtl(ll x) {
  if (x == 1 || x == 0)
    return 1;
  if (rd[x] != 0)
    return rd[x];
  return rd[x] = rFtl(x - 1) * Ep(x, MOD - 2) % MOD;
}
ll comb(ll m, ll n) {
  if (m < n)
    return 0;
  return Ftl(m) * rFtl(n) % MOD * rFtl(m - n) % MOD;
}

int main() {
  int k;
  string s;
  cin >> k >> s;
  int k2 = s.size();
  ll ans = 0;
  for (int i = 0; i <= k; ++i) {
    ans += Ep(26, k - i) * Ep(25, i) % MOD * comb(k2 + i - 1, i) % MOD;
    ans %= MOD;
    // cout << ans << endl;
  }
  cout << ans << endl;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define N 1000010
#define Mod 1000000007
char s[N];
int fac[N], inv[N];
inline void init(int n) {
  fac[0] = fac[1] = inv[0] = inv[1] = 1;
  for (int i = 1; i <= n; i++)
    fac[i] = 1LL * fac[i - 1] * i % Mod;
  for (int i = 2; i <= n; i++)
    inv[i] = 1LL * (Mod - Mod / i) * inv[Mod % i] % Mod;
  for (int i = 2; i <= n; i++)
    inv[i] = 1LL * inv[i - 1] * inv[i] % Mod;
}
inline int Pow(int a, int b, int p = Mod) {
  int res = 1;
  for (; b; b >>= 1, a = 1LL * a * a % p)
    if (b & 1)
      res = 1LL * res * a % p;
  return res;
}
inline int C(int n, int m) {
  return 1LL * fac[n] * inv[m] % Mod * inv[n - m] % Mod;
}
inline int read() {
  int x = 0;
  char ch = getchar();
  while (!isdigit(ch))
    ch = getchar();
  while (isdigit(ch))
    x = x * 10 + ch - '0', ch = getchar();
  return x;
}
int main() {
  int n = read();
  scanf("%s", s);
  int m = strlen(s), ans = 0;
  n += m;
  init(n);
  for (int i = m; i <= n; i++)
    (ans += 1LL * Pow(25, i - m) * Pow(26, n - i) % Mod * C(i - 1, m - 1) %
            Mod) %= Mod;
  return printf("%d\n", ans), 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define N 2000010
#define Mod 1000000007
char s[N];
int fac[N], inv[N];
inline void init(int n) {
  fac[0] = fac[1] = inv[0] = inv[1] = 1;
  for (int i = 1; i <= n; i++)
    fac[i] = 1LL * fac[i - 1] * i % Mod;
  for (int i = 2; i <= n; i++)
    inv[i] = 1LL * (Mod - Mod / i) * inv[Mod % i] % Mod;
  for (int i = 2; i <= n; i++)
    inv[i] = 1LL * inv[i - 1] * inv[i] % Mod;
}
inline int Pow(int a, int b, int p = Mod) {
  int res = 1;
  for (; b; b >>= 1, a = 1LL * a * a % p)
    if (b & 1)
      res = 1LL * res * a % p;
  return res;
}
inline int C(int n, int m) {
  return 1LL * fac[n] * inv[m] % Mod * inv[n - m] % Mod;
}
inline int read() {
  int x = 0;
  char ch = getchar();
  while (!isdigit(ch))
    ch = getchar();
  while (isdigit(ch))
    x = x * 10 + ch - '0', ch = getchar();
  return x;
}
int main() {
  int n = read();
  scanf("%s", s);
  int m = strlen(s), ans = 0;
  n += m;
  init(n);
  for (int i = m; i <= n; i++)
    (ans += 1LL * Pow(25, i - m) * Pow(26, n - i) % Mod * C(i - 1, m - 1) %
            Mod) %= Mod;
  return printf("%d\n", ans), 0;
}
Problem p02632 (C++)

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

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef unsigned long long ull;

#define faster                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(nullptr);                                                            \
  cout.tie(nullptr);
#define debug(x) cout << #x << " = " << (x) << endl
#define nl "\n"
#define sp " "

const int MOD = 1e9 + 7, SZ = 1e6 + 5;
int fact[SZ], N;
string s;

ll powmodk(ll a, ll k, ll m) {
  if (k == 0)
    return 1;
  ll r = powmodk(a, k / 2, m);
  r = (r * r) % m;
  if (k % 2)
    r = (r * a) % m;
  return r;
}

inline ll fix(ll x) { return (x % MOD + MOD) % MOD; }

inline ll modinverse(ll a) { return powmodk(fix(a), MOD - 2, MOD); }

ll nck(int n, int k) {
  ll num = fact[n];
  ll den = modinverse(1LL * fact[n - k] * fact[k]);
  return fix(num * den);
}

int main() {
  faster fact[0] = 1;
  for (int i = 1; i < SZ; i++) {
    fact[i] = fix(1LL * i * fact[i - 1]);
  }

  cin >> N >> s;
  N += int(s.length());
  ll ans = powmodk(26, N, MOD);

  for (int i = 0; i < int(s.size()); i++) {
    ll pow = powmodk(25, N - i, MOD);
    ans -= fix(nck(N, i) * pow);
  }

  cout << fix(ans) << nl;
}


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

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef unsigned long long ull;

#define faster                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(nullptr);                                                            \
  cout.tie(nullptr);
#define debug(x) cout << #x << " = " << (x) << endl
#define nl "\n"
#define sp " "

const int MOD = 1e9 + 7, SZ = 3e6 + 5;
int fact[SZ], N;
string s;

ll powmodk(ll a, ll k, ll m) {
  if (k == 0)
    return 1;
  ll r = powmodk(a, k / 2, m);
  r = (r * r) % m;
  if (k % 2)
    r = (r * a) % m;
  return r;
}

inline ll fix(ll x) { return (x % MOD + MOD) % MOD; }

inline ll modinverse(ll a) { return powmodk(fix(a), MOD - 2, MOD); }

ll nck(int n, int k) {
  ll num = fact[n];
  ll den = modinverse(1LL * fact[n - k] * fact[k]);
  return fix(num * den);
}

int main() {
  faster fact[0] = 1;
  for (int i = 1; i < SZ; i++) {
    fact[i] = fix(1LL * i * fact[i - 1]);
  }

  cin >> N >> s;
  N += int(s.length());
  ll ans = powmodk(26, N, MOD);

  for (int i = 0; i < int(s.size()); i++) {
    ll pow = powmodk(25, N - i, MOD);
    ans -= fix(nck(N, i) * pow);
  }

  cout << fix(ans) << nl;
}
Problem p02632 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod = 1000000007;
const ll inf = 1e18;

ll factmod(ll a, ll b, ll m) {
  if (a < b)
    return 0;
  ll s = 1;
  while (a >= b) {
    s = s * a % m;
    a -= 1;
  }
  return s;
}

ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}

ll combmod(ll a, ll b, ll m) {
  if (b == 0)
    return 1;
  ll c = factmod(a, a - b + 1, m);
  ll d = modinv(factmod(b, 1, m), m);
  ll e = (c * d) % m;
  return e;
}

ll powmod(ll a, ll n, ll m) {
  if (n == 0)
    return 1;

  if (n % 2 == 0) {
    ll r = powmod(a, n / 2, m);
    return r * r % m;
  }

  return a * powmod(a, n - 1, m) % m;
}

int main() {

  ll k;
  string s;
  cin >> k >> s;
  ll n = s.size();

  ll t = 0;
  for (int i = 0; i <= k; i++) {
    ll a = 1;
    a *= combmod(n + k - i - 1, n - 1, mod);
    a %= mod;
    a *= powmod(25, k - i, mod);
    a %= mod;
    a *= powmod(26, i, mod);
    a %= mod;
    t += a;
    t %= mod;
  }

  cout << t << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod = 1000000007;
const ll inf = 1e18;

ll factmod(ll a, ll b, ll m) {
  if (a < b)
    return 0;
  ll s = 1;
  while (a >= b) {
    s = s * a % m;
    a -= 1;
  }
  return s;
}

ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}

ll combmod(ll a, ll b, ll m) {
  if (b == 0)
    return 1;
  ll c = factmod(a, a - b + 1, m);
  ll d = modinv(factmod(b, 1, m), m);
  ll e = (c * d) % m;
  return e;
}

ll powmod(ll a, ll n, ll m) {
  if (n == 0)
    return 1;

  if (n % 2 == 0) {
    ll r = powmod(a, n / 2, m);
    return r * r % m;
  }

  return a * powmod(a, n - 1, m) % m;
}

int main() {

  ll k;
  string s;
  cin >> k >> s;
  ll n = s.size();

  ll t = 0;
  ll c, d, e;
  ll a = 1;
  c = combmod(n + k - 1, n - 1, mod);
  d = powmod(25, k, mod);
  e = powmod(26, 0, mod);
  a *= c;
  a %= mod;
  a *= d;
  a %= mod;
  a *= e;
  a %= mod;
  t += a;
  t %= mod;

  for (int i = 1; i <= k; i++) {
    a = 1;
    c = (((c * modinv(n + k - i, mod)) % mod) * (k - i + 1)) % mod;
    a *= c;
    d = (d * modinv(25, mod)) % mod;
    a = (a * d) % mod;
    e = e * 26 % mod;
    a = a * e % mod;
    t += a;
    t %= mod;
  }

  cout << t << endl;
}
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;

typedef long long ll;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

// combination
// O(n)

const ll MOD = 1e9 + 7;
const ll max_n = 1010101;
ll fact[max_n];
bool fact_init = false;

ll powmod(ll a, ll b) {
  if (b == 0)
    return 1;
  if (b % 2 == 1)
    return a * powmod(a, b - 1) % MOD;

  ll d = powmod(a, b / 2) % MOD;
  return d * d % MOD;
}

ll comb(ll n, ll k) {
  if (!fact_init) {
    fact[0] = 1;
    fact[1] = 1;

    for (ll i = 2; i < max_n; i++) {
      fact[i] = fact[i - 1] * i;
      fact[i] %= MOD;
    }

    fact_init = true;
  }

  ll ret = fact[n];
  ret *= powmod(fact[k], MOD - 2);
  ret %= MOD;
  ret *= powmod(fact[n - k], MOD - 2);
  ret %= MOD;
  return ret;

  // X^(-1) = X^(p-2) (mod p) (Fermat's little theorem)
}

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

  ll k;
  cin >> k;

  string s;
  cin >> s;

  ll n = s.size();
  ll ans = 0;
  rep(i, k + 1) {
    ll t = comb(n - 1 + k - i, n - 1);
    t *= powmod(25, k - i);
    t %= MOD;

    t *= powmod(26, i);
    t %= MOD;

    ans += t;
    ans %= MOD;
  }

  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = (0); i < (n); i++)

using namespace std;

typedef long long ll;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

// combination
// O(n)

const ll MOD = 1e9 + 7;
const ll max_n = 2020202;
ll fact[max_n];
bool fact_init = false;

ll powmod(ll a, ll b) {
  if (b == 0)
    return 1;
  if (b % 2 == 1)
    return a * powmod(a, b - 1) % MOD;

  ll d = powmod(a, b / 2) % MOD;
  return d * d % MOD;
}

ll comb(ll n, ll k) {
  if (!fact_init) {
    fact[0] = 1;
    fact[1] = 1;

    for (ll i = 2; i < max_n; i++) {
      fact[i] = fact[i - 1] * i;
      fact[i] %= MOD;
    }

    fact_init = true;
  }

  ll ret = fact[n];
  ret *= powmod(fact[k], MOD - 2);
  ret %= MOD;
  ret *= powmod(fact[n - k], MOD - 2);
  ret %= MOD;
  return ret;

  // X^(-1) = X^(p-2) (mod p) (Fermat's little theorem)
}

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

  ll k;
  cin >> k;

  string s;
  cin >> s;

  ll n = s.size();
  ll ans = 0;
  rep(i, k + 1) {
    ll t = comb(n - 1 + k - i, n - 1);
    t *= powmod(25, k - i);
    t %= MOD;

    t *= powmod(26, i);
    t %= MOD;

    ans += t;
    ans %= MOD;
  }

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

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

typedef long long ll;

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

int f[N], inv[N], finv[N];
// inv[]: inverse element

int powMod(int u, int v) {
  int res = 1;
  while (v) {
    if (v & 1)
      res = (ll)res * u % MOD;
    v >>= 1;
    u = (ll)u * u % MOD;
  }
  return res;
}

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

int C(int x, int y) {
  if (y < 0)
    return 0;
  return ((ll)f[x] * finv[y] % MOD) * finv[x - y] % MOD;
}

int Lucas(int u, int v) {
  if (v == 0)
    return 1;
  return (ll)C(u % MOD, v % MOD) * Lucas(u / MOD, v / MOD) % MOD;
}

int k, n, ans;
string s;

int main() {
  ios::sync_with_stdio(false);
  initInv();
  cin >> k >> s;
  n = s.length();
  for (int pref = 0; pref <= k; pref++) {
    ans = (ans + ((ll)powMod(26ll, pref) * powMod(25ll, k - pref) % MOD *
                  Lucas(n + k - 1 - pref, n - 1) % MOD)) %
          MOD;
  }
  cout << ans << endl;
  return 0;
}

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

typedef long long ll;

const int MOD = 1e9 + 7;
const int N = 2e6 + 5;

int f[N], inv[N], finv[N];
// inv[]: inverse element

int powMod(int u, int v) {
  int res = 1;
  while (v) {
    if (v & 1)
      res = (ll)res * u % MOD;
    v >>= 1;
    u = (ll)u * u % MOD;
  }
  return res;
}

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

int C(int x, int y) {
  if (y < 0)
    return 0;
  return ((ll)f[x] * finv[y] % MOD) * finv[x - y] % MOD;
}

int Lucas(int u, int v) {
  if (v == 0)
    return 1;
  return (ll)C(u % MOD, v % MOD) * Lucas(u / MOD, v / MOD) % MOD;
}

int k, n, ans;
string s;

int main() {
  ios::sync_with_stdio(false);
  initInv();
  cin >> k >> s;
  n = s.length();
  for (int pref = 0; pref <= k; pref++) {
    ans = (ans + ((ll)powMod(26ll, pref) * powMod(25ll, k - pref) % MOD *
                  Lucas(n + k - 1 - pref, n - 1) % MOD)) %
          MOD;
  }
  cout << ans << endl;
  return 0;
}
Problem p02632 (C++)

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

using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7;
const int sz = 1e6 + 1;

int k;
string s;
ll fact[sz], inv_fact[sz];

ll bpow(ll x, ll p) {
  if (p == 0)
    return 1;
  if (p % 2)
    return (x * bpow(x, p - 1)) % mod;
  else {
    ll b = bpow(x, p / 2);
    return (b * b) % mod;
  }
}

ll inv(ll x) { return bpow(x, mod - 2); }

void calc_fact() {
  fact[0] = 1;
  inv_fact[0] = 1;
  for (int i = 1; i < sz; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
    inv_fact[i] = inv(fact[i]);
  }
}

ll cnk(ll nn, ll kk) {
  return fact[nn] * inv_fact[nn - kk] % mod * inv_fact[kk] % mod;
}

void solve() {
  cin >> k >> s;
  int n = s.size();
  calc_fact();
  ll ans = 0;
  for (int i = 0; i <= k; i++) {
    ans +=
        cnk(n + k - i - 1, n - 1) * bpow(25, k - i) % mod * bpow(26, i) % mod;
    ans %= mod;
  }
  cout << ans;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#if defined(_DEBUG)
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int q = 1;
  // cin >> q;
  for (; q > 0; q--) {
    solve();
    cout << endl;
  }
}

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

using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7;
const int sz = 2e6 + 1;

int k;
string s;
ll fact[sz], inv_fact[sz];

ll bpow(ll x, ll p) {
  if (p == 0)
    return 1;
  if (p % 2)
    return (x * bpow(x, p - 1)) % mod;
  else {
    ll b = bpow(x, p / 2);
    return (b * b) % mod;
  }
}

ll inv(ll x) { return bpow(x, mod - 2); }

void calc_fact() {
  fact[0] = 1;
  inv_fact[0] = 1;
  for (int i = 1; i < sz; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
    inv_fact[i] = inv(fact[i]);
  }
}

ll cnk(ll nn, ll kk) {
  return fact[nn] * inv_fact[nn - kk] % mod * inv_fact[kk] % mod;
}

void solve() {
  cin >> k >> s;
  int n = s.size();
  calc_fact();
  ll ans = 0;
  for (int i = 0; i <= k; i++) {
    ans +=
        cnk(n + k - i - 1, n - 1) * bpow(25, k - i) % mod * bpow(26, i) % mod;
    ans %= mod;
  }
  cout << ans;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#if defined(_DEBUG)
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int q = 1;
  // cin >> q;
  for (; q > 0; q--) {
    solve();
    cout << endl;
  }
}
Problem p02632 (C++)

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

using namespace std;

typedef long double ld;
typedef long long ll;

#define sz(x) (int)(x).size()
#define pb push_back
#define mp make_pair
#define f first
#define s second

template <typename T, typename U> bool ckmin(T &a, U b) {
  return b < a ? a = b, true : false;
}
template <typename T, typename U> bool ckmax(T &a, U b) {
  return b > a ? a = b, true : false;
}

const ll MOD = 1e9 + 7;

ll k, res = 0;
string s;
vector<ll> fac;

ll exp(ll a, ll n) {
  if (n == 0)
    return 1;
  ll tmp = exp(a, n / 2);
  tmp *= tmp;
  tmp %= MOD;
  if (n % 2)
    tmp *= a;
  tmp %= MOD;
  return tmp;
}

ll inv(ll x) { return exp(x, MOD - 2); }

ll cmb(ll c, ll k) {
  if (k > c)
    return 0;
  ll t = inv(fac[c - k]) * inv(fac[k]);
  t %= MOD;
  t *= fac[c];
  t %= MOD;
  return t;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> k >> s;
  fac.assign(1e6 + 5, 1);
  for (int i = 1; i < sz(fac); ++i) {
    fac[i] = fac[i - 1] * i;
    fac[i] %= MOD;
  }
  // characters at very end
  for (int i = 0; i <= k; ++i) {
    ll tmp = exp(26, i);
    tmp *= cmb(k - i + sz(s) - 1, sz(s) - 1);
    tmp %= MOD;
    tmp *= exp(25, k - i);
    tmp %= MOD;
    res += tmp;
    res %= MOD;
  }
  cout << res;
  return 0;
}

Fixed submission:
#include "bits/stdc++.h"

using namespace std;

typedef long double ld;
typedef long long ll;

#define sz(x) (int)(x).size()
#define pb push_back
#define mp make_pair
#define f first
#define s second

template <typename T, typename U> bool ckmin(T &a, U b) {
  return b < a ? a = b, true : false;
}
template <typename T, typename U> bool ckmax(T &a, U b) {
  return b > a ? a = b, true : false;
}

const ll MOD = 1e9 + 7;

ll k, res = 0;
string s;
vector<ll> fac;

ll exp(ll a, ll n) {
  if (n == 0)
    return 1;
  ll tmp = exp(a, n / 2);
  tmp *= tmp;
  tmp %= MOD;
  if (n % 2)
    tmp *= a;
  tmp %= MOD;
  return tmp;
}

ll inv(ll x) { return exp(x, MOD - 2); }

ll cmb(ll c, ll k) {
  if (k > c)
    return 0;
  ll t = inv(fac[c - k]) * inv(fac[k]);
  t %= MOD;
  t *= fac[c];
  t %= MOD;
  return t;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> k >> s;
  fac.assign(3e6 + 5, 1);
  for (int i = 1; i < sz(fac); ++i) {
    fac[i] = fac[i - 1] * i;
    fac[i] %= MOD;
  }
  // characters at very end
  for (int i = 0; i <= k; ++i) {
    ll tmp = exp(26, i);
    tmp *= cmb(k - i + sz(s) - 1, sz(s) - 1);
    tmp %= MOD;
    tmp *= exp(25, k - i);
    tmp %= MOD;
    res += tmp;
    res %= MOD;
  }
  cout << res;
  return 0;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<long long> vll;
typedef vector<int> vi;

#define io ios_base::sync_with_stdio(false)
#define pb push_back
#define eb emplace_back
#define mod 1000000007
#define PI 2 * acos(0.0)

const int N = 1000005;
vi fac(N);

void fcalc() {
  fac[0] = 1;
  for (int i = 1; i < N; i++)
    fac[i] = (1LL * fac[i - 1] * i) % mod;
}

ll bigmod(ll x, ll po) {
  ll res = 1;
  while (po) {
    if (po & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    po >>= 1;
  }
  return res;
}

ll bin(int n, int i) {
  return (fac[n] * (bigmod(1LL * fac[n - i] * fac[i] % mod, mod - 2) % mod)) %
         mod;
  // return ((fac[n]*bigmod(fac[i], mod-2)%mod)%mod * bigmod(fac[n-i],
  // mod-2)%mod)%mod;
}

int32_t main() {
  io;
  fcalc();
  int n;
  string s;
  cin >> n >> s;
  int m = s.size();
  n += m;
  ll ans = 1, sub = 0;
  vi p(n + 1);
  p[0] = 1;
  for (int i = 1; i <= n; i++)
    p[i] = (p[i - 1] * 25LL) % mod;
  for (int i = 1; i <= n; i++)
    ans = (ans * 26) % mod;
  for (int i = 0; i < m; i++)
    sub = (sub + bin(n, i) * p[n - i] % mod) % mod;
  cout << (ans - sub + mod) % mod;
  return 0;
}


Fixed submission:
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<long long> vll;
typedef vector<int> vi;

#define io ios_base::sync_with_stdio(false)
#define pb push_back
#define eb emplace_back
#define mod 1000000007
#define PI 2 * acos(0.0)

const int N = 2000005;
vi fac(N);

void fcalc() {
  fac[0] = 1;
  for (int i = 1; i < N; i++)
    fac[i] = (1LL * fac[i - 1] * i) % mod;
}

ll bigmod(ll x, ll po) {
  ll res = 1;
  while (po) {
    if (po & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    po >>= 1;
  }
  return res;
}

ll bin(int n, int i) {
  return (fac[n] * (bigmod(1LL * fac[n - i] * fac[i] % mod, mod - 2) % mod)) %
         mod;
  // return ((fac[n]*bigmod(fac[i], mod-2)%mod)%mod * bigmod(fac[n-i],
  // mod-2)%mod)%mod;
}

int32_t main() {
  io;
  fcalc();
  int n;
  string s;
  cin >> n >> s;
  int m = s.size();
  n += m;
  ll ans = 1, sub = 0;
  vi p(n + 1);
  p[0] = 1;
  for (int i = 1; i <= n; i++)
    p[i] = (p[i - 1] * 25LL) % mod;
  for (int i = 1; i <= n; i++)
    ans = (ans * 26) % mod;
  for (int i = 0; i < m; i++)
    sub = (sub + bin(n, i) * p[n - i] % mod) % mod;
  cout << (ans - sub + mod) % mod;
  return 0;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD 1000000007
vector<ll> fact(2000000);
void init_fact(int n) {
  fact[0] = 1;
  for (int i = 1; i < n + 1; i++) {
    fact[i] = fact[i - 1] * i;
    fact[i] %= MOD;
  }
}
ll mod_pow(ll x, ll p) {
  ll res = 1;
  ll n = x;
  while (p > 0) {
    if (p & 1 == 1)
      res = (res * n) % MOD;
    n = (n * n) % MOD;
    p = (p >> 1);
  }
  return res;
}

ll nCr(int n, int r) {
  ll res = 1;
  res *= fact[n];
  res *= mod_pow(fact[r], MOD - 2);
  res %= MOD;
  res *= mod_pow(fact[n - r], MOD - 2);
  res %= MOD;
  return res;
}
int main() {
  ll K;
  cin >> K;
  string s;
  cin >> s;
  ll S = s.size();
  init_fact(K + S);
  ll ans = 0;
  for (int i = 0; i < K + 1; i++) {
    ll tmp = nCr(S + K - i - 1, S - 1);
    tmp *= mod_pow(25, K - i);
    tmp %= MOD;
    tmp *= mod_pow(26, i);
    tmp %= MOD;
    ans += tmp;
    ans %= MOD;
  }
  cout << ans << endl;
}

Fixed submission:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD 1000000007
vector<ll> fact(2000001);
void init_fact(int n) {
  fact[0] = 1;
  for (int i = 1; i < n + 1; i++) {
    fact[i] = fact[i - 1] * i;
    fact[i] %= MOD;
  }
}
ll mod_pow(ll x, ll p) {
  ll res = 1;
  ll n = x;
  while (p > 0) {
    if (p & 1 == 1)
      res = (res * n) % MOD;
    n = (n * n) % MOD;
    p = (p >> 1);
  }
  return res;
}

ll nCr(int n, int r) {
  ll res = 1;
  res *= fact[n];
  res *= mod_pow(fact[r], MOD - 2);
  res %= MOD;
  res *= mod_pow(fact[n - r], MOD - 2);
  res %= MOD;
  return res;
}
int main() {
  ll K;
  cin >> K;
  string s;
  cin >> s;
  ll S = s.size();
  init_fact(K + S);
  ll ans = 0;
  for (int i = 0; i < K + 1; i++) {
    ll tmp = nCr(S + K - i - 1, S - 1);
    tmp *= mod_pow(25, K - i);
    tmp %= MOD;
    tmp *= mod_pow(26, i);
    tmp %= MOD;
    ans += tmp;
    ans %= MOD;
  }
  cout << ans << endl;
}
Problem p02632 (C++)

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

using namespace std;
#define sint(a) scanf("%d", &a)
#define sint2(a, b) scanf("%d %d", &a, &b)
#define sll(a) scanf("%lld", &a)
#define sll2(a, b) scanf("%lld %lld", &a, &b)
#define mem(a, i) memset(a, i, sizeof(a))
#define pb push_back
#define ll long long
#define lson node << 1
#define rson (node << 1) + 1

const int maxn = 1e6 + 10;
const ll mod = 1e9 + 7;
const double pi = acos(-1);

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

ll ji[maxn];
void init() {
  ji[0] = 1;
  for (int i = 1; i < maxn; i++)
    ji[i] = ji[i - 1] * i % mod;
}

ll c(ll a, ll n) {
  return ji[n] * qpow(ji[a], mod - 2) % mod * qpow(ji[n - a], mod - 2) % mod;
}

int main() {
  init();
  ll n;
  string s;
  cin >> n >> s;
  ll k = s.length();
  ll len = k + n;
  ll ans = 0;
  for (int i = 1; i <= len - k + 1; i++) {
    ans = (ans + qpow(26, i - 1) * qpow(25, len - i - k + 1) % mod *
                     c(k - 1, len - i) % mod) %
          mod;
  }
  cout << ans;
  return 0;
}


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

using namespace std;
#define sint(a) scanf("%d", &a)
#define sint2(a, b) scanf("%d %d", &a, &b)
#define sll(a) scanf("%lld", &a)
#define sll2(a, b) scanf("%lld %lld", &a, &b)
#define mem(a, i) memset(a, i, sizeof(a))
#define pb push_back
#define ll long long
#define lson node << 1
#define rson (node << 1) + 1

const int maxn = 3e6 + 10;
const ll mod = 1e9 + 7;
const double pi = acos(-1);

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

ll ji[maxn];
void init() {
  ji[0] = 1;
  for (int i = 1; i < maxn; i++)
    ji[i] = ji[i - 1] * i % mod;
}

ll c(ll a, ll n) {
  return ji[n] * qpow(ji[a], mod - 2) % mod * qpow(ji[n - a], mod - 2) % mod;
}

int main() {
  init();
  ll n;
  string s;
  cin >> n >> s;
  ll k = s.length();
  ll len = k + n;
  ll ans = 0;
  for (int i = 1; i <= len - k + 1; i++) {
    ans = (ans + qpow(26, i - 1) * qpow(25, len - i - k + 1) % mod *
                     c(k - 1, len - i) % mod) %
          mod;
  }
  cout << ans;
  return 0;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define boost                                                                  \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(nullptr)

const int N = 1e6 + 5;
const int M = 1e9 + 7;

int mod(int m) {
  m %= M;
  return (m + M) % M;
}

int power(int x, int y) {
  int res = 1;
  x = mod(x);
  while (y > 0) {
    if (y & 1)
      res = mod(res * x);
    y = y >> 1;
    x = mod(x * x);
  }
  return mod(res);
}

int f[N], invf[N];
void fact() {
  f[0] = f[1] = 1;
  for (int i = 2; i < N; i++)
    f[i] = mod(f[i - 1] * i);

  invf[N - 1] = power(f[N - 1], M - 2);
  for (int i = N - 1; i > 0; i--)
    invf[i - 1] = mod(invf[i] * i);
}

int nCr(int n, int r) {
  if (r > n)
    return 0;
  int ans = f[n];
  ans = mod(ans * invf[n - r]);
  ans = mod(ans * invf[r]);
  return ans;
}

int nPr(int n, int r) {
  if (r > n)
    return 0;
  int ans = f[n];
  ans = mod(ans * invf[n - r]);
  return ans;
}

int32_t main() {
  fact();
  boost;
  int k;
  cin >> k;
  string s;
  cin >> s;
  int m = s.size();
  int n = m + k;
  int ans = power(26, n);
  for (int i = 0; i < m; i++)
    ans = mod(ans - mod(nCr(n, i) * power(25, n - i)));
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define boost                                                                  \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(nullptr)

const int N = 2e6 + 5;
const int M = 1e9 + 7;

int mod(int m) {
  m %= M;
  return (m + M) % M;
}

int power(int x, int y) {
  int res = 1;
  x = mod(x);
  while (y > 0) {
    if (y & 1)
      res = mod(res * x);
    y = y >> 1;
    x = mod(x * x);
  }
  return mod(res);
}

int f[N], invf[N];
void fact() {
  f[0] = f[1] = 1;
  for (int i = 2; i < N; i++)
    f[i] = mod(f[i - 1] * i);

  invf[N - 1] = power(f[N - 1], M - 2);
  for (int i = N - 1; i > 0; i--)
    invf[i - 1] = mod(invf[i] * i);
}

int nCr(int n, int r) {
  if (r > n)
    return 0;
  int ans = f[n];
  ans = mod(ans * invf[n - r]);
  ans = mod(ans * invf[r]);
  return ans;
}

int nPr(int n, int r) {
  if (r > n)
    return 0;
  int ans = f[n];
  ans = mod(ans * invf[n - r]);
  return ans;
}

int32_t main() {
  fact();
  boost;
  int k;
  cin >> k;
  string s;
  cin >> s;
  int m = s.size();
  int n = m + k;
  int ans = power(26, n);
  for (int i = 0; i < m; i++)
    ans = mod(ans - mod(nCr(n, i) * power(25, n - i)));
  cout << ans << endl;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAX = 510000;
const int MOD = 1000000007;
//
int 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;
  }
}

// 二項係数計算
int 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;
}
int modpow(int a, int n, int mod) {
  int res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
signed main() {
  COMinit();
  int k;
  string s;
  cin >> k >> s;
  int ans = 0;
  for (int i = 0; i <= k; i++) {
    ans = (ans + modpow(25, i, MOD) * COM(i + s.size() - 1, s.size() - 1) %
                     MOD * modpow(26, k - i, MOD) % MOD) %
          MOD;
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAX = 2000007;
const int MOD = 1000000007;
//
int 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;
  }
}

// 二項係数計算
int 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;
}
int modpow(int a, int n, int mod) {
  int res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
signed main() {
  COMinit();
  int k;
  string s;
  cin >> k >> s;
  int ans = 0;
  for (int i = 0; i <= k; i++) {
    ans = (ans + modpow(25, i, MOD) * COM(i + s.size() - 1, s.size() - 1) %
                     MOD * modpow(26, k - i, MOD) % MOD) %
          MOD;
  }
  cout << ans << endl;
}