alexjercan/bugnet huggingface dataset:
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

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

Error: 0

Fixed submission:

#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;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

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

Error: WA

Fixed submission:

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

#include <iostream>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

const int kFacMax = 2000000;

long long fac[kFacMax];
long long finv[kFacMax];
long long inv[kFacMax];

void combi_prepare(int mod) {
  fac[0] = 1;
  fac[1] = 1;
  finv[0] = 1;
  finv[1] = 1;
  inv[1] = 1;

  for (int i = 2; i < kFacMax; 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 combi(long long n, long long k, long long mod) {
  if (n < 0 || k < 0 || n < k)
    return 0;

  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

long long mod_pow(long long a, long long n, long long mod) {
  long long pow = 1;

  while (n > 0) {
    if (n & 1)
      pow = pow * a % mod;

    a = a * a % mod;
    n = n >> 1;
  }

  return pow;
}

int main() {
  const int MOD = 1000000007;

  combi_prepare(MOD);

  long long K;
  cin >> K;

  string S;
  cin >> S;

  long long sum = 0;
  for (long long i = 0; i <= K; i++) {
    long long left =
        combi(S.size() - 1 + i, S.size() - 1, MOD) * mod_pow(25, i, MOD) % MOD;
    long long right = mod_pow(26, K - i, MOD);
    sum += left * right % MOD;
    sum %= MOD;
  }
  cout << sum << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

const int kFacMax = 1000000;

long long fac[kFacMax];
long long finv[kFacMax];
long long inv[kFacMax];

void combi_prepare(int mod) {
  fac[0] = 1;
  fac[1] = 1;
  finv[0] = 1;
  finv[1] = 1;
  inv[1] = 1;

  for (int i = 2; i < kFacMax; 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 combi(long long n, long long k, long long mod) {
  if (n < 0 || k < 0 || n < k)
    return 0;

  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

long long mod_pow(long long a, long long n, long long mod) {
  long long pow = 1;

  while (n > 0) {
    if (n & 1)
      pow = pow * a % mod;

    a = a * a % mod;
    n = n >> 1;
  }

  return pow;
}

int main() {
  const int MOD = 1000000007;

  combi_prepare(MOD);

  long long K;
  cin >> K;

  string S;
  cin >> S;

  long long sum = 0;
  for (long long i = S.size(); i <= K + S.size(); i++) {
    long long left = combi(i - 1, S.size() - 1, MOD) *
                     mod_pow(25, (i - 1) - (S.size() - 1), MOD) % MOD;
    long long right = mod_pow(26, K + S.size() - i, MOD);
    sum += left * right % MOD;
    sum %= MOD;
  }
  cout << sum << endl;

  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll k, fact[3000001], inv[3000001], rez;
string s;
ll pw(ll a, ll b) {
  ll rez = 1;
  while (b) {
    if (b % 2)
      rez = (rez * a) % mod;
    a = (a * a) % mod;
    b /= 2;
  }
  return rez;
}
ll combi(ll a, ll b) {
  if (a < b)
    return 0;
  ll r = (fact[a] * inv[b]) % mod;
  r = (r * inv[a - b]) % mod;
  return r;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> k >> s;
  fact[0] = 1;
  inv[0] = pw(1, mod - 2);
  for (ll i = 1; i <= 3000000; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
    inv[i] = pw(fact[i], mod - 2) % mod;
  }
  ll n = k + s.size();
  ll nrelem = s.size();
  for (ll i = 0; i <= n - nrelem; i++) {
    ll ans = pw(26, i) % mod;
    ans = (ans * combi(n - i - 1, nrelem - 1)) % mod;
    ans = (ans * pw(25, n - i - nrelem)) % mod;
    rez = (rez + ans) % mod;
  }
  cout << rez;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll k, fact[1000001], inv[1000001], rez;
string s;
ll pw(ll a, ll b) {
  ll rez = 1;
  while (b) {
    if (b % 2)
      rez = (rez * a) % mod;
    a = (a * a) % mod;
    b /= 2;
  }
  return rez;
}
ll combi(ll a, ll b) {
  if (a < b)
    return 0;
  ll r = (fact[a] * inv[b]) % mod;
  r = (r * inv[a - b]) % mod;
  return r;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> k >> s;
  fact[0] = 1;
  inv[0] = pw(1, mod - 2);
  for (ll i = 1; i <= 1000000; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
    inv[i] = pw(fact[i], mod - 2);
  }
  ll n = k + s.size();
  ll nrelem = s.size();
  for (ll i = 0; i <= n - nrelem; i++) {
    ll ans = pw(26, i) % mod;
    ans = (ans * combi(n - i - 1, nrelem - 1)) % mod;
    ans = (ans * pw(25, n - i - nrelem)) % mod;
    rez = (rez + ans) % mod;
  }
  cout << rez;
  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

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

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

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

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

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


Error: 0

Fixed submission:

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

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

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

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

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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
ll pow25[2000005], pow26[2000005];

void init() {
  pow25[0] = 1;
  pow26[0] = 1;
  rep(i, 2000004) {
    pow25[i + 1] = pow25[i] * 25 % MOD;
    pow26[i + 1] = pow26[i] * 26 % MOD;
  }
}

const int MAX = 2100000;

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

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

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

int main() {
  COMinit();
  init();
  ll K;
  cin >> K;
  string S;
  cin >> S;
  ll s = S.size();
  ll ans = 0;
  rep(i, K + 1) {
    ans =
        (ans + (COM(s + i - 1, s - 1) * (pow25[i] * pow26[K - i] % MOD) % MOD) %
                   MOD) %
        MOD;
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
ll pow25[200005], pow26[200005];

void init() {
  pow25[0] = 1;
  pow26[0] = 1;
  rep(i, 200004) {
    pow25[i + 1] = pow25[i] * 25 % MOD;
    pow26[i + 1] = pow26[i] * 26 % MOD;
  }
}

const int MAX = 510000;

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();
  init();
  ll K;
  cin >> K;
  string S;
  cin >> S;
  ll s = S.size();
  ll ans = 0;
  rep(i, K + 1) {
    ans =
        (ans + (COM(s + i - 1, s - 1) * (pow25[i] * pow26[K - i] % MOD) % MOD) %
                   MOD) %
        MOD;
  }
  cout << ans << endl;
  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: 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 = 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;
}

Error: 0

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 = 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;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define l_ength size
const int inf = (1 << 30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

const int bound = 2000100;
ll fact[bound], fact_inv[bound];

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

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

void init() {
  fact[0] = 1;
  int b = bound - 10;
  for (int i = 0; i < b; ++i) {
    fact[i + 1] = fact[i] * (i + 1) % mod;
  }
  fact_inv[b] = inv(fact[b]);
  for (int i = b - 1; i >= 0; --i) {
    fact_inv[i] = fact_inv[i + 1] * (i + 1) % mod;
  }
}

ll comb(ll n, ll r) {
  if (n < r or r < 0)
    return 0;
  return (fact[n] * fact_inv[r]) % mod * fact_inv[n - r] % mod;
}

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

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define l_ength size
const int inf = (1 << 30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

const int bound = 1000100;
ll fact[bound], fact_inv[bound];

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

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

void init() {
  fact[0] = 1;
  int b = bound - 10;
  for (int i = 0; i < b; ++i) {
    fact[i + 1] = fact[i] * (i + 1) % mod;
  }
  fact_inv[b] = inv(fact[b]);
  for (int i = b - 1; i >= 0; --i) {
    fact_inv[i] = fact_inv[i + 1] * (i + 1) % mod;
  }
}

ll comb(ll n, ll r) {
  if (n < r)
    return 0;
  return (fact[n] * fact_inv[r]) % mod * fact_inv[n - r] % mod;
}

int main() {
  init();
  ll k, s;
  string tmp;
  cin >> k >> tmp;
  s = tmp.size();
  ll n = s + k;
  ll ans = 0;
  for (ll i = 0; i < n; ++i) {
    ans += power(26, i) * comb(n - (i + 1), s - 1) % mod *
           power(25, n - (i + 1) - (s - 1)) % mod;
    ans %= mod;
  }
  cout << ans << endl;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 2e6 + 5;
const int INF = 0x3f3f3f3f;
const ll p = 1e9 + 7;
#define DEBUG(x) cout << x << '\\n'

int F[MAXN], Finv[MAXN], inv[MAXN];
void init() {
  F[0] = Finv[0] = inv[1] = 1;
  for (int i = 2; i < MAXN; i++)
    inv[i] = (p - p / i) * 1ll * inv[p % i] % p;
  for (int i = 1; i < MAXN; i++) {
    F[i] = F[i - 1] * 1ll * i % p;
    Finv[i] = Finv[i - 1] * 1ll * inv[i] % p;
  }
}
int C(int n, int m) { return F[n] * 1ll * Finv[n - m] % p * Finv[m] % p; }
ll f_pow(ll a, ll b) {
  ll res = 1;
  for (; b; b >>= 1, a = a * a % p)
    if (b & 1)
      res = res * a % p;
  return res;
}
void run() {
  int n, k;
  string s;
  cin >> k >> s;
  init();
  n = s.size();
  int ans = 0;
  for (int i = n; i <= n + k; i++) {
    ans += C(i - 1, n - 1) * f_pow(26, n + k - i) % p * f_pow(25, i - n) % p;
    ans %= p;
  }
  cout << ans;
}
int main() {
#ifdef Irene
  freopen("in.txt", "r", stdin);
#endif // Irene
  ios::sync_with_stdio(false);

  run();
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e6 + 5;
const int INF = 0x3f3f3f3f;
const ll p = 1e9 + 7;
#define DEBUG(x) cout << x << '\\n'

int F[MAXN], Finv[MAXN], inv[MAXN];
void init() {
  F[0] = Finv[0] = inv[1] = 1;
  for (int i = 2; i < MAXN; i++)
    inv[i] = (p - p / i) * 1ll * inv[p % i] % p;
  for (int i = 1; i < MAXN; i++) {
    F[i] = F[i - 1] * 1ll * i % p;
    Finv[i] = Finv[i - 1] * 1ll * inv[i] % p;
  }
}
int C(int n, int m) { return F[n] * 1ll * Finv[n - m] % p * Finv[m] % p; }
ll f_pow(ll a, ll b) {
  ll res = 1;
  for (; b; b >>= 1, a = a * a % p)
    if (b & 1)
      res = res * a % p;
  return res;
}
void run() {
  int n, k;
  string s;
  cin >> k >> s;
  init();
  n = s.size();
  int ans = 0;
  for (int i = n; i <= n + k; i++) {
    ans += C(i - 1, n - 1) * f_pow(26, n + k - i) % p * f_pow(25, i - n) % p;
    ans %= p;
  }
  cout << ans;
}
int main() {
#ifdef Irene
  freopen("in.txt", "r", stdin);
#endif // Irene
  ios::sync_with_stdio(false);

  run();
}