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

#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef double dd;
const int N = 2e6 + 5;
const dd eps = 1e-8;
const int mod = 1e9 + 7;

int k, n, ss;
ll fac[N];
string s;

inline ll qpow(ll a, ll b) {
  ll ans = 1;
  a = (a % mod + mod) % mod;
  for (; b; b >>= 1) {
    if (b & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
  }
  return ans;
}

ll comb(int n, int m) {
  ll up = fac[n], down = (fac[m] * fac[n - m]) % mod;
  ll ans = (up * qpow(down, mod - 2)) % mod;
  return ans;
}

int main() {
  ios::sync_with_stdio(false);
  // freopen("input.txt","r",stdin);
  cin >> k >> s;
  n = k + s.size();
  ss = s.size();
  fac[0] = 1;
  for (int i = 1; i <= 2e6; i++) {
    fac[i] = (fac[i - 1] * i) % mod;
  }
  ll ans = qpow(26, n);
  ll neg = 0;
  for (int i = 0; i < ss; i++) {
    neg = (neg + (comb(n, i) * qpow(25, n - i)) % mod) % mod;
  }
  ans = (ans - neg + mod) % mod;
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef double dd;
const int N = 1e6 + 5;
const dd eps = 1e-8;
const int mod = 1e9 + 7;

int k, n, ss;
ll fac[N];
string s;

inline ll qpow(ll a, ll b) {
  ll ans = 1;
  a = (a % mod + mod) % mod;
  for (; b; b >>= 1) {
    if (b & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
  }
  return ans;
}

ll comb(int n, int m) {
  ll up = fac[n], down = (fac[m] * fac[n - m]) % mod;
  ll ans = (up * qpow(down, mod - 2)) % mod;
  return ans;
}

int main() {
  ios::sync_with_stdio(false);
  // freopen("input.txt","r",stdin);
  cin >> k >> s;
  n = k + s.size();
  ss = s.size();
  fac[0] = 1;
  for (int i = 1; i <= 1e6; i++) {
    fac[i] = (fac[i - 1] * i) % mod;
  }
  ll ans = qpow(26, n);
  ll neg = 0;
  for (int i = 0; i < ss; i++) {
    neg = (neg + (comb(n, i) * qpow(25, n - i)) % mod) % mod;
  }
  ans = (ans - neg + mod) % mod;
  cout << ans << endl;
  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define MSET(x, y) memset(x, y, sizeof(x))
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 3000005
#define ll long long
#define ld long double
#define INF 1e18
#define endl "\\n"
#define fastio                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
using namespace std;
ll MOD = 1000000007;
string yes = "YES\\n";
string no = "NO\\n";
#define PI 3.1415926535

ll k;
string s;

ll power(ll x, ll y, ll p) {
  ll res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1; // y = y/2
    x = (x * x) % p;
  }
  return res;
}
ll fac[M], invfac[M];

void pre() {
  fac[0] = 1;
  for (ll i = 1; i < M; i++)
    fac[i] = (fac[i - 1] * i) % MOD;
  invfac[M - 1] = power(fac[M - 1], MOD - 2, MOD);
  for (ll i = M - 2; i >= 0; i--) {
    invfac[i] = (invfac[i + 1] * (i + 1)) % MOD;
  }
}

ll ncr(ll n, ll r, ll p) {
  if (r < 0 or r > n)
    return 0;
  return ((((fac[n] * invfac[r]) % p) * invfac[n - r]) % p);
}

int32_t main() {
  fastio;
  cin >> k;
  cin >> s;
  ll n = s.size();
  pre();
  ll ans = 0;
  for (ll i = 0; i <= k; i++) {
    ans += ((((ncr(n + k - i - 1, n - 1, MOD) * power(25, k - i, MOD)) % MOD) *
             power(26, i, MOD) % MOD) %
            MOD);
    ans %= MOD;
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define MSET(x, y) memset(x, y, sizeof(x))
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 3000005
#define ll long long
#define ld long double
#define INF 1e18
#define endl "\\n"
#define fastio                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
using namespace std;
ll MOD = 1000000007;
string yes = "YES\\n";
string no = "NO\\n";
#define PI 3.1415926535

ll k;
string s;

ll power(ll x, ll y, ll p) {
  ll res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1; // y = y/2
    x = (x * x) % p;
  }
  return res;
}
ll fac[M], invfac[M];

ll pre() {
  fac[0] = 1;
  for (ll i = 1; i < M; i++)
    fac[i] = (fac[i - 1] * i) % MOD;
  invfac[M - 1] = power(fac[M - 1], MOD - 2, MOD);
  for (ll i = M - 2; i >= 0; i--) {
    invfac[i] = (invfac[i + 1] * (i + 1)) % MOD;
  }
}

ll ncr(ll n, ll r, ll p) {
  if (r < 0 or r > n)
    return 0;
  return ((((fac[n] * invfac[r]) % p) * invfac[n - r]) % p);
}

int32_t main() {
  fastio;
  cin >> k;
  cin >> s;
  ll n = s.size();
  pre();
  ll ans = 0;
  for (ll i = 0; i <= k; i++) {
    ans += ((((ncr(n + k - i - 1, n - 1, MOD) * power(25, k - i, MOD)) % MOD) *
             power(26, i, MOD) % MOD) %
            MOD);
    ans %= MOD;
  }
  cout << ans << endl;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
const int MOD = 1000000007;
const int BUF = 2000005;

int factorial[BUF];

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

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

int modpow(int p, int n) {
  if (n == 0)
    return 1;
  int t = modpow(p, n / 2);
  return n & 1 ? mul(t, mul(t, p)) : mul(t, t);
}

int inv(int v) { return modpow(v, MOD - 2); }

int nCk(int n, int k) {
  return mul(factorial[n], mul(inv(factorial[k]), inv(factorial[n - k])));
}

int nHk(int n, int k) { return nCk(n + k - 1, k); }

int K;
int sLeng;

void read() {
  string dummy;
  cin >> K >> dummy;
  sLeng = dummy.size();
}

void work() {
  int ans = 0;
  for (int i = 0; i <= K; ++i) {
    ans = add(ans, mul(nHk(sLeng, i), mul(modpow(25, i), modpow(26, K - i))));
  }
  cout << ans << endl;
}

int main() {
  factorial[0] = 1;
  for (int i = 1; i < BUF; ++i) {
    factorial[i] = mul(i, factorial[i - 1]);
  }

  read();
  work();

  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;
const int MOD = 1000000007;
const int BUF = 1000005;

int factorial[BUF];

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

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

int modpow(int p, int n) {
  if (n == 0)
    return 1;
  int t = modpow(p, n / 2);
  return n & 1 ? mul(t, mul(t, p)) : mul(t, t);
}

int inv(int v) { return modpow(v, MOD - 2); }

int nCk(int n, int k) {
  return mul(factorial[n], mul(inv(factorial[k]), inv(factorial[n - k])));
}

int nHk(int n, int k) { return nCk(n + k - 1, k); }

int K;
int sLeng;

void read() {
  string dummy;
  cin >> K >> dummy;
  sLeng = dummy.size();
}

void work() {
  int ans = 0;
  for (int i = 0; i <= K; ++i) {
    ans = add(ans, mul(nHk(sLeng, i), mul(modpow(25, i), modpow(26, K - i))));
  }
  cout << ans << endl;
}

int main() {
  factorial[0] = 1;
  for (int i = 1; i < BUF; ++i) {
    factorial[i] = mul(i, factorial[i - 1]);
  }

  read();
  work();

  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Time Limit Exceeded

#pragma GCC optimize(3, "Ofast", "inline")
#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;
template <class t> inline t read(t &x) {
  char c = getchar();
  bool f = 0;
  x = 0;
  while (!isdigit(c))
    f |= c == '-', c = getchar();
  while (isdigit(c))
    x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  if (f)
    x = -x;
  return x;
}
template <class t> inline void write(t x) {
  if (x < 0)
    putchar('-'), write(-x);
  else {
    if (x > 9)
      write(x / 10);
    putchar('0' + x % 10);
  }
}

#define int long long

const int mod = 1e9 + 7, N = 4e6 + 5;
int n, m, pw0[N], pw1[N], ans, fac[N], ifac[N], inv[N];
char s[N];

int C(int n, int m) { return fac[n] * ifac[m] % mod * ifac[n - m] % mod; }

signed main() {
  read(n);
  scanf("%s", s + 1);
  m = strlen(s + 1);
  n += m;
  if (n < m)
    return write(0), 0;
  pw0[0] = pw1[0] = fac[0] = inv[1] = ifac[0] = 1;
  for (int i = 1; i <= n + n; i++)
    fac[i] = fac[i - 1] * i % mod;
  for (int i = 2; i <= n + n; i++)
    inv[i] = (mod - mod / i) * inv[mod % i] % mod;
  for (int i = 1; i <= n + n; i++)
    ifac[i] = ifac[i - 1] * inv[i] % mod;
  for (int i = 1; i <= n + n; i++)
    pw0[i] = pw0[i - 1] * 25 % mod, pw1[i] = pw1[i - 1] * 26 % mod;
  n -= m;
  for (int i = 0; i <= n; i++)
    ans = (ans + pw0[i] * pw1[n - i] % mod * C(i + m - 1, m - 1) % mod) % mod;
  write(ans);
}


Error: TLE

Fixed submission:

#pragma GCC optimize(3, "Ofast", "inline")
#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;
template <class t> inline t read(t &x) {
  char c = getchar();
  bool f = 0;
  x = 0;
  while (!isdigit(c))
    f |= c == '-', c = getchar();
  while (isdigit(c))
    x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  if (f)
    x = -x;
  return x;
}
template <class t> inline void write(t x) {
  if (x < 0)
    putchar('-'), write(-x);
  else {
    if (x > 9)
      write(x / 10);
    putchar('0' + x % 10);
  }
}

#define int long long

const int mod = 1e9 + 7, N = 4e6 + 5;
int n, m, pw0[N], pw1[N], ans, fac[N], ifac[N], inv[N];
char s[N];

int C(int n, int m) { return fac[n] * ifac[m] % mod * ifac[n - m] % mod; }

signed main() {
  scanf("%s", s + 1);
  read(n);
  m = strlen(s + 1);
  if (n < m)
    return write(0), 0;
  pw0[0] = pw1[0] = fac[0] = inv[1] = ifac[0] = 1;
  for (int i = 1; i <= n + n; i++)
    fac[i] = fac[i - 1] * i % mod;
  for (int i = 2; i <= n + n; i++)
    inv[i] = (mod - mod / i) * inv[mod % i] % mod;
  for (int i = 1; i <= n + n; i++)
    ifac[i] = ifac[i - 1] * inv[i] % mod;
  for (int i = 1; i <= n + n; i++)
    pw0[i] = pw0[i - 1] * 25 % mod, pw1[i] = pw1[i - 1] * 26 % mod;
  n -= m;
  for (int i = 0; i <= n; i++)
    ans = (ans + pw0[i] * pw1[n - i] % mod * C(i + m - 1, m - 1) % mod) % mod;
  write(ans);
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int const nax = 2e6 + 10;
const int mod = 1000000007; //
void plusle(int &a, int b) {
  if ((a += b) >= mod)
    a -= mod;
}
void minun(int &a, int b) {
  if ((a -= b) < 0)
    a += mod;
}
int add(int a, int b) { return ((a += b) >= mod) ? a - mod : a; }
int sub(int a, int b) { return ((a -= b) < 0) ? a + mod : a; }
int mul(int a, int b) { return 1LL * a * b % mod; }
int power(int a, int b) {
  int res = 1;
  for (; b > 0; b >>= 1, a = mul(a, a))
    if (b & 1)
      res = mul(res, a);
  return res;
}

const int Mx = 2e6 + 10;
int fac[Mx], invf[Mx];
void prefact() {
  fac[0] = 1;
  for (int i = 1; i < Mx; i++) {
    fac[i] = mul(fac[i - 1], i);
  }
  invf[Mx - 1] = power(fac[Mx - 1], mod - 2);
  for (int i = Mx - 2; i >= 0; i--) {
    invf[i] = mul(invf[i + 1], i + 1);
  }
}

int ncr(int N, int R) {
  if (R > N)
    return 0;
  if (R == 0 || R == N)
    return 1;
  return mul(fac[N], mul(invf[N - R], invf[R]));
}

int k;
char s[nax];

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

  scanf("%s", s + 1);

  int n = strlen(s + 1);

  int ans = 0;
  for (int i = 0; i <= k; ++i) {
    plusle(ans, mul(ncr(n + k, i), power(25, i)));
  }

  printf("%d\\n", ans);
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int const nax = 1e3 + 10;
const int mod = 1000000007; //
void plusle(int &a, int b) {
  if ((a += b) >= mod)
    a -= mod;
}
void minun(int &a, int b) {
  if ((a -= b) < 0)
    a += mod;
}
int add(int a, int b) { return ((a += b) >= mod) ? a - mod : a; }
int sub(int a, int b) { return ((a -= b) < 0) ? a + mod : a; }
int mul(int a, int b) { return 1LL * a * b % mod; }
int power(int a, int b) {
  int res = 1;
  for (; b > 0; b >>= 1, a = mul(a, a))
    if (b & 1)
      res = mul(res, a);
  return res;
}

const int Mx = 2e6 + 10;
int fac[Mx], invf[Mx];
void prefact() {
  fac[0] = 1;
  for (int i = 1; i < Mx; i++) {
    fac[i] = mul(fac[i - 1], i);
  }
  invf[Mx - 1] = power(fac[Mx - 1], mod - 2);
  for (int i = Mx - 2; i >= 0; i--) {
    invf[i] = mul(invf[i + 1], i + 1);
  }
}

int ncr(int N, int R) {
  if (R > N)
    return 0;
  if (R == 0 || R == N)
    return 1;
  return mul(fac[N], mul(invf[N - R], invf[R]));
}

int k;
char s[nax];

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

  scanf("%s", s + 1);

  int n = strlen(s + 1);

  int ans = 0;
  for (int i = 0; i <= k; ++i) {
    plusle(ans, mul(ncr(n + k, i), power(25, i)));
  }

  printf("%d\\n", ans);
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const int N = 2e6 + 10;
const int mod = 1e9 + 7;

ll fac[N], inv[N];

ll binpow(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] = 1;
  for (int i = 1; i < N; i++)
    fac[i] = fac[i - 1] * i % mod;
  inv[N - 1] = binpow(fac[N - 1], mod - 2);
  for (int i = N - 2; i >= 0; i--)
    inv[i] = inv[i + 1] * (i + 1) % mod;
}

ll C(ll n, ll m) { return fac[n] * inv[m] % mod * inv[n - m] % mod; }

int main() {
  init();
  int k;
  string s;
  cin >> k >> s;
  int n = k + s.size();
  ll ans = 0;
  for (int i = s.size(); i <= n; i++)
    ans += C(n, i) * binpow(25, n - i) % mod, ans %= mod;
  cout << ans << "\\n";
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const int N = 1e6 + 10;
const int mod = 1e9 + 7;

ll fac[N], inv[N];

ll binpow(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] = 1;
  for (int i = 1; i < N; i++)
    fac[i] = fac[i - 1] * i % mod;
  inv[N - 1] = binpow(fac[N - 1], mod - 2);
  for (int i = N - 2; i >= 0; i--)
    inv[i] = inv[i + 1] * (i + 1) % mod;
}

ll C(ll n, ll m) { return fac[n] * inv[m] % mod * inv[n - m] % mod; }

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MAX = 2000005;
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 (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 COM(ll i, ll j) {
  if (i < j)
    return 0;
  if (i < 0 || j < 0)
    return 0;
  return fac[i] * (finv[j] * finv[i - j] % MOD) % MOD;
}
ll modpow(ll a, ll n, ll MOD) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return res;
}
ll k, n;
string s;
ll ans;
int main(void) {
  cin >> k >> s;
  n = s.size();
  COMinit();
  for (ll i = n; i <= n + k; i++) {
    ll l = modpow(25, i - n, MOD);
    l = l * COM(i - 1, n - 1) % MOD;
    ll r = modpow(26, n + k - i, MOD);
    ans = (ans + (l * r) % MOD) % MOD;
    // cout<<ans<<endl;
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MAX = 1000005;
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 (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 COM(ll i, ll j) {
  if (i < j)
    return 0;
  if (i < 0 || j < 0)
    return 0;
  return fac[i] * (finv[j] * finv[i - j] % MOD) % MOD;
}
ll modpow(ll a, ll n, ll MOD) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return res;
}
ll k, n;
string s;
ll ans;
int main(void) {
  cin >> k >> s;
  n = s.size();
  COMinit();
  for (ll i = n; i <= n + k; i++) {
    ll l = (modpow(25, i - n, MOD) * COM(i - 1, n - 1)) % MOD;
    ll r = modpow(26, n + k - i, MOD);
    ans = (ans + (l * r) % MOD) % MOD;
    // cout<<ans<<endl;
  }
  cout << ans << endl;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

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

constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int MAX = 3000000;

vector<long> fact(MAX), finv(MAX), inve(MAX);

void init() {
  fact.at(0) = fact.at(1) = 1;
  finv.at(0) = finv.at(1) = 1;
  inve.at(1) = 1;
  for (int i = 2; i < MAX; i++) {
    fact.at(i) = fact.at(i - 1) * i % MOD;
    inve.at(i) = MOD - inve.at(MOD % i) * (MOD / i) % MOD;
    finv.at(i) = finv.at(i - 1) * inve.at(i) % MOD;
  }
}

long com(long n, long r) {
  if (n < r || n < 0 || r < 0)
    return 0;
  return fact.at(n) * (finv.at(r) * finv.at(n - r) % MOD) % MOD;
}

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

int main() {
  init();
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N;
  string S;
  cin >> N >> S;
  int M = S.size();
  N += M;
  long ans = 0;
  for (int i = M; i <= N; i++) {
    long tmp = com(i - 1, M - 1);
    (tmp *= mpow(25, i - M)) %= MOD;
    (tmp *= mpow(26, N - i)) %= MOD;
    (ans += tmp) %= MOD;
  }
  cout << ans << "\\n";
}

Error: 0

Fixed submission:

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

constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int MAX = 510000;

vector<long> fact(MAX), finv(MAX), inve(MAX);

void init() {
  fact.at(0) = fact.at(1) = 1;
  finv.at(0) = finv.at(1) = 1;
  inve.at(1) = 1;
  for (int i = 2; i < MAX; i++) {
    fact.at(i) = fact.at(i - 1) * i % MOD;
    inve.at(i) = MOD - inve.at(MOD % i) * (MOD / i) % MOD;
    finv.at(i) = finv.at(i - 1) * inve.at(i) % MOD;
  }
}

long com(long n, long r) {
  if (n < r || n < 0 || r < 0)
    return 0;
  return fact.at(n) * (finv.at(r) * finv.at(n - r) % MOD) % MOD;
}

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

int main() {
  init();
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N;
  string S;
  cin >> N >> S;
  int M = S.size();
  N += M;
  long ans = 0;
  for (int i = M; i <= N; i++) {
    long tmp = com(i - 1, M - 1);
    (tmp *= mpow(25, i - M)) %= MOD;
    (tmp *= mpow(26, N - i)) %= MOD;
    (ans += tmp) %= MOD;
  }
  cout << ans << "\\n";
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int MAXN = 1e7 + 5;
const int MAXD = 2e7 + 5;
const int mod = 1e9 + 7;

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

ll fac[MAXN], inv[MAXN];
inline ll c(int n, int m) {
  if (n < 0 || m < 0 || n < m)
    return 0;
  return fac[n] * inv[m] % mod * inv[n - m] % mod;
}

ll pw25[MAXN], pw26[MAXN];

char s[MAXN];

int main(void) {
  fac[0] = 1;
  for (int i = 1; i < MAXN; ++i)
    fac[i] = fac[i - 1] * i % mod;
  inv[MAXN - 1] = pw(fac[MAXN - 1], mod - 2);
  for (int i = MAXN - 2; i >= 0; --i)
    inv[i] = inv[i + 1] * (i + 1) % mod;

  int d;
  scanf("%d%s", &d, s + 1);
  int n = strlen(s + 1);

  pw25[0] = pw26[0] = 1;
  for (int i = 1; i < MAXN; ++i)
    pw25[i] = pw25[i - 1] * 25 % mod, pw26[i] = pw26[i - 1] * 26 % mod;

  ll ans = 0;
  for (int i = 0; i <= d; ++i)
    ans = (ans + pw25[i] * c(i + n - 1, n - 1) % mod * pw26[d - i]) % mod;
  printf("%lld", ans);
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int MAXN = 1e6 + 5;
const int MAXD = 2e6 + 5;
const int mod = 1e9 + 7;

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

ll fac[MAXN], inv[MAXN];
inline ll c(int n, int m) {
  if (n < 0 || m < 0 || n < m)
    return 0;
  return fac[n] * inv[m] % mod * inv[n - m] % mod;
}

ll pw25[MAXD], pw26[MAXD];

char s[MAXN];

int main(void) {
  fac[0] = 1;
  for (int i = 1; i < MAXN; ++i)
    fac[i] = fac[i - 1] * i % mod;
  inv[MAXN - 1] = pw(fac[MAXN - 1], mod - 2);
  for (int i = MAXN - 2; i >= 0; --i)
    inv[i] = inv[i + 1] * (i + 1) % mod;

  int d;
  scanf("%d%s", &d, s + 1);
  int n = strlen(s + 1);

  pw25[0] = pw26[0] = 1;
  for (int i = 1; i <= d; ++i)
    pw25[i] = pw25[i - 1] * 25 % mod, pw26[i] = pw26[i - 1] * 26 % mod;

  ll ans = 0;
  for (int i = 0; i <= d; ++i)
    ans = (ans + pw25[i] * c(i + n - 1, n - 1) % mod * pw26[d - i]) % mod;
  printf("%lld", ans);
  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = {1, 0, -1, 0}, dj[4] = {0, 1, 0, -1};

#define N 2000007
ll fac[N], inv[N], finv[N];

void cominit(int n) {
  int i;
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (i = 2; i < n + 2; 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;
  }
  return;
}

ll com(int n, int r) {
  if (n < r)
    return 0;
  if (n < 0 || r < 0)
    return 0;
  if (r == 0 || r == n)
    return 1;
  return (fac[n] * finv[r]) % mod * finv[n - r] % mod;
}

ll ml_pow(ll n, ll k, int p) {
  ll y, res;

  res = 1;
  y = n;
  while (k > 0) {
    if (k % 2 == 1) {
      res = res * y % p;
    }
    y = y * y % p;
    k /= 2;
  }

  return res;
}

int main(void) {
  int n, k, i, ans;
  string s;

  scanf("%d", &k);
  cin >> s;

  n = s.size();

  cominit(n + k);

  ans = 0;
  for (i = n; i <= n + k; i++) {
    ans = (ans + com(i - 1, n - 1) * ml_pow(25, i - n, mod) % mod *
                     ml_pow(26, n + k - i, mod) % mod) %
          mod;
  }

  printf("%d\\n", ans);

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = {1, 0, -1, 0}, dj[4] = {0, 1, 0, -1};

#define N 200007
ll fac[N], inv[N], finv[N];

void cominit(int n) {
  int i;
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (i = 2; i < n + 2; 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;
  }
  return;
}

ll com(int n, int r) {
  if (n < r)
    return 0;
  if (n < 0 || r < 0)
    return 0;
  if (r == 0 || r == n)
    return 1;
  return (fac[n] * finv[r]) % mod * finv[n - r] % mod;
}

ll ml_pow(ll n, ll k, int p) {
  ll y, res;

  res = 1;
  y = n;
  while (k > 0) {
    if (k % 2 == 1) {
      res = res * y % p;
    }
    y = y * y % p;
    k /= 2;
  }

  return res;
}

int main(void) {
  int n, k, i, ans;
  string s;

  scanf("%d", &k);
  cin >> s;

  n = s.size();

  cominit(n + k);

  ans = 0;
  for (i = n; i <= n + k; i++) {
    ans = (ans + com(i - 1, n - 1) * ml_pow(25, i - n, mod) % mod *
                     ml_pow(26, n + k - i, mod) % mod) %
          mod;
  }

  printf("%d\\n", ans);

  return 0;
}