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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define pii pair<ll, ll>
#define debug(a) cout << a << '\n'
#define maxn 1000009 /// I wanna be the wind
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for (ll i = a; i < (b); ++i)
#define per(i, b, a) for (ll i = b - 1; i >= a; i--)
#define trav(a, x) for (auto &a : x)
#define allin(a, x) for (auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e14 + 9;
ll mult(ll a, ll b) { return a * b % MOD; }
ll fastpow(ll a, ll b) {
  ll calc = 1;
  for (; b >= 1LL; b /= 2LL) {
    if ((b & 1LL))
      calc = mult(calc, a);
    a = mult(a, a);
  }
  return calc;
}
ll soma(ll a, ll b) {
  if (a + b > MOD)
    return a + b - MOD;
  else
    return a + b;
}
ll subt(ll a, ll b) {
  if (a - b < 0)
    return a - b + MOD;
  else
    return a - b;
}
ll fact[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  fact[0] = 1;
  rep(i, 1, maxn) fact[i] = mult(i, fact[i - 1]);
  ll k;
  string s;
  cin >> k >> s;
  ll n = sz(s) + k;
  ll tir = 0;
  rep(i, 0, sz(s)) {
    tir = soma(
        tir, mult(fastpow(25, n - i),
                  mult(fact[n], fastpow(mult(fact[i], fact[n - i]), MOD - 2))));
  }
  cout << subt(fastpow(26, n), tir) << "\n";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define pii pair<ll, ll>
#define debug(a) cout << a << '\n'
#define maxn 2000009 /// I wanna be the wind
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for (ll i = a; i < (b); ++i)
#define per(i, b, a) for (ll i = b - 1; i >= a; i--)
#define trav(a, x) for (auto &a : x)
#define allin(a, x) for (auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e14 + 9;
ll mult(ll a, ll b) { return a * b % MOD; }
ll fastpow(ll a, ll b) {
  ll calc = 1;
  for (; b >= 1LL; b /= 2LL) {
    if ((b & 1LL))
      calc = mult(calc, a);
    a = mult(a, a);
  }
  return calc;
}
ll soma(ll a, ll b) {
  if (a + b > MOD)
    return a + b - MOD;
  else
    return a + b;
}
ll subt(ll a, ll b) {
  if (a - b < 0)
    return a - b + MOD;
  else
    return a - b;
}
ll fact[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  fact[0] = 1;
  rep(i, 1, maxn) fact[i] = mult(i, fact[i - 1]);
  ll k;
  string s;
  cin >> k >> s;
  ll n = sz(s) + k;
  ll tir = 0;
  rep(i, 0, sz(s)) {
    tir = soma(
        tir, mult(fastpow(25, n - i),
                  mult(fact[n], fastpow(mult(fact[i], fact[n - i]), MOD - 2))));
  }
  cout << subt(fastpow(26, n), tir) << "\n";
  return 0;
}
Problem p02632 (C++)

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

using namespace std;
#define _rep(n, a, b) for (int n = (a); n <= (b); ++n)
#define _rev(n, a, b) for (int n = (a); n >= (b); --n)
#define _for(n, a, b) for (int n = (a); n < (b); ++n)
#define _rof(n, a, b) for (int n = (a); n > (b); --n)
#define oo 0x3f3f3f3f3f3f
#define ll long long
#define db double
#define eps 1e-3
#define bin(x) cout << bitset<10>(x) << endl;
#define what_is(x) cerr << #x << " is " << x << endl
#define met(a, b) memset(a, b, sizeof(a))
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pdd pair<db, db>
#define endl "\n"
const int mod = 1e9 + 7;
const int maxn = 1e6 + 10;
vector<ll> f(maxn), invf(maxn);
ll qpow(ll a, ll b) {
  ll ret = 1;
  for (; b; a = a * a % mod, b >>= 1) {
    if (b & 1) {
      ret = ret * a % mod;
    }
  }
  return ret;
}

void prework() {
  f[0] = 1;
  _rep(i, 1, maxn - 1) { f[i] = f[i - 1] * i % mod; }
  invf[maxn - 1] = qpow(f[maxn - 1], mod - 2);
  for (int i = maxn - 2; i >= 0; i--) {
    invf[i] = invf[i + 1] * (i + 1) % mod;
  }
}

ll C(ll n, ll m) {
  if (n > m || m < 0)
    return 0;
  if (n == 0 || m == n)
    return 1;
  ll res = (f[m] * invf[m - n] % mod * invf[n]) % mod;
  return res;
}
signed main() {
  int k;
  string s;
  cin >> k >> s;
  prework();
  ll len = s.size();
  ll res = 0;
  _rep(i, 0, k) {
    res = (res + qpow(26, i) * qpow(25, k - i) % mod *
                     C(len - 1, k + len - 1 - i) % mod) %
          mod;
  }
  cout << res << endl;
}

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

using namespace std;
#define _rep(n, a, b) for (int n = (a); n <= (b); ++n)
#define _rev(n, a, b) for (int n = (a); n >= (b); --n)
#define _for(n, a, b) for (int n = (a); n < (b); ++n)
#define _rof(n, a, b) for (int n = (a); n > (b); --n)
#define oo 0x3f3f3f3f3f3f
#define ll long long
#define db double
#define eps 1e-3
#define bin(x) cout << bitset<10>(x) << endl;
#define what_is(x) cerr << #x << " is " << x << endl
#define met(a, b) memset(a, b, sizeof(a))
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pdd pair<db, db>
#define endl "\n"
const int mod = 1e9 + 7;
const int maxn = 2e6 + 10;
vector<ll> f(maxn), invf(maxn);
ll qpow(ll a, ll b) {
  ll ret = 1;
  for (; b; a = a * a % mod, b >>= 1) {
    if (b & 1) {
      ret = ret * a % mod;
    }
  }
  return ret;
}

void prework() {
  f[0] = 1;
  _rep(i, 1, maxn - 1) { f[i] = f[i - 1] * i % mod; }
  invf[maxn - 1] = qpow(f[maxn - 1], mod - 2);
  for (int i = maxn - 2; i >= 0; i--) {
    invf[i] = invf[i + 1] * (i + 1) % mod;
  }
}

ll C(ll n, ll m) {
  if (n > m || m < 0)
    return 0;
  if (n == 0 || m == n)
    return 1;
  ll res = (f[m] * invf[m - n] % mod * invf[n]) % mod;
  return res;
}
signed main() {
  int k;
  string s;
  cin >> k >> s;
  prework();
  ll len = s.size();
  ll res = 0;
  _rep(i, 0, k) {
    res = (res + qpow(26, i) * qpow(25, k - i) % mod *
                     C(len - 1, k + len - 1 - i) % mod) %
          mod;
  }
  cout << res << endl;
}
Problem p02632 (C++)

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

using namespace std;

#define ll long long
#define ull unsigned long long
#define ar array

const ll mod = 1e9 + 7;

ll pwr(ll a, ll b) {
  ll ret = 1;
  while (b > 0) {
    if (b % 2 == 1)
      ret = ret * a % mod;
    a = a * a % mod;
    b /= 2;
  }
  return ret;
}

const int N = 1e6 + 5;
ll f[N], inv[N];

ll C(int n, int k) {
  if (k > n || k < 0)
    return 0;
  return f[n] * (inv[k] * inv[n - k] % mod) % mod;
}

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

  int k, n;
  string s;
  cin >> k >> s;
  n = (int)s.size() + k;

  f[0] = 1;
  inv[0] = 1;
  for (int i = 1; i < N; i++) {
    f[i] = (ll)f[i - 1] * i % mod;
    inv[i] = pwr(f[i], mod - 2);
  }

  ll ans = 0;
  for (int i = 0; i < (int)s.size(); i++) {
    ans = (ans + pwr(25, n - i) * C(n, i) % mod) % mod;
  }
  ans = (pwr(26, n) - ans + mod) % mod;

  cout << ans << '\n';
}

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

using namespace std;

#define ll long long
#define ull unsigned long long
#define ar array

const ll mod = 1e9 + 7;

ll pwr(ll a, ll b) {
  ll ret = 1;
  while (b > 0) {
    if (b % 2 == 1)
      ret = ret * a % mod;
    a = a * a % mod;
    b /= 2;
  }
  return ret;
}

const int N = 2e6 + 5;
ll f[N], inv[N];

ll C(int n, int k) {
  if (k > n || k < 0)
    return 0;
  return f[n] * (inv[k] * inv[n - k] % mod) % mod;
}

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

  int k, n;
  string s;
  cin >> k >> s;
  n = (int)s.size() + k;

  f[0] = 1;
  inv[0] = 1;
  for (int i = 1; i < N; i++) {
    f[i] = (ll)f[i - 1] * i % mod;
    inv[i] = pwr(f[i], mod - 2);
  }

  ll ans = 0;
  for (int i = 0; i < (int)s.size(); i++) {
    ans = (ans + pwr(25, n - i) * C(n, i) % mod) % mod;
  }
  ans = (pwr(26, n) - ans + mod) % mod;

  cout << ans << '\n';
}
Problem p02632 (C++)

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

using namespace std;

#define pb push_back
#define sz(a) ((int)a.size())
#define mp make_pair
#define fi first
#define se second

const int maxn = 1e6 + 5;

const int maxv = 1e9;
const int mod = 1e9 + 7;

int T, tc;
int n;
int a[maxn];
long long fact[maxn], inv[maxn];
string s;

long long power_mod(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b % 2)
      res = res * a % mod;
    a = a * a % mod;
    b /= 2ll;
  }
  return res;
}

long long C(int n, int k) { return fact[n] * inv[k] % mod * inv[n - k] % mod; }

int main() {
  //	freopen("inp.txt", "r", stdin);

  cin >> n;

  fact[0] = inv[0] = 1;
  for (int i = 1; i < maxn; i++) {
    fact[i] = fact[i - 1] * i % mod;
    inv[i] = power_mod(fact[i], mod - 2);
  }

  cin >> s;

  long long len = (long long)s.size();

  long long ans = 0;
  for (int i = 0; i <= n; i++) {
    int rem = n - i;
    //		cout << power_mod(25, rem) << ' ' << C(rem + len - 1, len - 1) << ' '
    //<< power_mod(26, i) << endl;
    (ans += power_mod(25, rem) * C(rem + len - 1, len - 1) % mod *
            power_mod(26, i) % mod) %= mod;
  }

  cout << ans;

  return 0;
}

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

using namespace std;

#define pb push_back
#define sz(a) ((int)a.size())
#define mp make_pair
#define fi first
#define se second

const int maxn = 2e6 + 5;

const int maxv = 1e9;
const int mod = 1e9 + 7;

int T, tc;
int n;
int a[maxn];
long long fact[maxn], inv[maxn];
string s;

long long power_mod(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b % 2)
      res = res * a % mod;
    a = a * a % mod;
    b /= 2ll;
  }
  return res;
}

long long C(int n, int k) { return fact[n] * inv[k] % mod * inv[n - k] % mod; }

int main() {
  //	freopen("inp.txt", "r", stdin);

  cin >> n;

  fact[0] = inv[0] = 1;
  for (int i = 1; i < maxn; i++) {
    fact[i] = fact[i - 1] * i % mod;
    inv[i] = power_mod(fact[i], mod - 2);
  }

  cin >> s;

  long long len = (long long)s.size();

  long long ans = 0;
  for (int i = 0; i <= n; i++) {
    int rem = n - i;
    //		cout << power_mod(25, rem) << ' ' << C(rem + len - 1, len - 1) << ' '
    //<< power_mod(26, i) << endl;
    (ans += power_mod(25, rem) * C(rem + len - 1, len - 1) % mod *
            power_mod(26, i) % mod) %= mod;
  }

  cout << ans;

  return 0;
}
Problem p02632 (C++)

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

#define endl '\n'

const int N = 1000005;
const int M = 1000000007;

long long power(long long a, long long b) {
  if (b == 0)
    return 1;
  long long r = power(a, b / 2);
  r = (r * r) % M;
  if (b & 1)
    return (r * a) % M;
  return r;
}

long long f[N], inv[N];

int main() {
  int k;
  string s;
  cin >> k >> s;
  int n = s.size();
  f[0] = 1;
  for (int i = 1; i < N; i++)
    f[i] = (f[i - 1] * i) % M;
  inv[N - 1] = power(f[N - 1], M - 2);
  for (int i = N - 2; i >= 0; i--)
    inv[i] = (inv[i + 1] * (i + 1)) % M;
  auto C = [&](int x, int y) -> int {
    if (x < y || y < 0)
      return 0;
    if (x == y || y == 0)
      return 1;
    long long r = f[x];
    r = (r * inv[y]) % M;
    r = (r * inv[x - y]) % M;
    return r;
  };
  auto get = [&](int i) -> int {
    long long r = power(26, i);
    r = (r * power(25, k - i)) % M;
    r = (r * C(k - i + n - 1, n - 1)) % M;
    return r;
  };
  long long sum = 0;
  for (int i = 0; i <= k; i++) {
    sum = (sum + get(i)) % M;
  }
  cout << sum << endl;
  return 0;
}


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

#define endl '\n'

const int N = 3000005;
const int M = 1000000007;

long long power(long long a, long long b) {
  if (b == 0)
    return 1;
  long long r = power(a, b / 2);
  r = (r * r) % M;
  if (b & 1)
    return (r * a) % M;
  return r;
}

long long f[N], inv[N];

int main() {
  int k;
  string s;
  cin >> k >> s;
  int n = s.size();
  f[0] = 1;
  for (int i = 1; i < N; i++)
    f[i] = (f[i - 1] * i) % M;
  inv[N - 1] = power(f[N - 1], M - 2);
  for (int i = N - 2; i >= 0; i--)
    inv[i] = (inv[i + 1] * (i + 1)) % M;
  auto C = [&](int x, int y) -> int {
    if (x < y || y < 0)
      return 0;
    if (x == y || y == 0)
      return 1;
    long long r = f[x];
    r = (r * inv[y]) % M;
    r = (r * inv[x - y]) % M;
    return r;
  };
  auto get = [&](int i) -> int {
    long long r = power(26, i);
    r = (r * power(25, k - i)) % M;
    r = (r * C(k - i + n - 1, n - 1)) % M;
    return r;
  };
  long long sum = 0;
  for (int i = 0; i <= k; i++) {
    sum = (sum + get(i)) % M;
  }
  cout << sum << endl;
  return 0;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

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

ll modpow(ll a, ll n, ll p) {
  if (n == 0)
    return 1;
  if (n % 2)
    return (a * modpow(a, n - 1, p)) % p;
  if (!(n % 2)) {
    ll t = modpow(a, n / 2, p);
    return (t * t) % p;
  }
}

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

Fixed submission:
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

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

ll modpow(ll a, ll n, ll p) {
  if (n == 0)
    return 1;
  if (n % 2)
    return (a * modpow(a, n - 1, p)) % p;
  if (!(n % 2)) {
    ll t = modpow(a, n / 2, p);
    return (t * t) % p;
  }
}

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
// #define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

const int MAX = 1001000;
const ll MOD = 1000000007;

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) {
  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 n, ll t) {
  ll ret = 1;
  while (0 < t) {
    if (t % 2 == 0) {
      n *= n;
      n %= MOD;
      t >>= 1;
    } else {
      ret *= n;
      ret %= MOD;
      --t;
    }
  }
  return ret;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  string S;
  ll K;
  cin >> K >> S;
  ll size = S.size();
  ll ans = 0;

  COMinit();

  REP(i, K + 1) {
    ll p = modpow(26, i);
    ll c = COM((size + K - 1 - i), (size - 1));
    ll p2 = modpow(25, (K - i));
    // cout << c << " " << p << " " << p2 << endl;
    ans += (((p * c) % MOD) * p2) % MOD;
    ans %= MOD;
  }

  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
// #define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

const int MAX = 2001000;
const ll MOD = 1000000007;

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) {
  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 n, ll t) {
  ll ret = 1;
  while (0 < t) {
    if (t % 2 == 0) {
      n *= n;
      n %= MOD;
      t >>= 1;
    } else {
      ret *= n;
      ret %= MOD;
      --t;
    }
  }
  return ret;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  string S;
  ll K;
  cin >> K >> S;
  ll size = S.size();
  ll ans = 0;

  COMinit();

  REP(i, K + 1) {
    ll p = modpow(26, i);
    ll c = COM((size + K - 1 - i), (size - 1));
    ll p2 = modpow(25, (K - i));
    // cout << c << " " << p << " " << p2 << endl;
    ans += (((p * c) % MOD) * p2) % MOD;
    ans %= MOD;
  }

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

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

const int mod =
    1000000007; // 出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60; // INF = 11

#define N_MAX 201010
ll f[N_MAX], rf[N_MAX];
// f[n]  := n!
// rf[n] := (n!)^-1

ll modpow(ll a, ll b) { // aのb乗
  ll ans = 1;
  while (b > 0) {
    if (b & 1)
      ans = ans * a % mod;
    a = a * a % mod;
    b /= 2;
  }
  return ans;
}

void init() {
  f[0] = 1;
  for (ll i = 1; i < N_MAX; i++) {
    f[i] = (i * f[i - 1]) % mod;
  }
  for (ll i = 0; i < N_MAX; i++) {
    rf[i] = modpow(f[i], mod - 2);
  }
}

ll com(ll n, ll k) {
  // init();
  ll a = f[n];
  ll b = rf[k];
  ll c = rf[n - k];

  ll bc = (b * c) % mod;

  return ((a * bc) % mod);
}

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

  ll ans = 0;

  for (ll i = 0; i <= k; i++) {

    ans += com((n - 1 + k - i), (n - 1)) * modpow(25, k - i) % mod *
           modpow(26, i) % mod;
    ans %= mod;
  }

  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

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

const int mod =
    1000000007; // 出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60; // INF = 11

#define N_MAX 2010100
ll f[N_MAX], rf[N_MAX];
// f[n]  := n!
// rf[n] := (n!)^-1

ll modpow(ll a, ll b) { // aのb乗
  ll ans = 1;
  while (b > 0) {
    if (b & 1)
      ans = ans * a % mod;
    a = a * a % mod;
    b /= 2;
  }
  return ans;
}

void init() {
  f[0] = 1;
  for (ll i = 1; i < N_MAX; i++) {
    f[i] = (i * f[i - 1]) % mod;
  }
  for (ll i = 0; i < N_MAX; i++) {
    rf[i] = modpow(f[i], mod - 2);
  }
}

ll com(ll n, ll k) {
  // init();
  ll a = f[n];
  ll b = rf[k];
  ll c = rf[n - k];

  ll bc = (b * c) % mod;

  return ((a * bc) % mod);
}

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

  ll ans = 0;

  for (ll i = 0; i <= k; i++) {

    ans += com((n - 1 + k - i), (n - 1)) * modpow(25, k - i) % mod *
           modpow(26, i) % mod;
    ans %= mod;
  }

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

const int N = 1000001;

int n, k, fact[N], inv[N], mod = 1e9 + 7;
string s;

int powlog(int a, int b) {
  if (b == 0)
    return 1;
  int ret = powlog(a, b / 2);
  if (b % 2)
    return 1LL * ret * ret % mod * a % mod;
  return 1LL * ret * ret % mod;
}
int C(int n, int r) {
  if (r > n)
    return 0;
  return 1LL * fact[n] * inv[n - r] % mod * inv[r] % mod;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  fact[0] = 1;
  for (int i = 1; i < N; i++) {
    fact[i] = 1LL * i * fact[i - 1] % mod;
  }
  inv[N - 1] = powlog(fact[N - 1], mod - 2);
  for (int i = N - 2; i >= 0; i--) {
    inv[i] = 1LL * (i + 1) * inv[i + 1] % mod;
  }
  cin >> k >> s;
  n = s.size();
  int ans = 0;
  for (int i = 0; i <= k; i++) {
    ans = (ans + 1LL * powlog(25, k - i) * powlog(26, i) % mod *
                     C(n - 1 + k - i, n - 1)) %
          mod;
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

const int N = 2000001;

int n, k, fact[N], inv[N], mod = 1e9 + 7;
string s;

int powlog(int a, int b) {
  if (b == 0)
    return 1;
  int ret = powlog(a, b / 2);
  if (b % 2)
    return 1LL * ret * ret % mod * a % mod;
  return 1LL * ret * ret % mod;
}
int C(int n, int r) {
  if (r > n)
    return 0;
  return 1LL * fact[n] * inv[n - r] % mod * inv[r] % mod;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  fact[0] = 1;
  for (int i = 1; i < N; i++) {
    fact[i] = 1LL * i * fact[i - 1] % mod;
  }
  inv[N - 1] = powlog(fact[N - 1], mod - 2);
  for (int i = N - 2; i >= 0; i--) {
    inv[i] = 1LL * (i + 1) * inv[i + 1] % mod;
  }
  cin >> k >> s;
  n = s.size();
  int ans = 0;
  for (int i = 0; i <= k; i++) {
    ans = (ans + 1LL * powlog(25, k - i) * powlog(26, i) % mod *
                     C(n - 1 + k - i, n - 1)) %
          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 N = 1e6 + 10;
const int mod = 1e9 + 7;
ll fac[N], inv[N];
char s[N];
int k;

ll qp(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] = fac[1] = 1;
  for (int i = 2; i < N; i++)
    fac[i] = fac[i - 1] * i % mod;
  inv[N - 1] = qp(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) {
  if (b > a)
    return 0ll;
  return fac[a] * inv[b] % mod * inv[a - b] % mod;
}

ll add(ll a, ll b) { return (a + b) % mod; }

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

  ll res = 0;
  int len = strlen(s);

  for (int i = len; i <= k + len;
       i++) // 枚举前i个字符为S的所在地，即第i个位置是字符s[len-1]的所在地
    res = add(res, C(i - 1, len - 1) * qp(25ll, i - len) % mod *
                       qp(26ll, k + len - i) % mod);
  printf("%lld\n", res);

  return 0;
}

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

typedef long long ll;
const int N = 2e6 + 10;
const int mod = 1e9 + 7;
ll fac[N], inv[N];
char s[N];
int k;

ll qp(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] = fac[1] = 1;
  for (int i = 2; i < N; i++)
    fac[i] = fac[i - 1] * i % mod;
  inv[N - 1] = qp(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) {
  if (b > a)
    return 0ll;
  return fac[a] * inv[b] % mod * inv[a - b] % mod;
}

ll add(ll a, ll b) { return (a + b) % mod; }

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

  ll res = 0;
  int len = strlen(s);

  for (int i = len; i <= k + len;
       i++) // 枚举前i个字符为S的所在地，即第i个位置是字符s[len-1]的所在地
    res = add(res, C(i - 1, len - 1) * qp(25ll, i - len) % mod *
                       qp(26ll, k + len - i) % mod);
  printf("%lld\n", res);

  return 0;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
const int MAX = 510000;
const int MOD = 1000000007;

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

ll mod_pow(ll a, ll n) {
  a %= MOD;
  ll ret = 1;
  while (n > 0) {
    if (n & 1LL)
      ret = (ret * a) % MOD;
    a = (a * a) % MOD;
    n = n >> 1;
  }
  return ret;
}

// テーブルを作る前処理
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;
}

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

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
const int MAX = 2000010;
const int MOD = 1000000007;

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

ll mod_pow(ll a, ll n) {
  a %= MOD;
  ll ret = 1;
  while (n > 0) {
    if (n & 1LL)
      ret = (ret * a) % MOD;
    a = (a * a) % MOD;
    n = n >> 1;
  }
  return ret;
}

// テーブルを作る前処理
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;
}

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

Buggy submission (status: Runtime Error):
/*================================================================
*
*   创 建 者： badcw
*   创建日期： 2020/6/21 20:51
*
================================================================*/
#include <bits/stdc++.h>

#define ll long long
using namespace std;

const int maxn = 1e6 + 50;
const int mod = 1e9 + 7;
ll qp(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;
}

ll jie[maxn] = {1};
char s[maxn];

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

ll C(int x, int y) {
  if (x < y)
    return 0;
  if (x == 0)
    return 0;
  return jie[x] * inv(jie[y]) % mod * inv(jie[x - y]) % mod;
}

int main(int argc, char *argv[]) {
  int k;
  cin >> k >> s;
  int len = strlen(s);
  k += len;
  for (int i = 1; i <= k; ++i)
    jie[i] = jie[i - 1] * i % mod;
  ll res = qp(26, k);
  ll TC = 0;
  ll TQ = qp(25, k);
  ll tt = inv(25);
  for (int i = 0; i < len; ++i) {
    if (i == 0) {
      TC = 1;
    } else
      TC = TC * (k - i + 1) % mod * inv(i) % mod;
    res -= TC * TQ;
    res %= mod;
    TQ = TQ * tt % mod;
    //        res -= C(k, i) * qp(25, k - i) % mod;
    //        res %= mod;
  }
  if (res < 0)
    res += mod;
  cout << res << endl;
  //    printf("%lld\n", res);
  return 0;
}

Fixed submission:
/*================================================================
*
*   创 建 者： badcw
*   创建日期： 2020/6/21 20:51
*
================================================================*/
#include <bits/stdc++.h>

#define ll long long
using namespace std;

const int maxn = 2e6 + 50;
const int mod = 1e9 + 7;
ll qp(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;
}

ll jie[maxn] = {1};
char s[maxn];

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

ll C(int x, int y) {
  if (x < y)
    return 0;
  if (x == 0)
    return 0;
  return jie[x] * inv(jie[y]) % mod * inv(jie[x - y]) % mod;
}

int main(int argc, char *argv[]) {
  int k;
  cin >> k >> s;
  int len = strlen(s);
  k += len;
  for (int i = 1; i <= k; ++i)
    jie[i] = jie[i - 1] * i % mod;
  ll res = qp(26, k);
  ll TC = 0;
  ll TQ = qp(25, k);
  ll tt = inv(25);
  for (int i = 0; i < len; ++i) {
    if (i == 0) {
      TC = 1;
    } else
      TC = TC * (k - i + 1) % mod * inv(i) % mod;
    res -= TC * TQ;
    res %= mod;
    TQ = TQ * tt % mod;
    //        res -= C(k, i) * qp(25, k - i) % mod;
    //        res %= mod;
  }
  if (res < 0)
    res += mod;
  cout << res << endl;
  //    printf("%lld\n", res);
  return 0;
}
Problem p02632 (C++)

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

using namespace std;
typedef long long ll;
typedef vector<int> vi;
const ll MOD = 1e9 + 7;
const int M = 1e6 + 5;

ll fac[M], ifac[M];

ll inv(ll x) {
  ll ans = 1;
  ll p = MOD - 2;
  while (p > 0) {
    if (p & 1)
      ans = (ans * x) % MOD;
    p >>= 1;
    x = (x * x) % MOD;
  }
  return ans;
}

ll ifa(int i) {
  if (!ifac[i])
    ifac[i] = inv(fac[i]);
  return ifac[i];
}

ll C(int n, int k) { return (((fac[n] * ifa(k)) % MOD) * ifa(n - k)) % MOD; }

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

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

  int K;
  cin >> K;
  string S;
  cin >> S;
  int n = S.size();
  ll ans = 0;
  ll p25 = 1, p26 = 1, i26 = inv(26);
  for (int k = 0; k < K; ++k)
    p26 = (p26 * 26) % MOD;
  for (int k = 0; k <= K; ++k) {
    ll a = (p25 * C(k + n - 1, n - 1)) % MOD;
    a = (a * p26) % MOD;
    ans = (ans + a) % MOD;
    p25 = (p25 * 25) % MOD;
    p26 = (p26 * i26) % MOD;
  }
  cout << ans << "\n";

  return 0;
}

Fixed submission:
#include <iostream>
#include <map>
#include <vector>

using namespace std;
typedef long long ll;
typedef vector<int> vi;
const ll MOD = 1e9 + 7;
const int M = 2e6 + 5;

ll fac[M], ifac[M];

ll inv(ll x) {
  ll ans = 1;
  ll p = MOD - 2;
  while (p > 0) {
    if (p & 1)
      ans = (ans * x) % MOD;
    p >>= 1;
    x = (x * x) % MOD;
  }
  return ans;
}

ll ifa(int i) {
  if (!ifac[i])
    ifac[i] = inv(fac[i]);
  return ifac[i];
}

ll C(int n, int k) { return (((fac[n] * ifa(k)) % MOD) * ifa(n - k)) % MOD; }

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

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

  int K;
  cin >> K;
  string S;
  cin >> S;
  int n = S.size();
  ll ans = 0;
  ll p25 = 1, p26 = 1, i26 = inv(26);
  for (int k = 0; k < K; ++k)
    p26 = (p26 * 26) % MOD;
  for (int k = 0; k <= K; ++k) {
    ll a = (p25 * C(k + n - 1, n - 1)) % MOD;
    a = (a * p26) % MOD;
    ans = (ans + a) % MOD;
    p25 = (p25 * 25) % MOD;
    p26 = (p26 * i26) % MOD;
  }
  cout << ans << "\n";

  return 0;
}
Problem p02632 (C++)

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll MOD = 1e9 + 7;
const ll MX = 1e6 + 6;

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll extend_gcd(ll a, ll b, ll &x, ll &y) {
  if (b == 0) {
    x = 1, y = 0;
    return a;
  } else {
    ll r = extend_gcd(b, a % b, y, x);
    y -= x * (a / b);
    return r;
  }
}
ll inv(ll a, ll mod) {
  ll x, y;
  extend_gcd(a, mod, x, y);
  x = (x % mod + mod) % mod;
  return x;
}

ll K, NS, N;
string S;

ll fs[MX], ifs[MX];

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

ll Cnm(ll n, ll m) {
  return (((((fs[n] * ifs[m]) % MOD + MOD) % MOD) * ifs[n - m]) % MOD + MOD) %
         MOD;
}

void init() {
  for (ll a = 0; a < MX; a++) {
    if (a == 0)
      fs[a] = 1;
    else
      fs[a] = (fs[a - 1] * a) % MOD;
    ifs[a] = (inv(fs[a], MOD) % MOD + MOD) % MOD;
  }
}

int main() {
  init();
  cin >> K >> S;
  NS = S.size();
  N = NS + K;
  ll res = 0;
  for (ll j = 0; j <= K; j++) {
    res += (Cnm(N, j + NS) * mpow(25, N - NS - j)) % MOD;
    res %= MOD;
  }
  cout << res << endl;

  return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll extend_gcd(ll a, ll b, ll &x, ll &y) {
  if (b == 0) {
    x = 1, y = 0;
    return a;
  } else {
    ll r = extend_gcd(b, a % b, y, x);
    y -= x * (a / b);
    return r;
  }
}
ll inv(ll a, ll mod) {
  ll x, y;
  extend_gcd(a, mod, x, y);
  x = (x % mod + mod) % mod;
  return x;
}

ll K, NS, N;
string S;

ll fs[MX], ifs[MX];

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

ll Cnm(ll n, ll m) {
  return (((((fs[n] * ifs[m]) % MOD + MOD) % MOD) * ifs[n - m]) % MOD + MOD) %
         MOD;
}

void init() {
  for (ll a = 0; a < MX; a++) {
    if (a == 0)
      fs[a] = 1;
    else
      fs[a] = (fs[a - 1] * a) % MOD;
    ifs[a] = (inv(fs[a], MOD) % MOD + MOD) % MOD;
  }
}

int main() {
  init();
  cin >> K >> S;
  NS = S.size();
  N = NS + K;
  ll res = 0;
  for (ll j = 0; j <= K; j++) {
    res += (Cnm(N, j + NS) * mpow(25, N - NS - j)) % MOD;
    res %= MOD;
  }
  cout << res << endl;

  return 0;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

const int MAX = 1000001;
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 K;
string s;

int main() {
  COMinit();

  cin >> K >> s;
  int S = static_cast<int>(s.size());

  int res = 0;
  for (int i = 0; i <= K; i++) {
    int tmp = (modpow(25, K - i, MOD) * modpow(26, i, MOD)) % MOD;
    tmp = (tmp * COM(S + K - i - 1, S - 1)) % MOD;
    res = (res + tmp) % MOD;
  }
  cout << res << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

const int MAX = 3000000;
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 K;
string s;

int main() {
  COMinit();

  cin >> K >> s;
  int S = static_cast<int>(s.size());

  int res = 0;
  for (int i = 0; i <= K; i++) {
    int tmp = (modpow(25, K - i, MOD) * modpow(26, i, MOD)) % MOD;
    tmp = (tmp * COM(S + K - i - 1, S - 1)) % MOD;
    res = (res + tmp) % MOD;
  }
  cout << res << endl;

  return 0;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
const Int MOD = 1000000007;
const Int MAX = 1000100;
Int fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = finv[0] = finv[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 || n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
Int POW(Int n, Int m) {
  if (m == 0)
    return 1;
  if (m % 2 == 0)
    return POW(n * n % MOD, m / 2);
  return n * POW(n, m - 1) % MOD;
}
int main() {
  COMinit();
  int K;
  cin >> K;
  string S;
  cin >> S;
  int N = S.size();
  vector<Int> A(K + 1), B(K + 1);
  for (int i = 0; i <= K; i++) {
    A[i] = COM(N - 1 + i, i) * POW(25, i) % MOD;
  }
  for (int i = 0; i <= K; i++) {
    B[i] = A[i] + (i > 0 ? B[i - 1] * 26 : 0);
    B[i] %= MOD;
  }
  cout << B[K] << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
const Int MOD = 1000000007;
const Int MAX = 2000100;
Int fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = finv[0] = finv[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 || n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
Int POW(Int n, Int m) {
  if (m == 0)
    return 1;
  if (m % 2 == 0)
    return POW(n * n % MOD, m / 2);
  return n * POW(n, m - 1) % MOD;
}
int main() {
  COMinit();
  int K;
  cin >> K;
  string S;
  cin >> S;
  int N = S.size();
  vector<Int> A(K + 1), B(K + 1);
  for (int i = 0; i <= K; i++) {
    A[i] = COM(N - 1 + i, i) * POW(25, i) % MOD;
  }
  for (int i = 0; i <= K; i++) {
    B[i] = A[i] + (i > 0 ? B[i - 1] * 26 : 0);
    B[i] %= MOD;
  }
  cout << B[K] << endl;
  return 0;
}
Problem p02632 (C++)

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

int main() {
  long long ans = 0;
  int K;
  // int MOD = 1000000007;
  string S;
  cin >> K >> S;
  int l = S.size();
  COMinit();
  for (int i = 0; i <= K; i++) {
    ans = (ans + ((COM(i + l - 1, i) * modpow(25, i, MOD)) % MOD) *
                     modpow(26, K - i, MOD)) %
          MOD;
    // cout << ans << endl;
  }

  cout << ans << endl;
}

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

int main() {
  long long ans = 0;
  int K;
  // int MOD = 1000000007;
  string S;
  cin >> K >> S;
  int l = S.size();
  COMinit();
  for (int i = 0; i <= K; i++) {
    ans = (ans + ((COM(i + l - 1, i) * modpow(25, i, MOD)) % MOD) *
                     modpow(26, K - i, MOD)) %
          MOD;
    // cout << ans << endl;
  }

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
const int mod = 1e9 + 7;
int n, m;
int fac[maxn], ifac[maxn];
char s[maxn];
int mul(int x, int y) { return 1ll * x * y % mod; }
int fpw(int x, int y) {
  int r = 1;
  for (int i = y; i; i >>= 1, x = mul(x, x))
    if (i & 1)
      r = mul(r, x);
  return r;
}
int inv(int x) { return fpw(x, mod - 2); }
int mul(int x, int y, int z) { return mul(x, mul(y, z)); }
int C(int n, int m) { return mul(fac[n], ifac[m], ifac[n - m]); }
int read() {
  int x;
  scanf("%d", &x);
  return x;
}
int main() {
#ifdef LOCAL
  freopen("1.in", "r", stdin);
#endif
  n = read();
  scanf("%s", s);
  m = strlen(s);
  fac[0] = ifac[0] = 1;
  for (int i = 1; i <= n + m; ++i)
    fac[i] = mul(fac[i - 1], i), ifac[i] = mul(ifac[i - 1], inv(i));
  // new length = m + n
  int ans = 0;
  for (int i = 0; i <= n; ++i) {
    ans += mul(mul(C(m + i - 1, i), fpw(25, i)), fpw(26, n - i));
    ans %= mod;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6 + 10;
const int mod = 1e9 + 7;
int n, m;
int fac[maxn], ifac[maxn];
char s[maxn];
int mul(int x, int y) { return 1ll * x * y % mod; }
int fpw(int x, int y) {
  int r = 1;
  for (int i = y; i; i >>= 1, x = mul(x, x))
    if (i & 1)
      r = mul(r, x);
  return r;
}
int inv(int x) { return fpw(x, mod - 2); }
int mul(int x, int y, int z) { return mul(x, mul(y, z)); }
int C(int n, int m) { return mul(fac[n], ifac[m], ifac[n - m]); }
int read() {
  int x;
  scanf("%d", &x);
  return x;
}
int main() {
#ifdef LOCAL
  freopen("1.in", "r", stdin);
#endif
  n = read();
  scanf("%s", s);
  m = strlen(s);
  fac[0] = ifac[0] = 1;
  for (int i = 1; i <= n + m; ++i)
    fac[i] = mul(fac[i - 1], i), ifac[i] = mul(ifac[i - 1], inv(i));
  // new length = m + n
  int ans = 0;
  for (int i = 0; i <= n; ++i) {
    ans += mul(mul(C(m + i - 1, i), fpw(25, i)), fpw(26, n - i));
    ans %= mod;
  }
  cout << ans << endl;
}
Problem p02632 (C++)

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

using namespace std;
using ll = long long;

const ll MOD = 1e9 + 7;
const int mx = 1e6 + 9;

inline void normal(ll &a) {
  if (a >= MOD)
    a %= MOD;
  (a < 0) && (a += MOD);
}
inline ll modMul(ll a, ll b) {
  normal(a), normal(b);
  return (a * b) % MOD;
}
inline ll modAdd(ll a, ll b) {
  normal(a), normal(b);
  return (a + b) % MOD;
}
inline ll modSub(ll a, ll b) {
  normal(a), normal(b);
  a -= b;
  normal(a);
  return a;
}
inline ll modPow(ll b, ll p) {
  ll r = 1;
  while (p) {
    if (p & 1)
      r = modMul(r, b);
    b = modMul(b, b);
    p >>= 1;
  }
  return r;
} // if MOD is prime, modPow(b, p % (MOD-1))
inline ll modInverse(ll a) { return modPow(a, MOD - 2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll f[mx];

ll nCr(ll n, ll r) { return modDiv(f[n], modMul(f[r], f[n - r])); }

int main() {
  f[0] = 1;
  for (int i = 1; i < mx; i++)
    f[i] = modMul(i, f[i - 1]);
  int k;
  string s;
  cin >> k >> s;

  int sz = s.size();
  int n = k + sz;
  int z = 26;

  ll ans = 0;
  for (int m = 0; m < sz; m++) {
    ll temp = nCr(n, m);
    temp = modMul(temp, modPow(z - 1, n - m));
    ans = modAdd(ans, temp);
  }

  ans = modSub(modPow(z, n), ans);
  cout << ans << endl;
}

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

using namespace std;
using ll = long long;

const ll MOD = 1e9 + 7;
const int mx = 3e6 + 9;

inline void normal(ll &a) {
  if (a >= MOD)
    a %= MOD;
  (a < 0) && (a += MOD);
}
inline ll modMul(ll a, ll b) {
  normal(a), normal(b);
  return (a * b) % MOD;
}
inline ll modAdd(ll a, ll b) {
  normal(a), normal(b);
  return (a + b) % MOD;
}
inline ll modSub(ll a, ll b) {
  normal(a), normal(b);
  a -= b;
  normal(a);
  return a;
}
inline ll modPow(ll b, ll p) {
  ll r = 1;
  while (p) {
    if (p & 1)
      r = modMul(r, b);
    b = modMul(b, b);
    p >>= 1;
  }
  return r;
} // if MOD is prime, modPow(b, p % (MOD-1))
inline ll modInverse(ll a) { return modPow(a, MOD - 2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll f[mx];

ll nCr(ll n, ll r) { return modDiv(f[n], modMul(f[r], f[n - r])); }

int main() {
  f[0] = 1;
  for (int i = 1; i < mx; i++)
    f[i] = modMul(i, f[i - 1]);
  int k;
  string s;
  cin >> k >> s;

  int sz = s.size();
  int n = k + sz;
  int z = 26;

  ll ans = 0;
  for (int m = 0; m < sz; m++) {
    ll temp = nCr(n, m);
    temp = modMul(temp, modPow(z - 1, n - m));
    ans = modAdd(ans, temp);
  }

  ans = modSub(modPow(z, n), ans);
  cout << ans << endl;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define foi(i, k, n) for (int i = (int)k; i < (int)n; ++i)

using namespace std;

constexpr int MOD = 7 + 1e9;
constexpr int MAXN = 5 + 1e6;

int add(int a, int b) {
  int ans = a + b;
  if (ans >= MOD)
    ans -= MOD;
  return ans;
}

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

int fpow(int b, int e) {
  int ans = 1;
  for (; e; e >>= 1) {
    if (e & 1)
      ans = mul(ans, b);
    b = mul(b, b);
  }
  return ans;
}

int f[MAXN];
int choose(int n, int k) {
  assert(k <= n);
  return mul(f[n], fpow(mul(f[k], f[n - k]), MOD - 2));
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  f[0] = 1;
  for (int i = 1; i < MAXN; ++i) {
    f[i] = mul(f[i - 1], i);
  }
  int n, k, ans = 0;
  cin >> k;
  string s;
  cin >> s;
  n = s.size() + k;
  k = s.size();
  for (int j = 0; j <= n - k; ++j) {
    ans = add(ans, mul(choose(n, j + k), fpow(25, n - k - j)));
  }
  cout << ans << '\n';
  return 0;
}


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

using namespace std;

constexpr int MOD = 7 + 1e9;
constexpr int MAXN = 5 + 3e6;

int add(int a, int b) {
  int ans = a + b;
  if (ans >= MOD)
    ans -= MOD;
  return ans;
}

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

int fpow(int b, int e) {
  int ans = 1;
  for (; e; e >>= 1) {
    if (e & 1)
      ans = mul(ans, b);
    b = mul(b, b);
  }
  return ans;
}

int f[MAXN];
int choose(int n, int k) {
  assert(k <= n);
  return mul(f[n], fpow(mul(f[k], f[n - k]), MOD - 2));
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  f[0] = 1;
  for (int i = 1; i < MAXN; ++i) {
    f[i] = mul(f[i - 1], i);
  }
  int n, k, ans = 0;
  cin >> k;
  string s;
  cin >> s;
  n = s.size() + k;
  k = s.size();
  for (int j = 0; j <= n - k; ++j) {
    ans = add(ans, mul(choose(n, j + k), fpow(25, n - k - j)));
  }
  cout << ans << '\n';
  return 0;
}