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

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define IOS                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0)
/* start */

const int mod = 1e9 + 7;
const int N = 2e6 + 9;

int fat[N], inv[N];

int fastexp(int b, int e) {
  if (e == 0)
    return 1;
  int ans = fastexp(b, e / 2);
  ans = (ans * ans) % mod;
  if (e % 2 == 1)
    ans = (ans * b) % mod;
  return ans;
}

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

int comb(int a, int b) { return fat[a] * inv[b] % mod * inv[a - b] % mod; }

signed main() {
  IOS;
  init();
  int k;
  cin >> k;
  string s;
  cin >> s;
  int n = s.size();
  int ans = 0;
  for (int i = 0; i <= k; i++) {
    ans = (ans + fastexp(25, i) * fastexp(26, k - i) % mod *
                     comb(i + n - 1, n - 1) % mod) %
          mod;
  }
  cout << ans << "\\n";
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define IOS                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0)
/* start */

const int mod = 1e9 + 7; // CHANGE THIS
const int N = 1e6 + 9;   // CHANGE THIS

int fat[N], inv[N];

int fastexp(int b, int e) {
  if (e == 0)
    return 1;
  int ans = fastexp(b, e / 2);
  ans = (ans * ans) % mod;
  if (e % 2 == 1)
    ans = (ans * b) % mod;
  return ans;
}

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

int comb(int a, int b) { return fat[a] * inv[b] % mod * inv[a - b] % mod; }

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

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

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

int fact[MAX];
int inv[MAX];

int Power(int n, int x) {
  if (x == 0) {
    return 1;
  } else if (x & 1) {
    return 1ll * n * Power(n, x - 1) % MOD;
  } else {
    int res = Power(n, x / 2);
    return 1ll * res * res % MOD;
  }
}

int C(int n, int r) {
  if (r > n || r < 0) {
    return 0;
  }
  return 1ll * fact[n] * inv[r] % MOD * inv[n - r] % MOD;
}

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

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

  int K;
  cin >> K;
  string S;
  cin >> S;
  int ans = 0;
  for (int i = 0; i <= K; i++) {
    ans += 1ll * Power(26, i) * Power(25, K - i) % MOD *
           C(K - i + int(S.size()) - 1, int(S.size()) - 1) % MOD;
    if (ans >= MOD) {
      ans -= MOD;
    }
  }
  cout << ans << "\\n";
  return 0;
}


Error: 0

Fixed submission:

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

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

int fact[MAX];
int inv[MAX];

int Power(int n, int x) {
  if (x == 0) {
    return 1;
  } else if (x & 1) {
    return 1ll * n * Power(n, x - 1) % MOD;
  } else {
    int res = Power(n, x / 2);
    return 1ll * res * res % MOD;
  }
}

int C(int n, int r) {
  if (r > n || r < 0) {
    return 0;
  }
  return 1ll * fact[n] * inv[r] % MOD * inv[n - r] % MOD;
}

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

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

  int K;
  cin >> K;
  string S;
  cin >> S;
  int ans = 0;
  for (int i = 0; i <= K; i++) {
    ans += 1ll * Power(26, i) * Power(25, K - i) % MOD *
           C(K - i + int(S.size()) - 1, int(S.size()) - 1) % MOD;
    if (ans >= MOD) {
      ans -= MOD;
    }
  }
  cout << ans << "\\n";
  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;

ll kai[2000001], inv[2000001];
int n, k;
ll mod_pow(ll x, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) {
      res = res * x % mod;
    }
    x = x * x % mod;
    n /= 2;
  }
  return res;
}
void init() {
  kai[0] = 1LL;
  for (ll i = 1LL; i <= 2000000; i++) {
    kai[i] = kai[i - 1] * i;
    kai[i] %= MOD;
  }
  inv[2000000] = mod_pow(kai[2000000], MOD - 2LL, MOD);
  for (ll i = 1999999; i >= 0; i--) {
    inv[i] = inv[i + 1] * (i + 1);
    inv[i] %= MOD;
  }
}

ll comb(ll r, ll c) {
  ll res;
  res = kai[r];
  res *= inv[c];
  res %= MOD;
  res *= inv[r - c];
  res %= MOD;
  return res;
}

ll calc(ll x, ll y) {
  if (y == 0LL) {
    return 1LL;
  }
  ll res = comb(x + y, x) * mod_pow(25, y, MOD);
  res %= MOD;
  res += calc(x + 1LL, y - 1LL);
  return res % MOD;
}

int main() {
  string s;
  cin >> k >> s;
  n = s.length();
  init();
  cout << calc(n, k) << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
  int n, k;
  string s;
  cin >> k >> s;
  n = s.length();
  vector<vector<ll>> dp(n + 10);
  for (int i = 0; i <= n; i++) {
    dp[i].resize(k + 10);
  }
  dp[0][0] = 1LL;
  for (int i = 1; i <= n; i++) {
    dp[i][0] = dp[i - 1][0];
  }
  for (int i = 1; i <= k; i++) {
    dp[0][i] = dp[0][i - 1] * 26LL;
    dp[0][i] %= MOD;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= k; j++) {
      dp[i][j] = dp[i - 1][j] + dp[i][j - 1] * 25LL;
      dp[i][j] %= MOD;
    }
  }
  /*for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= k; j++) {
      cout << dp[i][j] << "\\t";
    }
    cout << endl;
  }*/
  cout << dp[n][k] << endl;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

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


Error: 0

Fixed submission:

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

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

long long MOD = 1000000000 + 7;
long long fact[2000000] = {1};
long long invfact[2000000] = {1};

long long nCr(int n, int r) {
  long long ans = (fact[n] * invfact[r] % MOD) * invfact[n - r] % MOD;
  return ans;
}

long long power(long long a, long long b) {
  long long res = 1;

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

int main(void) {
  for (int i = 1; i < 2000000; i++) {
    fact[i] = fact[i - 1] * i % MOD;
  }

  invfact[2000000 - 1] = power(fact[2000000 - 1], MOD - 2);
  for (int i = 2000000 - 1; i > 0; i--) {
    invfact[i - 1] = invfact[i] * i % MOD;
  }

  long long K;
  string S;

  cin >> K >> S;

  int slen = S.length();

  int tlen = slen + K;
  long long ans = 0;
  for (int i = slen; i <= tlen; i++) {
    ans += power(26, (tlen - i)) * power(25, (tlen - slen - (tlen - i))) % MOD *
           nCr((tlen - (tlen - i) - 1), slen - 1) % MOD;
    ans %= MOD;
  }

  cout << ans << endl;
}


Error: 0

Fixed submission:

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

long long MOD = 1000000000 + 7;
long long fact[1100000] = {1};
long long invfact[1100000] = {1};

long long nCr(int n, int r) {
  long long ans = (fact[n] * invfact[r] % MOD) * invfact[n - r] % MOD;
  return ans;
}

long long power(long long a, long long b) {
  long long res = 1;

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

int main(void) {
  for (int i = 1; i < 1100000; i++) {
    fact[i] = fact[i - 1] * i % MOD;
  }

  invfact[1100000 - 1] = power(fact[1100000 - 1], MOD - 2);
  for (int i = 1100000 - 1; i > 0; i--) {
    invfact[i - 1] = invfact[i] * i % MOD;
  }

  long long K;
  string S;

  cin >> K >> S;

  int slen = S.length();

  int tlen = slen + K;
  long long ans = 0;
  for (int i = slen; i <= tlen; i++) {
    ans += power(26, (tlen - i)) * power(25, (tlen - slen - (tlen - i))) % MOD *
           nCr((tlen - (tlen - i) - 1), slen - 1) % MOD;
    ans %= MOD;
  }

  cout << ans << endl;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

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


Error: 0

Fixed submission:

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

Error: 0

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

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


Error: 0

Fixed submission:

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

#include <bits/stdc++.h>

using namespace std;

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

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

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

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

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

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

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

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

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

  for (int i = 0; i < int(s.size()); i++) {
    ans -= fix(nck(N, i) * pw[N - i]);
  }

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


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

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

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

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

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

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

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

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

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

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

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

  cout << fix(ans) << nl;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll MOD = 1e9 + 7;

const int maxN = 2 * 1e6 + 7;

int fact[maxN];

ll power(ll n, ll k) {
  ll res = 1;
  while (k) {
    if (k % 2)
      res = (res * n) % MOD;
    n = (n * n) % MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll n) { return power(n, MOD - 2); }

ll ncr(ll n, ll k) {
  if (n < k)
    return 0;
  if (k == 0 || n == k)
    return 1;
  ll fact_n = fact[n];
  fact_n = (fact_n * inverse(fact[n - k])) % MOD;
  fact_n = (fact_n * inverse(fact[k])) % MOD;
  return fact_n;
}

int main() {
  int k;
  string s;
  cin >> k >> s;
  int size_s = s.size();
  int n = k + size_s;
  fact[0] = fact[1] = 1;
  for (int i = 2; i < maxN; i++) {
    fact[i] = (fact[i - 1] * 1LL * i) % MOD;
  }
  int ans = 0;
  for (int i = size_s; i <= n; i++) {
    int cur = (power(25, n - i) * 1LL * ncr(n, i)) % MOD;
    ans = (ans + cur) % MOD;
  }
  cout << ans << '\\n';
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll MOD = 1e9 + 7;

const int maxN = 1e6 + 1;

int fact[maxN];

ll power(ll n, ll k) {
  ll res = 1;
  while (k) {
    if (k % 2)
      res = (res * n) % MOD;
    n = (n * n) % MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll n) { return power(n, MOD - 2); }

ll ncr(ll n, ll k) {
  ll fact_n = fact[n];
  fact_n = (fact_n * inverse(fact[n - k])) % MOD;
  fact_n = (fact_n * inverse(fact[k])) % MOD;
  return fact_n;
}

int main() {
  int k;
  string s;
  cin >> k >> s;
  int size_s = s.size();
  int n = k + size_s;
  fact[0] = fact[1] = 1;
  for (int i = 2; i <= n; i++) {
    fact[i] = (fact[i - 1] * i) % MOD;
  }
  ll res = power(26, n);
  for (int i = 0; i < size_s; i++) {
    ll cur = ncr(n, i);
    cur = (cur * power(25, n - i)) % MOD;
    res = (((res - cur) % MOD) + MOD) % MOD;
  }
  cout << res << '\\n';
}