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

#include "bits/stdc++.h"

using namespace std;

typedef long double ld;
typedef long long ll;

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

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

const ll MOD = 1e9 + 7;

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

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

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

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

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

Error: WA

Fixed submission:

#include "bits/stdc++.h"

using namespace std;

typedef long double ld;
typedef long long ll;

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

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

const ll MOD = 1e9 + 7;

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

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

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

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

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

#include <bits/stdc++.h>
#define ll long long int
#define uu first
#define vv second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define INF 1e9
#define fastRead                                                               \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
using namespace std;

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

ll fact[MAX], invFact[MAX];

ll bigMod(ll a, ll b) {

  if (b == 0)
    return 1LL;
  ll ret = bigMod(a, b / 2);
  ret = (ret * ret) % MOD;
  if (b & 1)
    ret = (ret * a) % MOD;
  return ret;
}
ll invMod(ll x) { return bigMod(x, MOD - 2); }
void pre() {

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

  invFact[MAX - 1] = invMod(fact[MAX - 1]);

  for (int i = MAX - 2; i >= 0; i--) {
    invFact[i] = (invFact[i + 1] * (i + 1)) % MOD;
  }
  //    for(int i =0 ; i < 5; i++ ) cout<<invFact[i]<<" ";
}

ll ncr(ll n, ll r) {

  ll lob = fact[n];

  ll hor = (invFact[r] * invFact[n - r]) % MOD;

  return (lob * hor) % MOD;
}

int main() {
  fastRead;
  pre();
  int k;
  string s;
  cin >> k >> s;
  int n = s.size();
  int tot = n + k;
  ll ans = bigMod(26, tot);

  for (int i = 0; i < n; i++) {

    ll tmp = (ncr(tot, i) * bigMod(25, tot - i)) % MOD;
    ans = (ans - tmp) % MOD;
    ans = (ans + MOD) % MOD;
  }
  cout << ans << '\\n';
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define uu first
#define vv second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define INF 1e9
#define fastRead                                                               \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
using namespace std;

const int MAX = 1e6 + 6;
const ll MOD = 1e9 + 7;

ll fact[MAX], invFact[MAX];

ll bigMod(ll a, ll b) {

  if (b == 0)
    return 1LL;
  ll ret = bigMod(a, b / 2);
  ret = (ret * ret) % MOD;
  if (b & 1)
    ret = (ret * a) % MOD;
  return ret;
}
ll invMod(ll x) { return bigMod(x, MOD - 2); }
void pre() {

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

  invFact[MAX - 1] = invMod(fact[MAX - 1]);

  for (int i = MAX - 2; i >= 0; i--) {
    invFact[i] = (invFact[i + 1] * (i + 1)) % MOD;
  }
  //    for(int i =0 ; i < 5; i++ ) cout<<invFact[i]<<" ";
}

ll ncr(ll n, ll r) {

  ll lob = fact[n];

  ll hor = (invFact[r] * invFact[n - r]) % MOD;

  return (lob * hor) % MOD;
}

int main() {
  fastRead;
  pre();
  int k;
  string s;
  cin >> k >> s;
  int n = s.size();
  int tot = n + k;
  ll ans = bigMod(26, tot);

  for (int i = 0; i < n; i++) {

    ll tmp = (ncr(tot, i) * bigMod(25, tot - i)) % MOD;
    ans = (ans - tmp) % MOD;
    ans = (ans + MOD) % MOD;
  }
  cout << ans << '\\n';
  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

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

using ll = long long;
#define mod 1000000007
#define max_index 10000000

ll modpow(ll n, ll m = mod - 2) {
  ll r = 1;
  while (m) {
    r = r * ((m % 2) ? n : 1) % mod, n = n * n % mod, m >>= 1;
  }
  return r;
}

ll fact[max_index];    // i! (mod)
ll inv[max_index];     // i^(-1) (mod)
ll invfact[max_index]; // i!^(-1) (mod)

void calc_fact_invfact() {
  if (fact[0] == 0) {
    fact[0] = inv[1] = invfact[0] = 1;
    for (ll i = 2; i < max_index; i++)
      inv[i] = mod - inv[mod % i] * (mod / i) % mod;
    for (ll i = 1; i < max_index; i++)
      fact[i] = fact[i - 1] * i % mod,
      invfact[i] = invfact[i - 1] * inv[i] % mod;
  }
}
ll nCk(int n, int k) {
  if (n < k || k < 0)
    return 0;
  else
    return fact[n] * invfact[k] % mod * invfact[n - k] % mod;
}

int main() {

  ll K;
  cin >> K;
  string s;
  cin >> s;

  ll len = s.length();
  ll ans = 0;
  ll now;
  calc_fact_invfact();
  for (ll i = 0; i <= K; i++) {
    now = modpow(25, i) % mod;
    now = now * nCk(i + (len - 1), len - 1) % mod;
    now = now * modpow(26, K - i) % mod;
    now = (now + mod) % mod;
    ans = (ans + now + mod) % mod;
  }

  cout << (ans + mod) % mod << endl;
}

Error: 0

Fixed submission:

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

using ll = long long;
#define mod 1000000007
#define max_index 200002

ll modpow(ll n, ll m = mod - 2) {
  ll r = 1;
  while (m) {
    r = r * ((m % 2) ? n : 1) % mod, n = n * n % mod, m >>= 1;
  }
  return r;
}

ll fact[max_index];    // i! (mod)
ll inv[max_index];     // i^(-1) (mod)
ll invfact[max_index]; // i!^(-1) (mod)

void calc_fact_invfact() {
  if (fact[0] == 0) {
    fact[0] = inv[1] = invfact[0] = 1;
    for (int i = 2; i < max_index; i++)
      inv[i] = mod - inv[mod % i] * (mod / i) % mod;
    for (int i = 1; i < max_index; i++)
      fact[i] = fact[i - 1] * i % mod,
      invfact[i] = invfact[i - 1] * inv[i] % mod;
  }
}
ll nCk(int n, int k) {
  if (n < k || k < 0)
    return 0;
  else
    return fact[n] * invfact[k] % mod * invfact[n - k] % mod;
}

int main() {

  ll K;
  cin >> K;
  string s;
  cin >> s;

  ll len = s.length();
  ll ans = 0;
  ll now;
  calc_fact_invfact();
  for (ll i = 0; i <= K; i++) {
    now = modpow(25, i);
    now = (now * (nCk(i + (len - 1), len - 1) + mod)) % mod;
    now = (now * modpow(26, K - i) + mod) % mod;
    ans = (ans + now + mod) % mod;
  }

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

#include <bits/stdc++.h>

#define ll long long

using namespace std;

// memset(dp, 0, sizeof(dp));
const ll M = 1e9 + 7;
const int N = 2e6 + 10;
int F[N], G[N];

ll comb(int n, int m) {
  if (n < m || m < 0) {
    return 0;
  }
  return (ll)F[n] * G[m] % M * G[n - m] % M;
}

void init(int n) {
  static int inv[N];
  inv[1] = 1;
  for (int i = 2; i < n; i++) {
    inv[i] = (M - M / i) * (ll)inv[M % i] % M;
  }
  F[0] = G[0] = 1;
  for (int i = 1; i < n; ++i) {
    F[i] = (ll)F[i - 1] * i % M;
    G[i] = (ll)G[i - 1] * inv[i] % M;
  }
}

ll power_mod(ll a, ll n, ll p = M) {
  ll res = 1;
  for (; n; n >>= 1) {
    if (n & 1) {
      res = res * a % p;
    }
    a = a * a % p;
  }
  return res;
}
void work(int T) {

  int k;
  cin >> k;
  string s;
  cin >> s;

  int m = s.size(), n = m + k;
  ll res = 0, mul = 1;
  init(n);
  for (int i = m - 1; i < n; i++) {
    res = (res +
           (ll)comb(i, m - 1) % M * mul % M * power_mod(26, n - i - 1) % M) %
          M;
    mul = mul * 25ll % M;
  }
  cout << res << endl;

  return;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);
  cout << fixed;
  // int t;
  // for(cin >> t; t > 0; t--) {
  // work(t);
  // }
  work(0);
  return 0;
};


Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define ll long long

using namespace std;

// memset(dp, 0, sizeof(dp));

void work(int T) {
  int k;
  cin >> k;
  string s;
  cin >> s;
  ll n = k + s.size(), M = 1e9 + 7, sum = 1;
  // for(int i = 0; i < n; i++) {
  // sum = sum * 26 % M;
  // }
  vector<vector<ll>> dp(n, vector<ll>(s.size() + 1));
  dp[0][0] = 25;
  dp[0][1] = 1;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < s.size(); j++) {
      dp[i][j] = (dp[i][j] + dp[i - 1][j] * 25) % M;
      dp[i][j + 1] = (dp[i][j + 1] + dp[i - 1][j]) % M;
    }
    dp[i][s.size()] = (dp[i][s.size()] + dp[i - 1][s.size()] * 26) % M;
  }

  cout << dp[n - 1][s.size()] << endl;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);
  cout << fixed;
  // int t;
  // for(cin >> t; t > 0; t--) {
  // work(t);
  // }
  work(0);
  return 0;
};
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;

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

// combination
// O(n)

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

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

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

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

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

    fact_init = true;
  }

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

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

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

  ll k;
  cin >> k;

  string s;
  cin >> s;

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

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

    ans += t;
    ans %= MOD;
  }

  cout << ans << endl;
}


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;

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

// combination
// O(n)

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

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

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

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

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

    fact_init = true;
  }

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

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

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

  ll k;
  cin >> k;

  string s;
  cin >> s;

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

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

    ans += t;
    ans %= MOD;
  }

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

#include <cstdio>
#include <cstring>
using namespace std;

const int md = 1000000007;

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

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

char s[N + 1];

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


Error: 0

Fixed submission:

#include <cstdio>
#include <cstring>
using namespace std;

const int md = 1000000007;

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

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

char s[N + 1];

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

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

#define ll long long int
#define pb push_back
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define per(i, j, n) for (ll i = j; i >= n; i--)
#define all(x) x.begin(), x.end()
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;

ll mod = 1e9 + 7;
ll fact[(ll)2000005];
ll infact[(ll)2000005];

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

ll mod_inv(ll n) {
  ll a = bin_exp(n, mod - 2);
  return a;
}

void fac() {
  fact[0] = 1;
  infact[0] = 1;
  rep(i, 1, 2000002) {
    fact[i] = (fact[i - 1] * i) % mod;
    infact[i] = (mod_inv(i) * infact[i - 1]) % mod;
  }
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ll k;
  string s;
  cin >> k >> s;
  ll n = s.length();
  fac();
  ll ans = 0;
  rep(i, 0, k + 1) {
    ll res =
        (fact[n + k - i - 1] * ((infact[k - i] * infact[n - 1]) % mod)) % mod;
    ll bin = (bin_exp(26, i) * bin_exp(25, k - i)) % mod;
    ans = (ans + ((res * bin) % mod)) % mod;
  }
  cout << ans << endl;
}

Error: -11

Fixed submission:

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

#define ll long long int
#define pb push_back
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define per(i, j, n) for (ll i = j; i >= n; i--)
#define all(x) x.begin(), x.end()
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;

ll mod = 1e9 + 7;
ll fact[200005];
ll infact[200005];

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

ll mod_inv(ll n) {
  ll a = bin_exp(n, mod - 2);
  return a;
}

void fac() {
  fact[0] = 1;
  infact[0] = 1;
  rep(i, 1, 200002) {
    fact[i] = (fact[i - 1] * i) % mod;
    infact[i] = (mod_inv(i) * infact[i - 1]) % mod;
  }
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ll k;
  string s;
  cin >> k >> s;
  ll n = s.length();
  fac();
  ll ans = 0;
  rep(i, 0, k + 1) {
    ll res =
        (fact[n + k - i - 1] * ((infact[k - i] * infact[n - 1]) % mod)) % mod;
    ll bin = (bin_exp(26, i) * bin_exp(25, k - i)) % mod;
    ans = (ans + ((res * bin) % mod)) % mod;
  }
  cout << ans << endl;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
const int mod = 1e9 + 7;

string s;
lint fact[2000002], invf[2000002];
lint ipow[2000002];

lint c(int x, int y) { return fact[x] * (invf[y] * invf[x - y] % mod) % mod; }

lint p(int x) { return ipow[x]; }

struct query {
  int x, y, idx;
};

vector<query> q;
int ret[2000002];

lint fpow(int x, int y) {
  lint ret = 1, piv = x;
  while (y) {
    if (y & 1)
      ret *= piv;
    piv *= piv;
    ret %= mod;
    piv %= mod;
    y >>= 1;
  }
  return ret;
}

int solve(int x, int y) {
  if (y < x / 2) {
    lint ret = mod - fpow(26, x);
    for (int i = x; i > x - y; i--) {
      ret += c(x, i) * ipow[i];
      ret %= mod;
    }
    return (mod - ret) % mod;
  }
  lint ret = 0;
  for (int i = 0; i <= x - y; i++) {
    ret += c(x, i) * ipow[i];
    ret %= mod;
  }
  return ret;
}
int main() {
  fact[0] = invf[0] = ipow[0] = 1;
  for (int i = 1; i <= 2000001; i++) {
    fact[i] = fact[i - 1] * i % mod;
    ipow[i] = ipow[i - 1] * 25 % mod;
    invf[i] = fpow(fact[i], mod - 2);
  }
  int Q;
  cin >> Q >> s;
  int n = s.length();
  int len = n + Q;
  printf("%d\\n", solve(len, (int)s.size()));
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
const int mod = 1e9 + 7;

string s;
lint fact[1000002], invf[1000002];
lint ipow[1000002];

lint c(int x, int y) { return fact[x] * (invf[y] * invf[x - y] % mod) % mod; }

lint p(int x) { return ipow[x]; }

struct query {
  int x, y, idx;
};

vector<query> q;
int ret[1000002];

lint fpow(int x, int y) {
  lint ret = 1, piv = x;
  while (y) {
    if (y & 1)
      ret *= piv;
    piv *= piv;
    ret %= mod;
    piv %= mod;
    y >>= 1;
  }
  return ret;
}

int solve(int x, int y) {
  if (y < x / 2) {
    lint ret = mod - fpow(26, x);
    for (int i = x; i > x - y; i--) {
      ret += c(x, i) * ipow[i];
      ret %= mod;
    }
    return (mod - ret) % mod;
  }
  lint ret = 0;
  for (int i = 0; i <= x - y; i++) {
    ret += c(x, i) * ipow[i];
    ret %= mod;
  }
  return ret;
}
int main() {
  fact[0] = invf[0] = ipow[0] = 1;
  for (int i = 1; i <= 1000000; i++) {
    fact[i] = fact[i - 1] * i % mod;
    ipow[i] = ipow[i - 1] * 25 % mod;
    invf[i] = fpow(fact[i], mod - 2);
  }
  int Q;
  cin >> Q >> s;
  int n = s.length();
  int len = n + Q;
  printf("%d\\n", solve(len, (int)s.size()));
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

// https://atcoder.jp/contests/abc171/tasks/abc171_f

#include <bits/stdc++.h>
using namespace std;
#define watch(x) cerr << (#x) << " is " << (x) << endl;
#define endl '\\n'

using ll = long long;

ll fac[2000500];

const ll MOD = 1000000007LL;

ll modmul(ll a, ll b) { return (a * b) % MOD; }

ll modpow(ll a, ll exp) {
  if (exp == 0)
    return 1LL;

  ll t = modpow(a, exp / 2);
  if (exp % 2)
    return t * t % MOD * a % MOD;
  return t * t % MOD;
}

ll modinv(ll n) { return modpow(n, MOD - 2); }

ll choose(ll n, ll k) {
  return modmul(fac[n], modinv(modmul(fac[k], fac[n - k])));
}

signed main() {
  ios::sync_with_stdio(0);
  cin.sync_with_stdio(0);
  cin.tie(0);
  fac[0] = 1;
  for (ll i = 1; i <= 2000000; i++) {
    fac[i] = modmul(fac[i - 1], i);
  }

  ll K;
  string s;

  cin >> K >> s;

  ll N = s.size();

  ll ans = 0;
  // i = not same
  for (ll i = 0; i <= K; i++) {
    ll val = modmul(modpow(25, i), choose(N + K, i));
    ans += val;

    ans %= MOD;
  }

  cout << ans << endl;
}


Error: 0

Fixed submission:

// https://atcoder.jp/contests/abc171/tasks/abc171_f

#include <bits/stdc++.h>
using namespace std;
#define watch(x) cerr << (#x) << " is " << (x) << endl;
#define endl '\\n'

using ll = long long;

ll fac[200500];

const ll MOD = 1000000007;

ll modmul(ll a, ll b) { return (a * b) % MOD; }

ll modpow(ll a, ll exp) {
  if (exp == 0)
    return 1;

  ll t = modpow(a, exp / 2);
  if (exp % 2)
    return t * t % MOD * a % MOD;
  return t * t % MOD;
}

ll modinv(ll n) { return modpow(n, MOD - 2); }

ll choose(ll n, ll k) {
  return modmul(fac[n], modmul(modinv(fac[n - k]), modinv(fac[k])));
}

signed main() {
  ios::sync_with_stdio(0);
  cin.sync_with_stdio(0);
  cin.tie(0);
  fac[0] = 1;
  for (ll i = 1; i <= 200300; i++) {
    fac[i] = modmul(fac[i - 1], i);
  }

  ll K;
  string s;

  cin >> K >> s;

  ll l = s.size();
  ll n = l + K;

  ll ans = modpow(26LL, n);
  for (ll match = 0; match < l; match++) {
    ll val = modmul(modpow(25LL, n - match), choose(n, match));

    ans -= val;
    ans = (ans + MOD) % MOD;
  }

  cout << (ans + MOD) % MOD << endl;
}