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

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

ll mpower(ll a, ll b, ll c) {
  int z;
  if (b == 0) {
    z = 1;
    z %= c;
    return z;
  }
  if (b == 1) {
    z = a;
    z %= c;
    return z;
  } else {
    return (((mpower(a, b / 2, c)) * (mpower(a, b / 2, c)) % c) *
            mpower(a, b % 2, c) % c);
  }
}

const int MAX = 1100000;
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() {
  COMinit();
  ll mod = 1e9 + 7;
  int k;
  string S;
  cin >> k >> S;
  int s = S.size();
  ll ans = mpower(26, s + k, mod);
  ll ansb = 0;
  for (ll i = 0; i < s; i++) {
    ansb += mpower(25, s + k - i, mod) * COM(s + k, i);
    ansb %= mod;
  }
  ans -= ansb;
  while (ans < 0) {
    ans += mod;
  }
  cout << ans << endl;
}

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

ll mpower(ll a, ll b, ll c) {
  int z;
  if (b == 0) {
    z = 1;
    z %= c;
    return z;
  }
  if (b == 1) {
    z = a;
    z %= c;
    return z;
  } else {
    return (((mpower(a, b / 2, c)) * (mpower(a, b / 2, c)) % c) *
            mpower(a, b % 2, c) % c);
  }
}

const int MAX = 2100000;
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() {
  COMinit();
  ll mod = 1e9 + 7;
  int k;
  string S;
  cin >> k >> S;
  int s = S.size();
  ll ans = mpower(26, s + k, mod);
  ll ansb = 0;
  for (ll i = 0; i < s; i++) {
    ansb += mpower(25, s + k - i, mod) * COM(s + k, i);
    ansb %= mod;
  }
  ans -= ansb;
  while (ans < 0) {
    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 MAX = 1000005;
ll mod = 1000000007;
ll fac[MAX];
ll finv[MAX];
ll inv[MAX];

// 階乗、逆階乗のテーブル作成
void conInit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (ll i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % mod;
    inv[i] = mod - inv[mod % i] * (mod / i) % mod;
    finv[i] = finv[i - 1] * inv[i] % mod;
  }
}
// nCk mod
ll con(ll n, ll k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

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

int main() {
  conInit();

  ll K;
  string S;
  ll sum = 0;

  cin >> K;
  cin >> S;
  ll sNum = S.size();

  for (int i = 0; i <= K; i++) {
    ll sumsub = (modPow(25, i) % mod * modPow(26, K - i) % mod) % mod;

    ll r = sNum - 1;
    ll n = i + r;
    sumsub *= con(n, r) % mod;
    sum += sumsub % mod;
  }
  cout << sum % mod << endl;
}

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

const ll MAX = 2000005;
ll mod = 1000000007;
ll fac[MAX];
ll finv[MAX];
ll inv[MAX];

// 階乗、逆階乗のテーブル作成
void conInit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (ll i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % mod;
    inv[i] = mod - inv[mod % i] * (mod / i) % mod;
    finv[i] = finv[i - 1] * inv[i] % mod;
  }
}
// nCk mod
ll con(ll n, ll k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

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

int main() {
  conInit();

  ll K;
  string S;
  ll sum = 0;

  cin >> K;
  cin >> S;
  ll sNum = S.size();

  for (int i = 0; i <= K; i++) {
    ll sumsub = (modPow(25, i) % mod * modPow(26, K - i) % mod) % mod;

    ll r = sNum - 1;
    ll n = i + r;
    sumsub *= con(n, r) % mod;
    sum += sumsub % mod;
  }
  cout << sum % mod << endl;
}
Problem p02632 (C++)

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

using namespace std;

const long long mod = 1e9 + 7ll;

long long modpower(long long a, long long b) {
  if (b == 0)
    return 1ll;
  long long x = modpower(a, b / 2ll);
  x = (x * x) % mod;
  if (b & 1)
    return (x * a) % mod;
  return (x % mod);
}

struct combination {
  vector<long long> fact, inv;
  combination(int sz) : fact(sz + 1), inv(sz + 1) {
    fact[0] = 1ll;
    inv[0] = 1ll;
    for (long long i = 1; i <= sz; ++i)
      fact[i] = (fact[i - 1] * i) % mod;
    inv[sz] = modpower(fact[sz], mod - 2ll);
    for (long long i = sz - 1; i >= 1; --i)
      inv[i] = (inv[i + 1] * (i + 1)) % mod;
  }
  long long choose(int n, int k) const {
    if (k < 0 || n < k)
      return 0;
    return ((((fact[n] * inv[k]) % mod) * inv[n - k]) % mod);
  }
};

const int MAX = 1e6 + 10;

combination comb(MAX);
int n, m;
string s;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  cin >> s;
  m = s.size();
  n += m;
  long long ans = 0ll;
  for (int i = m; i <= n; ++i) {
    long long x = modpower(26, n - i);
    long long a = comb.choose(i - 1, m - 1);
    long long y = (a * modpower(25, i - m)) % mod;
    x = (x * y) % mod;
    ans = (ans + x) % mod;
  }
  return cout << ans << "\n", 0;
}

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

using namespace std;

const long long mod = 1e9 + 7ll;

long long modpower(long long a, long long b) {
  if (b == 0)
    return 1ll;
  long long x = modpower(a, b / 2ll);
  x = (x * x) % mod;
  if (b & 1)
    return (x * a) % mod;
  return (x % mod);
}

struct combination {
  vector<long long> fact, inv;
  combination(int sz) : fact(sz + 1), inv(sz + 1) {
    fact[0] = 1ll;
    inv[0] = 1ll;
    for (long long i = 1; i <= sz; ++i)
      fact[i] = (fact[i - 1] * i) % mod;
    inv[sz] = modpower(fact[sz], mod - 2ll);
    for (long long i = sz - 1; i >= 1; --i)
      inv[i] = (inv[i + 1] * (i + 1)) % mod;
  }
  long long choose(int n, int k) const {
    if (k < 0 || n < k)
      return 0;
    return ((((fact[n] * inv[k]) % mod) * inv[n - k]) % mod);
  }
};

const int MAX = 2e6 + 10;

combination comb(MAX);
int n, m;
string s;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  cin >> s;
  m = s.size();
  n += m;
  long long ans = 0ll;
  for (int i = m; i <= n; ++i) {
    long long x = modpower(26, n - i);
    long long a = comb.choose(i - 1, m - 1);
    long long y = (a * modpower(25, i - m)) % mod;
    x = (x * y) % mod;
    ans = (ans + x) % mod;
  }
  return cout << ans << "\n", 0;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()

typedef tree<ll, null_type, less<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)
const ll nax = 1e6;
ll fact[nax + 1];
ll mod = 1e9 + 7;
ll power(ll x, ll y) {
  ll ans = 1;
  while (y) {
    if (y & 1) {
      ans = (ans * x) % mod;
    }
    y /= 2;
    x = (x * x) % mod;
  }
  return ans;
}
ll modinverse(ll x) { return power(x, mod - 2); }
ll combi(ll n, ll r) {
  return (fact[n] * modinverse((fact[r] * fact[n - r]) % mod)) % mod;
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll k, i;
  string s;
  cin >> k >> s;
  fact[0] = 1;
  for (i = 1; i < nax + 1; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
  }
  ll tot = power(26, k + s.length());
  for (i = 0; i < s.length(); i++) {
    tot = ((tot - combi(k + s.length(), i) * power(25, k + s.length() - i)) %
               mod +
           mod) %
          mod;
  }
  cout << tot << "\n";
}

Fixed submission:
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()

typedef tree<ll, null_type, less<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)
const ll nax = 3e6;
ll fact[nax + 1];
ll mod = 1e9 + 7;
ll power(ll x, ll y) {
  ll ans = 1;
  while (y) {
    if (y & 1) {
      ans = (ans * x) % mod;
    }
    y /= 2;
    x = (x * x) % mod;
  }
  return ans;
}
ll modinverse(ll x) { return power(x, mod - 2); }
ll combi(ll n, ll r) {
  return (fact[n] * modinverse((fact[r] * fact[n - r]) % mod)) % mod;
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll k, i;
  string s;
  cin >> k >> s;
  fact[0] = 1;
  for (i = 1; i < nax + 1; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
  }
  ll tot = power(26, k + s.length());
  for (i = 0; i < s.length(); i++) {
    tot = ((tot - combi(k + s.length(), i) * power(25, k + s.length() - i)) %
               mod +
           mod) %
          mod;
  }
  cout << tot << "\n";
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 10;
const ll mod = 1e9 + 7;
ll fac[maxn], inv[maxn], facinv[maxn], bin25[maxn], bin26[maxn];
void pre() {
  fac[0] = 1;
  for (int i = 1; i < maxn; ++i)
    fac[i] = fac[i - 1] * i % mod;
  inv[1] = 1;
  for (int i = 2; i < maxn; ++i)
    inv[i] = (mod - mod / i) * inv[mod % i] % mod;
  facinv[0] = 1;
  for (int i = 1; i < maxn; ++i)
    facinv[i] = facinv[i - 1] * inv[i] % mod;
  bin25[0] = 1;
  for (int i = 1; i < maxn; ++i)
    bin25[i] = bin25[i - 1] * 25 % mod;
  bin26[0] = 1;
  for (int i = 1; i < maxn; ++i)
    bin26[i] = bin26[i - 1] * 26 % mod;
}
ll C(int n, int m) {
  return n < m ? 0 : fac[n] * facinv[m] % mod * facinv[n - m] % mod;
}
ll ans;
int main() {
  int k;
  string s;
  cin >> k >> s;
  int n = s.length();
  int m = k + n;
  pre();
  for (int i = 0; i <= k; ++i)
    ans = (ans + bin26[i] * C(m - i - 1, n - 1) % mod * bin25[m - i - n]) % mod;
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e6 + 10;
const ll mod = 1e9 + 7;
ll fac[maxn], inv[maxn], facinv[maxn], bin25[maxn], bin26[maxn];
void pre() {
  fac[0] = 1;
  for (int i = 1; i < maxn; ++i)
    fac[i] = fac[i - 1] * i % mod;
  inv[1] = 1;
  for (int i = 2; i < maxn; ++i)
    inv[i] = (mod - mod / i) * inv[mod % i] % mod;
  facinv[0] = 1;
  for (int i = 1; i < maxn; ++i)
    facinv[i] = facinv[i - 1] * inv[i] % mod;
  bin25[0] = 1;
  for (int i = 1; i < maxn; ++i)
    bin25[i] = bin25[i - 1] * 25 % mod;
  bin26[0] = 1;
  for (int i = 1; i < maxn; ++i)
    bin26[i] = bin26[i - 1] * 26 % mod;
}
ll C(int n, int m) {
  return n < m ? 0 : fac[n] * facinv[m] % mod * facinv[n - m] % mod;
}
ll ans;
int main() {
  int k;
  string s;
  cin >> k >> s;
  int n = s.length();
  int m = k + n;
  pre();
  for (int i = 0; i <= k; ++i)
    ans = (ans + bin26[i] * C(m - i - 1, n - 1) % mod * bin25[m - i - n]) % mod;
  cout << ans << endl;
  return 0;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define INF (1ll << 60)
#define mod 1000000007
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

#define MAX 1000100
ll fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (ll i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % mod;
    inv[i] = mod - inv[mod % i] * (mod / i) % mod;
    finv[i] = finv[i - 1] * inv[i] % mod;
  }
}
// 二項係数計算
ll combi(ll n, ll k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
// mainに   COMinit();   を入れる

ll modpow(ll x, ll n) {
  ll ret = 1;
  while (n > 0) {
    if (n & 1)
      ret = ret * x % mod; // n の最下位bitが 1 ならば x^(2^i) をかける
    x = x * x % mod;
    n >>= 1; // n を1bit 左にずらす
  }
  return ret;
}

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

  ll minus = 0, ans = modpow(26ll, n + k);
  rep(i, n) {
    minus += (combi(n + k, i) * modpow(25ll, n + k - i)) % mod;
    minus %= mod;
  }

  ans -= minus;
  if (ans < 0)
    ans += mod;
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define INF (1ll << 60)
#define mod 1000000007
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

#define MAX 2000100
ll fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (ll i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % mod;
    inv[i] = mod - inv[mod % i] * (mod / i) % mod;
    finv[i] = finv[i - 1] * inv[i] % mod;
  }
}
// 二項係数計算
ll combi(ll n, ll k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
// mainに   COMinit();   を入れる

ll modpow(ll x, ll n) {
  ll ret = 1;
  while (n > 0) {
    if (n & 1)
      ret = ret * x % mod; // n の最下位bitが 1 ならば x^(2^i) をかける
    x = x * x % mod;
    n >>= 1; // n を1bit 左にずらす
  }
  return ret;
}

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

  ll minus = 0, ans = modpow(26ll, n + k);
  rep(i, n) {
    minus += (combi(n + k, i) * modpow(25ll, n + k - i)) % mod;
    minus %= mod;
  }

  ans -= minus;
  if (ans < 0)
    ans += mod;
  cout << ans << endl;
  return 0;
}
Problem p02632 (C++)

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

typedef long long ll;

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

ll mod_pow(ll x, ll n) { // べき乗
  ll ans = 1;
  x %= MOD;
  while (n != 0) {
    if (n & 1)
      ans = ans * x % MOD;
    x = x * x % MOD;
    n = n >> 1;
  }
  return ans % MOD;
}

void com_init() { // 初期化
  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;
    finv[i] = finv[i - 1] * mod_pow(i, MOD - 2) % MOD; // フェルマーの小定理より
  }
}

ll comb(ll n, ll k) { // nCk
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

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

typedef long long ll;

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

ll mod_pow(ll x, ll n) { // べき乗
  ll ans = 1;
  x %= MOD;
  while (n != 0) {
    if (n & 1)
      ans = ans * x % MOD;
    x = x * x % MOD;
    n = n >> 1;
  }
  return ans % MOD;
}

void com_init() { // 初期化
  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;
    finv[i] = finv[i - 1] * mod_pow(i, MOD - 2) % MOD; // フェルマーの小定理より
  }
}

ll comb(ll n, ll k) { // nCk
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

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

const long long mod = 1e9 + 7;
const long long N = 1e6 + 10;

long long fact[N];

template <typename T> void add_self(T &a, T b) {
  a += b;
  if (a > mod) {
    a -= mod;
  }
}

template <typename T> void substract_self(T &a, T b) {
  a -= b;
  if (a < 0) {
    a += mod;
  }
}

template <typename T> long long mul(T a, T b) { return (a * b) % mod; }

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

long long modInverse(long long a) { return power(a, (long long)(mod - 2)); }

long long nCr(long long n, long long r) {
  long long val =
      mul(fact[n], mul(modInverse(fact[n - r]), modInverse(fact[r])));
  return val;
}

int main() {
  fact[0] = 1;
  for (int i = 1; i < N; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
  }
  long long n, k;
  cin >> k;
  string s;
  cin >> s;
  n = s.length();
  long long sol = power(26ll, n + k);
  for (int i = 0; i < n; i++) {
    long long val = mul(nCr(n + k, i), power(25ll, n + k - i));
    substract_self(sol, val);
  }
  cout << sol;

  return 0;
}

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

const long long mod = 1e9 + 7;
const long long N = 2e6 + 10;

long long fact[N];

template <typename T> void add_self(T &a, T b) {
  a += b;
  if (a > mod) {
    a -= mod;
  }
}

template <typename T> void substract_self(T &a, T b) {
  a -= b;
  if (a < 0) {
    a += mod;
  }
}

template <typename T> long long mul(T a, T b) { return (a * b) % mod; }

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

long long modInverse(long long a) { return power(a, (long long)(mod - 2)); }

long long nCr(long long n, long long r) {
  long long val =
      mul(fact[n], mul(modInverse(fact[n - r]), modInverse(fact[r])));
  return val;
}

int main() {
  fact[0] = 1;
  for (int i = 1; i < N; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
  }
  long long n, k;
  cin >> k;
  string s;
  cin >> s;
  n = s.length();
  long long sol = power(26ll, n + k);
  for (int i = 0; i < n; i++) {
    long long val = mul(nCr(n + k, i), power(25ll, n + k - i));
    substract_self(sol, val);
  }
  cout << sol;

  return 0;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int M = 1e6 + 5;
const int mod = 1e9 + 7;
int k, ans, f[M], inv[M];
string s;

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

int modInv(int a) { return power(a, mod - 2); }

void precompute() {
  f[0] = f[1] = 1;
  for (int i = 2; i < M; i++)
    f[i] = (f[i - 1] * i) % mod;
  inv[M - 1] = modInv(f[M - 1]);
  for (int i = M - 2; i >= 0; i--)
    inv[i] = (inv[i + 1] * (i + 1)) % mod;
}

int nCr(int n, int r) {
  if (n < r)
    return 0;
  int res = f[n];
  res = (res * inv[r]) % mod;
  res = (res * inv[n - r]) % mod;
  return res % mod;
}

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  precompute();
  cin >> k >> s;
  int n = s.size();
  for (int i = 0; i <= k; i++) {
    int cur = nCr(n + k, n + i);
    cur = (cur * power(25, k - i)) % mod;
    ans = (ans + cur) % mod;
  }
  cout << ans << "\n";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int M = 2e6 + 5;
const int mod = 1e9 + 7;
int k, ans, f[M], inv[M];
string s;

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

int modInv(int a) { return power(a, mod - 2); }

void precompute() {
  f[0] = f[1] = 1;
  for (int i = 2; i < M; i++)
    f[i] = (f[i - 1] * i) % mod;
  inv[M - 1] = modInv(f[M - 1]);
  for (int i = M - 2; i >= 0; i--)
    inv[i] = (inv[i + 1] * (i + 1)) % mod;
}

int nCr(int n, int r) {
  if (n < r)
    return 0;
  int res = f[n];
  res = (res * inv[r]) % mod;
  res = (res * inv[n - r]) % mod;
  return res % mod;
}

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  precompute();
  cin >> k >> s;
  int n = s.size();
  for (int i = 0; i <= k; i++) {
    int cur = nCr(n + k, n + i);
    cur = (cur * power(25, k - i)) % mod;
    ans = (ans + cur) % mod;
  }
  cout << ans << "\n";
  return 0;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int k, n, l;
long long res, MOD = 1000000007, p25[1000100], comb;
long long inv[1000100];
void init_math(int N) {
  inv[1] = 1LL;
  for (int i = 2; i <= N; i++)
    inv[i] = (MOD - ((MOD / i) * inv[MOD % i]) % MOD);
}
string s;
int main() {
  cin >> k >> s;
  n = s.size() + k;
  l = s.size();
  init_math(n);
  p25[0] = 1;
  for (int x = 1; x <= n; x++)
    p25[x] = (p25[x - 1] * 25LL) % MOD;
  comb = 1;
  for (int x = 1; x <= n; x++) {
    comb = (comb * (long long)(n - x + 1)) % MOD;
    comb = (comb * inv[x]) % MOD;
    if (x >= l)
      res = (res + comb * p25[n - x] % MOD) % MOD;
  }
  cout << res << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int k, n, l;
long long res, MOD = 1000000007, p25[2000100], comb;
long long inv[2000100];
void init_math(int N) {
  inv[1] = 1LL;
  for (int i = 2; i <= N; i++)
    inv[i] = (MOD - ((MOD / i) * inv[MOD % i]) % MOD);
}
string s;
int main() {
  cin >> k >> s;
  n = s.size() + k;
  l = s.size();
  init_math(n);
  p25[0] = 1;
  for (int x = 1; x <= n; x++)
    p25[x] = (p25[x - 1] * 25LL) % MOD;
  comb = 1;
  for (int x = 1; x <= n; x++) {
    comb = (comb * (long long)(n - x + 1)) % MOD;
    comb = (comb * inv[x]) % MOD;
    if (x >= l)
      res = (res + comb * p25[n - x] % MOD) % MOD;
  }
  cout << res << endl;
  return 0;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string.h>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 2e18;
const ll MOD = 1e9 + 7;

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

const ll MAX = 1000000;
ll fac[MAX], finv[MAX], inv[MAX];
// nCk初期化
void nCkInit(const ll MOD) { // O(max(n,r)logmax(n,r) mは素数)
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (ll i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
ll nCk(ll n, ll k, const ll MOD) { // init後,O(1)
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll K;
string S;
map<char, ll> mp;
int main() {
  cin >> K >> S;
  nCkInit(MOD);
  ll ans = 0;
  for (ll i = 0; i <= K; i++) {
    ans = (ans + nCk(K + S.length() - 1 - i, S.length() - 1, MOD) *
                     modpow(25, K - i, MOD) % MOD * modpow(26, i, MOD) % MOD) %
          MOD;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cassert>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string.h>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 2e18;
const ll MOD = 1e9 + 7;

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

const ll MAX = 2000000;
ll fac[MAX], finv[MAX], inv[MAX];
// nCk初期化
void nCkInit(const ll MOD) { // O(max(n,r)logmax(n,r) mは素数)
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (ll i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
ll nCk(ll n, ll k, const ll MOD) { // init後,O(1)
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll K;
string S;
map<char, ll> mp;
int main() {
  cin >> K >> S;
  nCkInit(MOD);
  ll ans = 0;
  for (ll i = 0; i <= K; i++) {
    ans = (ans + nCk(K + S.length() - 1 - i, S.length() - 1, MOD) *
                     modpow(25, K - i, MOD) % MOD * modpow(26, i, MOD) % MOD) %
          MOD;
  }
  cout << ans << endl;
  return 0;
}
Problem p02632 (C++)

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

ll mul(ll a, ll b) { return (a * b) % M; }
ll mod_pow(ll a, ll b) {
  ll r = 1;
  while (b) {
    if (b & 1)
      r = mul(r, a);
    b >>= 1;
    a = mul(a, a);
  }
  return r;
}
struct combination {
  vector<int> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < M);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i)
      fact[i] = mul(fact[i - 1], i);
    ifact[n] = mod_pow(fact[n], M - 2);
    for (int i = n; i >= 1; --i)
      ifact[i - 1] = mul(ifact[i], i);
  }
  int operator()(int n, int k) {
    assert(k >= 0 && k <= n);
    return mul(fact[n], mul(ifact[k], ifact[n - k]));
  }
} C(200005);

void solve() {
  int k;
  string s;
  cin >> k >> s;
  int n = s.size();

  ll ans = 0;
  for (int i = 0; i <= k; ++i) {
    ll now = mod_pow(25, i);
    now = (now * mod_pow(26, k - i)) % M;
    now = (now * C(n - 1 + i, n - 1)) % M;
    ans = (ans + now) % M;
  }
  cout << ans << endl;
}

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

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

ll mul(ll a, ll b) { return (a * b) % M; }
ll mod_pow(ll a, ll b) {
  ll r = 1;
  while (b) {
    if (b & 1)
      r = mul(r, a);
    b >>= 1;
    a = mul(a, a);
  }
  return r;
}
struct combination {
  vector<int> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < M);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i)
      fact[i] = mul(fact[i - 1], i);
    ifact[n] = mod_pow(fact[n], M - 2);
    for (int i = n; i >= 1; --i)
      ifact[i - 1] = mul(ifact[i], i);
  }
  int operator()(int n, int k) {
    assert(k >= 0 && k <= n);
    return mul(fact[n], mul(ifact[k], ifact[n - k]));
  }
} C(2000005);

void solve() {
  int k;
  string s;
  cin >> k >> s;
  int n = s.size();

  ll ans = 0;
  for (int i = 0; i <= k; ++i) {
    ll now = mod_pow(25, i);
    now = (now * mod_pow(26, k - i)) % M;
    now = (now * C(n - 1 + i, n - 1)) % M;
    ans = (ans + now) % M;
  }
  cout << ans << endl;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  solve();
}
Problem p02632 (C++)

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

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

ll inv(ll x) {
  ll res = 1;
  ll k = MOD - 2;
  ll y = x;
  while (k) {
    if (k & 1)
      res = (res * y) % MOD;
    y = (y * y) % MOD;
    k /= 2;
  }
  return res;
}

ll C(int n, int k) {
  ll a = f[n];
  ll b = f[n - k];
  ll c = f[k];
  ll bc = (b * c) % MOD;
  return (a * inv(bc)) % MOD;
}

ll powmod(ll a, ll n, ll m = MOD) {
  ll ret = 1;
  for (; n > 0; n >>= 1, a = a * a % m) {
    if (n % 2 == 1) {
      ret = ret * a % m;
    }
  }
  return ret;
}

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

  int n = s.size() + k, m = s.size();

  ll ans = 0;
  for (int i = m; i <= n; i++) {
    ll d = C(i - 1, m - 1) * powmod(25, i - m);
    d %= MOD;
    d *= powmod(26, n - i);
    d %= MOD;
    ans += d;
    ans %= MOD;
    // cout << i << " " << d << " " << ans << endl;
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr int MOD = 1000000007;
constexpr int MAX = 2000005;

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

ll inv(ll x) {
  ll res = 1;
  ll k = MOD - 2;
  ll y = x;
  while (k) {
    if (k & 1)
      res = (res * y) % MOD;
    y = (y * y) % MOD;
    k /= 2;
  }
  return res;
}

ll C(int n, int k) {
  ll a = f[n];
  ll b = f[n - k];
  ll c = f[k];
  ll bc = (b * c) % MOD;
  return (a * inv(bc)) % MOD;
}

ll powmod(ll a, ll n, ll m = MOD) {
  ll ret = 1;
  for (; n > 0; n >>= 1, a = a * a % m) {
    if (n % 2 == 1) {
      ret = ret * a % m;
    }
  }
  return ret;
}

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

  int n = s.size() + k, m = s.size();

  ll ans = 0;
  for (int i = m; i <= n; i++) {
    ll d = C(i - 1, m - 1) * powmod(25, i - m);
    d %= MOD;
    d *= powmod(26, n - i);
    d %= MOD;
    ans += d;
    ans %= MOD;
    // cout << i << " " << d << " " << ans << endl;
  }

  cout << ans << endl;

  return 0;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
#include <vector>
using namespace std;

const int MAX = 1001000;
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(int x, int r) {
  if (r == 0) {
    return 1;
  } else if (r % 2 == 0) {
    long long tmp = modpow(x, r / 2);
    return tmp % mod * tmp % mod;
  } else {
    return x % mod * modpow(x, r - 1) % mod;
  }
}

int main() {
  COMinit();
  long long K;
  string S;
  cin >> K >> S;
  long long L = S.length() + K;
  long long N = S.length();
  long long ans = 0;
  for (long long i = N; i <= L; i++) {
    // S_N以降の文字数
    long long p = L - i;
    ans += COM(L - p - 1, N - 1) % mod * modpow(25, K - p) % mod *
           modpow(26, p) % mod;
    ans %= mod;
  }
  cout << ans << endl;
}

Fixed submission:
#include <iostream>
#include <string>
#include <vector>
using namespace std;

const int MAX = 10000000;
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(int x, int r) {
  if (r == 0) {
    return 1;
  } else if (r % 2 == 0) {
    long long tmp = modpow(x, r / 2);
    return tmp % mod * tmp % mod;
  } else {
    return x % mod * modpow(x, r - 1) % mod;
  }
}

int main() {
  COMinit();
  long long K;
  string S;
  cin >> K >> S;
  long long L = S.length() + K;
  long long N = S.length();
  long long ans = 0;
  for (long long i = N; i <= L; i++) {
    // S_N以降の文字数
    long long p = L - i;
    ans += COM(L - p - 1, N - 1) % mod * modpow(25, K - p) % mod *
           modpow(26, p) % mod;
    ans %= mod;
  }
  cout << ans << endl;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define FASTIO                                                                 \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define LL long long int
using namespace std;

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

LL powermod(LL a, LL b) {
  if (b == 0)
    return 1;
  LL res = powermod(a, b / 2);
  res = (res * res) % MOD;
  if (b & 1)
    res = (res * a) % MOD;
  return res;
}
int fac[N], invfac[N];
void pre() {
  fac[0] = 1;
  for (int i = 1; i < N; ++i)
    fac[i] = (fac[i - 1] * 1LL * i) % MOD;
  invfac[N - 1] = powermod(fac[N - 1], MOD - 2);
  for (int i = N - 2; i >= 0; --i) {
    invfac[i] = (invfac[i + 1] * 1LL * (i + 1)) % MOD;
  }
}
LL ncr(int n, int r) {
  if (r < 0 || r > n)
    return 0;
  LL ans = (fac[n] * 1LL * invfac[r]) % MOD;
  ans = (ans * 1LL * invfac[n - r]) % MOD;
  return ans;
}
void solve() {
  int k;
  cin >> k;
  string str;
  cin >> str;
  int s = str.size();
  LL ans = 0, sixinv = powermod(26, MOD - 2), have = 1, have2 = powermod(26, k);
  for (int i = 0; i <= k; ++i) {
    ans += ((ncr(s + i - 1, s - 1) * have) % MOD * have2) % MOD;
    have2 = (have2 * sixinv) % MOD;
    have = (have * 25) % MOD;
    if (ans >= MOD)
      ans -= MOD;
  }
  cout << ans << '\n';
}

int main() {
  FASTIO;
  pre();
  int t = 1;
  // cin >> t;
  while (t--)
    solve();
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define FASTIO                                                                 \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define LL long long int
using namespace std;

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

LL powermod(LL a, LL b) {
  if (b == 0)
    return 1;
  LL res = powermod(a, b / 2);
  res = (res * res) % MOD;
  if (b & 1)
    res = (res * a) % MOD;
  return res;
}
int fac[N], invfac[N];
void pre() {
  fac[0] = 1;
  for (int i = 1; i < N; ++i)
    fac[i] = (fac[i - 1] * 1LL * i) % MOD;
  invfac[N - 1] = powermod(fac[N - 1], MOD - 2);
  for (int i = N - 2; i >= 0; --i) {
    invfac[i] = (invfac[i + 1] * 1LL * (i + 1)) % MOD;
  }
}
LL ncr(int n, int r) {
  if (r < 0 || r > n)
    return 0;
  LL ans = (fac[n] * 1LL * invfac[r]) % MOD;
  ans = (ans * 1LL * invfac[n - r]) % MOD;
  return ans;
}
void solve() {
  int k;
  cin >> k;
  string str;
  cin >> str;
  int s = str.size();
  LL ans = 0, sixinv = powermod(26, MOD - 2), have = 1, have2 = powermod(26, k);
  for (int i = 0; i <= k; ++i) {
    ans += ((ncr(s + i - 1, s - 1) * have) % MOD * have2) % MOD;
    have2 = (have2 * sixinv) % MOD;
    have = (have * 25) % MOD;
    if (ans >= MOD)
      ans -= MOD;
  }
  cout << ans << '\n';
}

int main() {
  FASTIO;
  pre();
  int t = 1;
  // cin >> t;
  while (t--)
    solve();
  return 0;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define all(x) (x).begin(), (x).end()
const int INF = 1e9 + 5;
const int N = 1e6 + 5;
const int mod = 1e9 + 7;

ll fac[N];

ll mul(ll a, ll b) { return a * b % mod; }

ll poww(ll a, ll b) {
  ll r = 1;
  while (b) {
    if (b & 1)
      r = mul(r, a);
    a = mul(a, a);
    b >>= 1;
  }
  return r;
}

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

void add_self(ll &a, ll b) {
  a += b;
  a %= mod;
}

void init() {
  fac[0] = fac[1] = 1;
  for (int i = 2; i < N; ++i) {
    fac[i] = mul(fac[i - 1], 1ll * i);
  }
}

ll bino(ll n, ll k) {
  if (k < 0)
    return 1;
  if (!k)
    return 1;
  return mul(fac[n], mul(inv(fac[n - k]), inv(fac[k])));
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  init();
  ll k;
  string s;
  cin >> k >> s;
  ll n = (ll)s.size();
  ll ans = 0;
  for (ll last = 0; last <= k; ++last) {
    ll ch26 = poww(26, last);
    ll ch25 = poww(25, k - last);
    ll chpos = bino(k + n - last - 1, n - 1);
    ll cur = mul(ch26, mul(ch25, chpos));
    add_self(ans, cur);
  }
  cout << ans;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define all(x) (x).begin(), (x).end()
const int INF = 1e9 + 5;
const int N = 2e6 + 10;
const ll mod = 1e9 + 7;

ll fac[N];

ll mul(ll a, ll b) { return a * b % mod; }

ll poww(ll a, ll b) {
  ll r = 1;
  while (b) {
    if (b & 1)
      r = mul(r, a);
    a = mul(a, a);
    b >>= 1;
  }
  return r;
}

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

void add_self(ll &a, ll b) {
  a += b;
  a %= mod;
}

void init() {
  fac[0] = fac[1] = 1;
  for (int i = 2; i < N; ++i) {
    fac[i] = mul(fac[i - 1], 1ll * i);
  }
}

ll bino(ll n, ll k) {
  if (k < 0)
    return 1;
  if (!k)
    return 1;
  return mul(fac[n], mul(inv(fac[n - k]), inv(fac[k])));
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  init();
  ll k;
  string s;
  cin >> k >> s;
  ll n = (ll)s.size();
  ll ans = 0;
  for (ll last = 0; last <= k; ++last) {
    ll ch26 = poww(26, last);
    ll ch25 = poww(25, k - last);
    ll chpos = bino(k + n - last - 1, n - 1);
    ll cur = mul(ch26, mul(ch25, chpos));
    add_self(ans, cur);
  }
  cout << ans;
  return 0;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define db(a) cout << fixed << #a << " = " << a << endl;

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const ll MOD = 1e9 + 7;
const int MAXN = 1e6 + 10;
ll fact[MAXN];
ll powd[MAXN];
ll b_pow(ll x, ll m) {
  if (m == 1LL)
    return x % MOD;
  if (m == 0LL)
    return 1LL;
  if (m % 2LL == 0LL) {
    return b_pow((x * x) % MOD, m / 2LL) % MOD;
  } else {
    return (x * b_pow((x * x) % MOD, m / 2LL)) % MOD;
  }
}

ll inverse(ll x) {
  if (x == 0)
    return 1LL;
  return b_pow(x, MOD - 2) % MOD;
}
ll nCk(ll n, ll k) {
  if (n < k)
    return 0LL;
  return (((fact[n] % MOD) * inverse(fact[n - k])) % MOD * inverse(fact[k])) %
         MOD;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  fact[0] = 1;
  powd[0] = 1;
  for (ll i = 1; i < MAXN - 1; i++) {
    fact[i] = fact[i - 1] * i;
    fact[i] %= MOD;
    powd[i] = powd[i - 1] * 25;
    powd[i] %= MOD;
  }

  ll n;
  cin >> n;
  string S;
  cin >> S;
  ll k = S.size();
  ll r = 0;
  n += k;
  for (int j = 0; j <= n - k; j++) {
    // db(nCk(n, j + k)*powd[n - k - j]);
    r += nCk(n, j + k) * powd[n - k - j];
    r %= MOD;
  }
  cout << r << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define db(a) cout << fixed << #a << " = " << a << endl;

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const ll MOD = 1e9 + 7;
const int MAXN = 2e6 + 10;
ll fact[MAXN];
ll powd[MAXN];
ll b_pow(ll x, ll m) {
  if (m == 1LL)
    return x % MOD;
  if (m == 0LL)
    return 1LL;
  if (m % 2LL == 0LL) {
    return b_pow((x * x) % MOD, m / 2LL) % MOD;
  } else {
    return (x * b_pow((x * x) % MOD, m / 2LL)) % MOD;
  }
}

ll inverse(ll x) {
  if (x == 0)
    return 1LL;
  return b_pow(x, MOD - 2) % MOD;
}
ll nCk(ll n, ll k) {
  if (n < k)
    return 0LL;
  return (((fact[n] % MOD) * inverse(fact[n - k])) % MOD * inverse(fact[k])) %
         MOD;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  fact[0] = 1;
  powd[0] = 1;
  for (ll i = 1; i < MAXN - 1; i++) {
    fact[i] = fact[i - 1] * i;
    fact[i] %= MOD;
    powd[i] = powd[i - 1] * 25;
    powd[i] %= MOD;
  }

  ll n;
  cin >> n;
  string S;
  cin >> S;
  ll k = S.size();
  ll r = 0;
  n += k;
  for (int j = 0; j <= n - k; j++) {
    // db(nCk(n, j + k)*powd[n - k - j]);
    r += nCk(n, j + k) * powd[n - k - j];
    r %= MOD;
  }
  cout << r << endl;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
// Problem Link:
// Tutorial Link:

#include <bits/stdc++.h>

using namespace std;

#define LL long long
#define pb push_back
#define pLL pair<LL, LL>
#define ff first
#define ss second
#define rep(i, a, b) for (LL i = a; i <= b; ++i)
#define repb(i, a, b) for (LL i = a; i >= b; --i)
#define ld double
#define mp make_pair
#define vLL vector<LL>
#define vpLL vector<pLL>
#define vld vector<ld>
#define pld pair<ld, ld>
#define vpld vector<pld>
#define SLL set<LL>
#define SpLL set<pLL>
#define FIO ios::sync_with_stdio(false)
#define mod 1000000007

LL poww(LL a, LL n) {
  if (n == 0)
    return 1;
  LL val = poww(a, n / 2);
  if (n % 2 == 0)
    return (val * val) % mod;
  else
    return (((val * val) % mod) * a) % mod;
}

LL k, n, fact[1000005], inv[1000005];
string s;

inline LL comb(LL n, LL k) {
  if (n == 0 || k == 0 || n - k < 0)
    return 1;
  return (((fact[n] * inv[k]) % mod) * inv[n - k]) % mod;
}

int main() {
  FIO;
  cin >> k >> s;
  fact[0] = 1;
  inv[0] = 1;
  n = s.length();
  rep(i, 1, n + k + 2) {
    fact[i] = (fact[i - 1] * i) % mod;
    inv[i] = poww(fact[i], mod - 2);
  }
  LL ans = poww(26LL, n + k);
  rep(i, 0, n - 1) {
    LL val = comb(n + k, i);
    val = (val * poww(25, n + k - i)) % mod;
    ans = (ans + mod - val) % mod;
  }
  cout << ans << endl;
}

Fixed submission:
// Problem Link:
// Tutorial Link:

#include <bits/stdc++.h>

using namespace std;

#define LL long long
#define pb push_back
#define pLL pair<LL, LL>
#define ff first
#define ss second
#define rep(i, a, b) for (LL i = a; i <= b; ++i)
#define repb(i, a, b) for (LL i = a; i >= b; --i)
#define ld double
#define mp make_pair
#define vLL vector<LL>
#define vpLL vector<pLL>
#define vld vector<ld>
#define pld pair<ld, ld>
#define vpld vector<pld>
#define SLL set<LL>
#define SpLL set<pLL>
#define FIO ios::sync_with_stdio(false)
#define mod 1000000007

LL poww(LL a, LL n) {
  if (n == 0)
    return 1;
  LL val = poww(a, n / 2);
  if (n % 2 == 0)
    return (val * val) % mod;
  else
    return (((val * val) % mod) * a) % mod;
}

LL k, n, fact[3000005], inv[3000005];
string s;

inline LL comb(LL n, LL k) {
  if (n == 0 || k == 0 || n - k < 0)
    return 1;
  return (((fact[n] * inv[k]) % mod) * inv[n - k]) % mod;
}

int main() {
  FIO;
  cin >> k >> s;
  fact[0] = 1;
  inv[0] = 1;
  n = s.length();
  rep(i, 1, n + k + 2) {
    fact[i] = (fact[i - 1] * i) % mod;
    inv[i] = poww(fact[i], mod - 2);
  }
  LL ans = poww(26LL, n + k);
  rep(i, 0, n - 1) {
    LL val = comb(n + k, i);
    val = (val * poww(25, n + k - i)) % mod;
    ans = (ans + mod - val) % mod;
  }
  cout << ans << endl;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define fo(i, a, b) for ((i) = (a); i <= (b); i++)
#define rfo(i, a, b) for ((i) = (a); i >= (b); i--)
#define inrange(x, y, z) (((x) >= (y)) && ((x) <= (z)))
#define ALL(vec) ((vec).begin(), (vec).end())
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)), (vec).end())
using namespace std;
int k, n, l;
long long res, MOD = 1000000007, p25[1000100];
long long inv[1000100], fac[1000100], ifac[1000100];
void init_math(int N) {
  inv[1] = 1LL;
  for (int i = 2; i <= N; i++)
    inv[i] = (MOD - ((MOD / i) * inv[MOD % i]) % MOD);
  fac[0] = 1LL;
  ifac[0] = 1LL;
  for (int i = 1; i <= N; i++) {
    fac[i] = (fac[i - 1] * (long long)(i)) % MOD;
    ifac[i] = (ifac[i - 1] * inv[i]) % MOD;
  }
}
long long C(int x, int y) {
  return ((fac[x] * ifac[y]) % MOD * ifac[x - y]) % MOD;
}
string s;
int main() {
#ifdef FILIN
#ifndef DavidDesktop
  freopen(FILIN, "r", stdin);
  freopen(FILOUT, "w", stdout);
#endif
#endif
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> k >> s;
  n = s.size() + k;
  l = s.size();
  init_math(n);
  p25[0] = 1;
  for (int x = 1; x <= n; x++) {
    p25[x] = (p25[x - 1] * 25LL) % MOD;
  }
  for (int x = l; x <= n; x++) {
    res = (res + C(n, x) * p25[n - x] % MOD) % MOD;
  }
  cout << res << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define fo(i, a, b) for ((i) = (a); i <= (b); i++)
#define rfo(i, a, b) for ((i) = (a); i >= (b); i--)
#define inrange(x, y, z) (((x) >= (y)) && ((x) <= (z)))
#define ALL(vec) ((vec).begin(), (vec).end())
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)), (vec).end())
using namespace std;
int k, n, l;
long long res, MOD = 1000000007, p25[2000100];
long long inv[2000100], fac[2000100], ifac[2000100];
void init_math(int N) {
  inv[1] = 1LL;
  for (int i = 2; i <= N; i++)
    inv[i] = (MOD - ((MOD / i) * inv[MOD % i]) % MOD);
  fac[0] = 1LL;
  ifac[0] = 1LL;
  for (int i = 1; i <= N; i++) {
    fac[i] = (fac[i - 1] * (long long)(i)) % MOD;
    ifac[i] = (ifac[i - 1] * inv[i]) % MOD;
  }
}
long long C(int x, int y) {
  return ((fac[x] * ifac[y]) % MOD * ifac[x - y]) % MOD;
}
string s;
int main() {
#ifdef FILIN
#ifndef DavidDesktop
  freopen(FILIN, "r", stdin);
  freopen(FILOUT, "w", stdout);
#endif
#endif
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> k >> s;
  n = s.size() + k;
  l = s.size();
  init_math(n);
  p25[0] = 1;
  for (int x = 1; x <= n; x++) {
    p25[x] = (p25[x - 1] * 25LL) % MOD;
  }
  for (int x = l; x <= n; x++) {
    res = (res + C(n, x) * p25[n - x] % MOD) % MOD;
  }
  cout << res << endl;
  return 0;
}