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 MOD = 1e9 + 7;
const int mx = 3e6 + 9;

inline void normal(ll &a) {
  if (a >= MOD)
    a %= MOD;
  (a < 0) && (a += MOD);
}
inline ll modMul(ll a, ll b) {
  normal(a), normal(b);
  return (a * b) % MOD;
}
inline ll modAdd(ll a, ll b) {
  normal(a), normal(b);
  return (a + b) % MOD;
}
inline ll modSub(ll a, ll b) {
  normal(a), normal(b);
  a -= b;
  normal(a);
  return a;
}
inline ll modPow(ll b, ll p) {
  ll r = 1;
  while (p) {
    if (p & 1)
      r = modMul(r, b);
    b = modMul(b, b);
    p >>= 1;
  }
  return r;
} // if MOD is prime, modPow(b, p % (MOD-1))
inline ll modInverse(ll a) { return modPow(a, MOD - 2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll f[mx];

ll nCr(ll n, ll r) { return modDiv(f[n], modMul(f[r], f[n - r])); }

int main() {
  f[0] = 1;
  for (int i = 1; i < mx; i++)
    f[i] = modMul(i, f[i - 1]);
  int k;
  string s;
  cin >> k >> s;

  int sz = s.size();
  int n = k + sz;
  int z = 26;

  ll ans = 0;
  for (int m = 0; m < sz; m++) {
    ll temp = nCr(n, m);
    temp = modMul(temp, modPow(z - 1, n - m));
    ans = modAdd(ans, temp);
  }

  ans = modSub(modPow(z, n), ans);
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include "bits/stdc++.h"

using namespace std;
using ll = long long;

const ll MOD = 1e9 + 7;
const int mx = 1e6 + 9;

inline void normal(ll &a) {
  if (a >= MOD)
    a %= MOD;
  (a < 0) && (a += MOD);
}
inline ll modMul(ll a, ll b) {
  normal(a), normal(b);
  return (a * b) % MOD;
}
inline ll modAdd(ll a, ll b) {
  normal(a), normal(b);
  return (a + b) % MOD;
}
inline ll modSub(ll a, ll b) {
  normal(a), normal(b);
  a -= b;
  normal(a);
  return a;
}
inline ll modPow(ll b, ll p) {
  ll r = 1;
  while (p) {
    if (p & 1)
      r = modMul(r, b);
    b = modMul(b, b);
    p >>= 1;
  }
  return r;
} // if MOD is prime, modPow(b, p % (MOD-1))
inline ll modInverse(ll a) { return modPow(a, MOD - 2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll f[mx];

ll nCr(ll n, ll r) { return modDiv(f[n], modMul(f[r], f[n - r])); }

int main() {
  f[0] = 1;
  for (int i = 1; i < mx; i++)
    f[i] = modMul(i, f[i - 1]);
  int k;
  string s;
  cin >> k >> s;

  int sz = s.size();
  int n = k + sz;
  int z = 26;

  ll ans = 0;
  for (int m = 0; m < sz; m++) {
    ll temp = nCr(n, m);
    temp = modMul(temp, modPow(z - 1, n - m));
    ans = modAdd(ans, temp);
  }

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

#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6 + 10, mod = 1e9 + 7;
typedef long long ll;
ll fact[maxn], inv[maxn];
ll exp(ll a, ll b) {
  ll res = 1LL;
  for (; b; b >>= 1, a = (a * a) % mod)
    if (b & 1)
      res = (res * a) % mod;
  return res;
}
void precalc() {
  fact[0] = 1LL;
  for (int i = 1; i < maxn; i++)
    fact[i] = (fact[i - 1] * i) % mod;
  inv[maxn - 1] = exp(fact[maxn - 1], mod - 2);
  for (int i = maxn - 2; i >= 0; i--)
    inv[i] = (inv[i + 1] * (i + 1)) % mod;
}
ll ncr(ll n, ll r) {
  if (n < r)
    return 0LL;
  return ((fact[n] * inv[n - r]) % mod * inv[r]) % mod;
}
int main() {
  precalc();
  ll k;
  cin >> k;
  string s;
  cin >> s;
  ll n = (int)s.size();
  ll l = n + k;
  ll ans = 0LL;
  for (ll i = n; i <= l; i++)
    ans = (ans + ((ncr(i - 1, n - 1) * exp(25, i - n)) % mod * exp(26, l - i)) %
                     mod) %
          mod;
  cout << ans << "\\n";
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10, mod = 1e9 + 7;
typedef long long ll;
ll fact[maxn], inv[maxn];
ll exp(ll a, ll b) {
  ll res = 1LL;
  for (; b; b >>= 1, a = (a * a) % mod)
    if (b & 1)
      res = (res * a) % mod;
  return res;
}
void precalc() {
  fact[0] = 1LL;
  for (int i = 1; i < maxn; i++)
    fact[i] = (fact[i - 1] * i) % mod;
  inv[maxn - 1] = exp(fact[maxn - 1], mod - 2);
  for (int i = maxn - 2; i >= 0; i--)
    inv[i] = (inv[i + 1] * (i + 1)) % mod;
}
ll ncr(ll n, ll r) {
  if (n < r)
    return 0LL;
  return ((fact[n] * inv[n - r]) % mod * inv[r]) % mod;
}
int main() {
  precalc();
  ll k;
  cin >> k;
  string s;
  cin >> s;
  ll n = (int)s.size();
  ll l = n + k;
  ll ans = 0LL;
  for (ll i = n; i <= l; i++)
    ans = (ans + ((ncr(i - 1, n - 1) * exp(25, i - n)) % mod * exp(26, l - i)) %
                     mod) %
          mod;
  cout << ans << "\\n";
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define foi(i, k, n) for (int i = (int)k; i < (int)n; ++i)

using namespace std;

constexpr int MOD = 7 + 1e9;
constexpr int MAXN = 5 + 3e6;

int add(int a, int b) {
  int ans = a + b;
  if (ans >= MOD)
    ans -= MOD;
  return ans;
}

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

int fpow(int b, int e) {
  int ans = 1;
  for (; e; e >>= 1) {
    if (e & 1)
      ans = mul(ans, b);
    b = mul(b, b);
  }
  return ans;
}

int f[MAXN];
int choose(int n, int k) {
  assert(k <= n);
  return mul(f[n], fpow(mul(f[k], f[n - k]), MOD - 2));
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  f[0] = 1;
  for (int i = 1; i < MAXN; ++i) {
    f[i] = mul(f[i - 1], i);
  }
  int n, k, ans = 0;
  cin >> k;
  string s;
  cin >> s;
  n = s.size() + k;
  k = s.size();
  for (int j = 0; j <= n - k; ++j) {
    ans = add(ans, mul(choose(n, j + k), fpow(25, n - k - j)));
  }
  cout << ans << '\\n';
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define foi(i, k, n) for (int i = (int)k; i < (int)n; ++i)

using namespace std;

constexpr int MOD = 7 + 1e9;
constexpr int MAXN = 5 + 1e6;

int add(int a, int b) {
  int ans = a + b;
  if (ans >= MOD)
    ans -= MOD;
  return ans;
}

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

int fpow(int b, int e) {
  int ans = 1;
  for (; e; e >>= 1) {
    if (e & 1)
      ans = mul(ans, b);
    b = mul(b, b);
  }
  return ans;
}

int f[MAXN];
int choose(int n, int k) {
  assert(k <= n);
  return mul(f[n], fpow(mul(f[k], f[n - k]), MOD - 2));
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  f[0] = 1;
  for (int i = 1; i < MAXN; ++i) {
    f[i] = mul(f[i - 1], i);
  }
  int n, k, ans = 0;
  cin >> k;
  string s;
  cin >> s;
  n = s.size() + k;
  k = s.size();
  for (int j = 0; j <= n - k; ++j) {
    ans = add(ans, mul(choose(n, j + k), fpow(25, n - k - j)));
  }
  cout << ans << '\\n';
  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6 + 10;
const int mod = 1e9 + 7;
int n, m;
int fac[maxn], ifac[maxn];
char s[maxn];
int mul(int x, int y) { return 1ll * x * y % mod; }
int fpw(int x, int y) {
  int r = 1;
  for (int i = y; i; i >>= 1, x = mul(x, x))
    if (i & 1)
      r = mul(r, x);
  return r;
}
int inv(int x) { return fpw(x, mod - 2); }
int mul(int x, int y, int z) { return mul(x, mul(y, z)); }
int C(int n, int m) { return mul(fac[n], ifac[m], ifac[n - m]); }
int read() {
  int x;
  scanf("%d", &x);
  return x;
}
int main() {
#ifdef LOCAL
  freopen("1.in", "r", stdin);
#endif
  n = read();
  scanf("%s", s);
  m = strlen(s);
  fac[0] = ifac[0] = 1;
  for (int i = 1; i <= n + m; ++i)
    fac[i] = mul(fac[i - 1], i), ifac[i] = mul(ifac[i - 1], inv(i));
  // new length = m + n
  int ans = 0;
  for (int i = 0; i <= n; ++i) {
    ans += mul(mul(C(m + i - 1, i), fpw(25, i)), fpw(26, n - i));
    ans %= mod;
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
const int mod = 1e9 + 7;
int n, m;
int fac[maxn], ifac[maxn];
char s[maxn];
int mul(int x, int y) { return 1ll * x * y % mod; }
int fpw(int x, int y) {
  int r = 1;
  for (int i = y; i; i >>= 1, x = mul(x, x))
    if (i & 1)
      r = mul(r, x);
  return r;
}
int inv(int x) { return fpw(x, mod - 2); }
int mul(int x, int y, int z) { return mul(x, mul(y, z)); }
int C(int n, int m) { return mul(fac[n], ifac[m], ifac[n - m]); }
int read() {
  int x;
  scanf("%d", &x);
  return x;
}
int main() {
#ifdef LOCAL
  freopen("1.in", "r", stdin);
#endif
  n = read();
  scanf("%s", s);
  m = strlen(s);
  fac[0] = ifac[0] = 1;
  for (int i = 1; i <= n + m; ++i)
    fac[i] = mul(fac[i - 1], i), ifac[i] = mul(ifac[i - 1], inv(i));
  // new length = m + n
  int ans = 0;
  for (int i = 0; i <= n; ++i) {
    ans += mul(mul(C(m + i - 1, i), fpw(25, i)), fpw(26, n - i));
    ans %= mod;
  }
  cout << ans << endl;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
ll fac[2000005];
ll qpow(ll x, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}
ll C(ll n, ll m) {
  return fac[n] * qpow(fac[m], mod - 2) % mod * qpow(fac[n - m], mod - 2) % mod;
}
int main() {
  // freopen("in.txt","r",stdin);
  fac[0] = 1;
  fac[1] = 1;
  for (ll i = 2; i < 2000002; i++) {
    fac[i] = i * fac[i - 1];
    fac[i] %= mod;
  }
  ll k;
  cin >> k;
  string ss;
  cin >> ss;
  ll s = ss.size();
  ll ans = 0;
  for (ll i = 0; i < s; i++) {
    ans += C(k + s, i) * qpow(25, k + s - i);
    ans %= mod;
  }
  cout << (qpow(26, k + s) - ans + mod) % mod << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
ll fac[1000005];
ll inv[1000005];
ll qpow(ll x, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}
ll C(ll n, ll m) { return fac[n] * inv[fac[m]] % mod * inv[fac[n - m]] % mod; }
int main() {
  fac[1] = 1;
  for (ll i = 2; i < 1000000; i++) {
    fac[i] = i * fac[i - 1];
    fac[i] %= mod;
  }
  inv[0] = 1;
  inv[1] = 1; // inv[0]=1 !!!
  for (ll i = 2; i <= 1000000; i++) {
    inv[i] = (mod - mod / i) * inv[mod % i] % mod;
  }
  ll k;
  cin >> k;
  string ss;
  cin >> ss;
  ll s = ss.size();
  ll ans = 0;
  for (ll i = 0; i < s; i++) {
    ans += C(k + s, i) * qpow(25, k + s - i);
    ans %= mod;
  }
  cout << (qpow(26, k + s) - ans + mod) % mod << endl;
  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
const int MAX = 2000001;
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() {
  long long ans = 0;
  int K;
  // int MOD = 1000000007;
  string S;
  cin >> K >> S;
  int l = S.size();
  COMinit();
  for (int i = 0; i <= K; i++) {
    ans = (ans + ((COM(i + l - 1, i) * modpow(25, i, MOD)) % MOD) *
                     modpow(26, K - i, MOD)) %
          MOD;
    // cout << ans << endl;
  }

  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
const int MAX = 1000001;
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() {
  long long ans = 0;
  int K;
  // int MOD = 1000000007;
  string S;
  cin >> K >> S;
  int l = S.size();
  COMinit();
  for (int i = 0; i <= K; i++) {
    ans = (ans + ((COM(i + l - 1, i) * modpow(25, i, MOD)) % MOD) *
                     modpow(26, K - i, MOD)) %
          MOD;
    // cout << ans << endl;
  }

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

#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll N = 2e6 + 30, Mod = 1e9 + 7;
const ll SQ = 330;

ll F[N], I[N];
ll mul(ll a, ll b) { return (a * b) % Mod; }
ll sum(ll a, ll b) { return (a + b + Mod) % Mod; }
ll Pow(ll a, ll b) {
  ll res = 1;
  for (; b; b >>= 1, a = mul(a, a))
    if (b & 1)
      res = mul(res, a);
  return res;
}
ll C(ll r, ll n) {
  if (r < 0 || r > n)
    return 0;
  return mul(F[n], mul(I[r], I[n - r]));
}
ll inv(ll x) { return Pow(x, Mod - 2); }
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  F[0] = 1;
  for (int i = 1; i < N; i++)
    F[i] = mul(i, F[i - 1]);
  I[N - 1] = Pow(F[N - 1], Mod - 2);
  for (int i = N - 2; ~i; i--)
    I[i] = mul(i + 1, I[i + 1]);
  ll ans = 0;
  ll k;
  cin >> k;
  string s;
  cin >> s;
  ll n = s.size();
  for (int i = 0; i <= k; i++) {
    ll res = 0;
    res = C(n - 1, k + n - i - 1);
    res = mul(res, Pow(25, k - i));
    res = mul(res, Pow(26, i));
    ans = sum(ans, res);
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll N = 1e6 + 30, Mod = 1e9 + 7;
const ll SQ = 330;

ll F[N], I[N];
ll mul(ll a, ll b) { return (a * b) % Mod; }
ll sum(ll a, ll b) { return (a + b + Mod) % Mod; }
ll Pow(ll a, ll b) {
  ll res = 1;
  for (; b; b >>= 1, a = mul(a, a))
    if (b & 1)
      res = mul(res, a);
  return res;
}
ll C(ll r, ll n) {
  if (r < 0 || r > n)
    return 0;
  return mul(F[n], mul(I[r], I[n - r]));
}
ll inv(ll x) { return Pow(x, Mod - 2); }
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  F[0] = 1;
  for (int i = 1; i < N; i++)
    F[i] = mul(i, F[i - 1]);
  I[N - 1] = Pow(F[N - 1], Mod - 2);
  for (int i = N - 2; ~i; i--)
    I[i] = mul(i + 1, I[i + 1]);
  ll ans = 0;
  ll k;
  cin >> k;
  string s;
  cin >> s;
  ll n = s.size();
  for (int i = 0; i <= k; i++) {
    ll res = 0;
    res = C(n - 1, k + n - i - 1);
    res = mul(res, Pow(25, k - i));
    res = mul(res, Pow(26, i));
    ans = sum(ans, res);
  }
  cout << ans << endl;
}
Problem p02632 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 1000000007;
int f[2000010], in[2000010];
int cc(int n, int m) {
  int sum = 1;
  for (; m; m >>= 1, n = n * n % mod)
    if (m & 1)
      sum = sum * n % mod;
  return sum;
}
int c(int n, int m) { return f[n] * in[m] % mod * in[n - m] % mod; }
signed main() {
  int k;
  int sum = 0;
  string s;
  cin >> k >> s;
  f[0] = 1;
  in[0] = 1;
  for (int i = 1; i < k + s.size() + 5; i++) {
    f[i] = f[i - 1] * i % mod;
    in[i] = cc(f[i], mod - 2);
  }
  for (int i = 0; i <= k; i++) {
    sum = (sum + cc(26, i) * cc(25, k - i) % mod *
                     c(k - i + s.size() - 1, s.size() - 1)) %
          mod;
  }
  cout << sum << endl;
  return 0;
}
/*
                                A CCCCCCCCCC AAA                  C A   A C A A
   C AAAAAAAAA               C A         A              CCCCCCCCCC
*/

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 1e7;
int f[2000010], in[2000010];
int cc(int n, int m) {
  int sum = 1;
  for (; m; m >> 1, n *= n % mod) {
    if (m & 1) {
      sum *= n % mod;
    }
  }
  return sum;
}
int c(int n, int m) { return f[n] * in[m] % mod * in[n - m] % mod; }
signed main() {
  int k;
  int sum = 0;
  string s;
  cin >> k >> s;
  f[0] = 1;
  in[0] = 1;
  for (int i = 1; i < k + s.size() + 5; i++) {
    f[i] = f[i - 1] * i % mod;
    in[i] = cc(f[i], mod - 2);
  }
  for (int i = 0; i <= k; i++) {
    sum = (sum + cc(26, i) * cc(25, k - i) % mod *
                     c(k - i + s.size() - 1, s.size() - 1)) %
          mod;
  }
  cout << sum << endl;
  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define boost                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(nullptr)

const int N = 2e6 + 5;
const int M = 1e9 + 7;

int mod(int m) {
  m %= M;
  return (m + M) % M;
}

int power(int x, int y) {
  int res = 1;
  x = mod(x);
  while (y > 0) {
    if (y & 1)
      res = mod(res * x);
    y = y >> 1;
    x = mod(x * x);
  }
  return mod(res);
}

int f[N], invf[N];
void fact() {
  f[0] = f[1] = 1;
  for (int i = 2; i < N; i++)
    f[i] = mod(f[i - 1] * i);

  invf[N - 1] = power(f[N - 1], M - 2);
  for (int i = N - 1; i > 0; i--)
    invf[i - 1] = mod(invf[i] * i);
}

int nCr(int n, int r) {
  if (r > n)
    return 0;
  int ans = f[n];
  ans = mod(ans * invf[n - r]);
  ans = mod(ans * invf[r]);
  return ans;
}

int nPr(int n, int r) {
  if (r > n)
    return 0;
  int ans = f[n];
  ans = mod(ans * invf[n - r]);
  return ans;
}

int32_t main() {
  fact();
  boost;
  int k;
  cin >> k;
  string s;
  cin >> s;
  int m = s.size();
  int n = m + k;
  int ans = power(26, n);
  for (int i = 0; i < m; i++)
    ans = mod(ans - mod(nCr(n, i) * power(25, n - i)));
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define boost                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(nullptr)

const int N = 1e6 + 5;
const int M = 1e9 + 7;

int mod(int m) {
  m %= M;
  return (m + M) % M;
}

int power(int x, int y) {
  int res = 1;
  x = mod(x);
  while (y > 0) {
    if (y & 1)
      res = mod(res * x);
    y = y >> 1;
    x = mod(x * x);
  }
  return mod(res);
}

int f[N], invf[N];
void fact() {
  f[0] = f[1] = 1;
  for (int i = 2; i < N; i++)
    f[i] = mod(f[i - 1] * i);

  invf[N - 1] = power(f[N - 1], M - 2);
  for (int i = N - 1; i > 0; i--)
    invf[i - 1] = mod(invf[i] * i);
}

int nCr(int n, int r) {
  if (r > n)
    return 0;
  int ans = f[n];
  ans = mod(ans * invf[n - r]);
  ans = mod(ans * invf[r]);
  return ans;
}

int nPr(int n, int r) {
  if (r > n)
    return 0;
  int ans = f[n];
  ans = mod(ans * invf[n - r]);
  return ans;
}

int32_t main() {
  fact();
  boost;
  int k;
  cin >> k;
  string s;
  cin >> s;
  int m = s.size();
  int n = m + k;
  int ans = power(26, n);
  for (int i = 0; i < m; i++)
    ans = mod(ans - mod(nCr(n, i) * power(25, n - i)));
  cout << ans << endl;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const long long md = 1e9 + 7;
long long pw(long long x, long long y) {
  long long ans = 1;
  while (y) {
    if (y & 1) {
      ans *= x;
      ans %= md;
    }
    x *= x;
    x %= md;
    y >>= 1;
  }
  return ans;
}
long long ff[2020202], fff[2020202], n, ans = 1;
string s;
long long C(long long x, long long y) {
  return ff[x] * fff[x - y] % md * fff[y] % md;
}
int main() {
  cin >> n >> s;
  ff[0] = 1;
  for (int i = 1; i <= 2020000; i++) {
    ff[i] = ff[i - 1] * i;
    ff[i] %= md;
  }
  fff[2020000] = pw(ff[2020000], md - 2);
  for (int i = 2019999; i >= 1; i--) {
    fff[i] = fff[i + 1] * (i + 1);
    fff[i] %= md;
  }
  for (int i = s.size(); i <= s.size() + n; i++) {
    ans += C(s.size() + n, i) * pw(25, s.size() + n - i) % md;
    ans %= md;
  }
  cout << ans << endl;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const long long md = 1e9 + 7;
long long pw(long long x, long long y) {
  long long ans = 1;
  while (y) {
    if (y & 1) {
      ans *= x;
      ans %= md;
    }
    x *= x;
    x %= md;
    y >>= 1;
  }
  return ans;
}
long long ff[1010101], fff[1010101], n, ans;
string s;
long long C(long long x, long long y) {
  return ff[x] * fff[x - y] % md * fff[y] % md;
}
int main() {
  cin >> n >> s;
  ff[0] = 1;
  for (int i = 1; i <= 1010000; i++) {
    ff[i] = ff[i - 1] * i;
    ff[i] %= md;
  }
  fff[1010000] = pw(ff[1010000], md - 2);
  for (int i = 1009999; i >= 1; i--) {
    fff[i] = fff[i + 1] * (i + 1);
    fff[i] %= md;
  }
  for (int i = s.size(); i <= s.size() + n; i++) {
    ans += C(s.size() + n, i) * pw(25, s.size() + n - i) % md;
    ans %= md;
  }
  cout << ans << endl;
  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
const int MAX = 2000100;
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(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

int main() {
  long k;
  cin >> k;
  string s;
  cin >> s;
  long n = s.size();
  COMinit();
  long ans = 0;
  rep2(i, n, k + n + 1) {
    ans = (ans + modpow(25, i - n, MOD) * modpow(26, k + n - i, MOD) % MOD *
                     COM(i - 1, n - 1)) %
          MOD;
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
const int MAX = 200100;
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(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

int main() {
  long k;
  cin >> k;
  string s;
  cin >> s;
  long n = s.size();
  COMinit();
  long ans = 0;
  rep2(i, n, k + n + 1) {
    ans = (ans + modpow(25, i - n, MOD) * modpow(26, k + n - i, MOD) % MOD *
                     COM(i - 1, n - 1)) %
          MOD;
  }
  cout << ans << endl;
}