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

#include <bits/stdc++.h>

const int64_t MOD = 1000000007;
int64_t ff[2000006];

int64_t fact(int n) {
  if (n == 0)
    return 1;
  if (n == 1)
    return 1;
  if (ff[n] != 0)
    return ff[n];
  ff[n] = (fact(n - 1) * n) % MOD;
  return ff[n] % MOD;
}

int64_t pm(int64_t a, int64_t b) {
  if (b == 0)
    return 1;
  if (b == 1)
    return a % MOD;
  int64_t v = pm(a, b / 2) % MOD;
  v = v * v % MOD;
  if (b % 2) {
    return v * a % MOD;
  }
  return v;
}

int main() {
  int64_t ans = 0;
  int N;
  int K;
  std::cin >> K;
  std::string s;
  std::cin >> s;
  N = s.size();

  int64_t st = N + K;
  for (; st >= N; --st) {
    int64_t v = pm(26, N + K - st) * pm(25, st - N) % MOD;
    v = v * fact(st - 1) % MOD;
    v = v * pm(fact(st - N), MOD - 2) % MOD;
    v = v * pm(fact(N - 1), MOD - 2) % MOD;
    ans += v;
    ans = ans % MOD;
  }

  printf("%lld\\n", ans % MOD);
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

const int64_t MOD = 1000000007;
int64_t ff[1000006];

int64_t fact(int n) {
  if (n == 0)
    return 1;
  if (n == 1)
    return 1;
  if (ff[n] != 0)
    return ff[n];
  ff[n] = (fact(n - 1) * n) % MOD;
  return ff[n] % MOD;
}

int64_t pm(int64_t a, int64_t b) {
  if (b == 0)
    return 1;
  if (b == 1)
    return a % MOD;
  int64_t v = pm(a, b / 2) % MOD;
  v = v * v % MOD;
  if (b % 2) {
    return v * a % MOD;
  }
  return v;
}

int main() {
  int64_t ans = 0;
  int N;
  int K;
  std::cin >> K;
  std::string s;
  std::cin >> s;
  N = s.size();

  int64_t st = N + K;
  for (; st >= N; --st) {
    int64_t v = pm(26, N + K - st) * pm(25, st - N) % MOD;
    v = v * fact(st - 1) % MOD;
    v = v * pm(fact(st - N), MOD - 2) % MOD;
    v = v * pm(fact(N - 1), MOD - 2) % MOD;
    ans += v;
    ans = ans % MOD;
  }

  printf("%lld\\n", ans % MOD);
}
Problem p02632 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>

#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
ll N, K;
ll m;
string S;
ll d;
ll M = 1000000007;
vector<ll> fac(5000001);  // n!(mod M)
vector<ll> ifac(5000001); // k!^{M-2} (mod M)
// a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x,
        ll n) { // x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
  ll ans = 1;
  while (n != 0) {
    if (n & 1)
      ans = ans * x % M;
    x = x * x % M;
    n = n >> 1;
  }
  return ans;
}

ll comb(ll a, ll b) { // aCbをmod計算
  if (a == 0 && b == 0)
    return 1;
  if (a < b || a < 0)
    return 0;
  ll tmp = ifac[a - b] * ifac[b] % M;
  return tmp * fac[a] % M;
}
int main() {
  fac[0] = 1;
  ifac[0] = 1;
  for (ll i = 0; i < 2000000; i++) {
    fac[i + 1] = fac[i] * (i + 1) % M; // n!(mod M)
    ifac[i + 1] =
        ifac[i] * mpow(i + 1, M - 2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
  }
  cin >> K >> S;
  N = S.size();
  for (ll i = 0; i <= K; i++) {
    d = comb(i + N - 1, N - 1);
    d = (d * mpow(25, i)) % M;
    d = (d * mpow(26, (K - i))) % M;
    m = (m + d) % M;
  }
  cout << m << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>

#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
ll N, K;
ll m;
string S;
ll d;
ll M = 1000000007;
vector<ll> fac(5000001);  // n!(mod M)
vector<ll> ifac(5000001); // k!^{M-2} (mod M)
// a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x,
        ll n) { // x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
  ll ans = 1;
  while (n != 0) {
    if (n & 1)
      ans = ans * x % M;
    x = x * x % M;
    n = n >> 1;
  }
  return ans;
}

ll comb(ll a, ll b) { // aCbをmod計算
  if (a == 0 && b == 0)
    return 1;
  if (a < b || a < 0)
    return 0;
  ll tmp = ifac[a - b] * ifac[b] % M;
  return tmp * fac[a] % M;
}
int main() {
  fac[0] = 1;
  ifac[0] = 1;
  for (ll i = 0; i < 5000000; i++) {
    fac[i + 1] = fac[i] * (i + 1) % M; // n!(mod M)
    ifac[i + 1] =
        ifac[i] * mpow(i + 1, M - 2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
  }
  cin >> K >> S;
  N = S.size();
  for (ll i = 0; i <= K; i++) {
    d = comb(i + N - 1, N - 1);
    d = (d * mpow(25, i)) % M;
    d = (d * mpow(26, (K - i))) % M;
    m = (m + d) % M;
  }
  cout << m << endl;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define endl "\\n"
using namespace std;
typedef long long int lli;
const lli M = 1e9 + 7, N = 2e6 + 5;
lli fact[N];

lli binpow(lli a, lli b) {
  if (b == 0)
    return 1;
  lli res = binpow(a, b / 2);
  res = (res * res) % M;

  if (b % 2)
    return (res * a) % M;
  return res;
}

lli inv(lli a) { return binpow(a, M - 2); }

lli add(lli a, lli b) {
  lli res = a + b;
  if (res >= M)
    return res - M;
  return res;
}

lli mul(lli a, lli b) {
  lli res = a * b;
  if (res >= M)
    return res % M;
  return res;
}

lli sub(lli a, lli b) { return (a % M - b % M + M) % M; }

void pre() {
  fact[0] = 1;
  for (int i = 1; i < N; i++)
    fact[i] = mul(fact[i - 1], i);
}

lli ncr(lli n, lli r) { return mul(fact[n], inv(mul(fact[n - r], fact[r]))); }

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

  lli k;
  string s;
  cin >> k >> s;
  lli i, n = s.length(), ans = binpow(26, n + k);

  for (i = 0; i < n; i++)
    ans = sub(ans, mul(ncr(n + k, i), binpow(25, n + k - i)));
  cout << ans;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define endl "\\n"
using namespace std;
typedef long long int lli;
const lli M = 1e9 + 7, N = 1e6 + 5;
lli fact[N];

lli binpow(lli a, lli b) {
  if (b == 0)
    return 1;
  lli res = binpow(a, b / 2);
  res = (res * res) % M;

  if (b % 2)
    return (res * a) % M;
  return res;
}

lli inv(lli a) { return binpow(a, M - 2); }

lli add(lli a, lli b) {
  lli res = a + b;
  if (res >= M)
    return res - M;
  return res;
}

lli mul(lli a, lli b) {
  lli res = a * b;
  if (res >= M)
    return res % M;
  return res;
}

lli sub(lli a, lli b) { return (a % M - b % M + M) % M; }

void pre() {
  fact[0] = 1;
  for (int i = 1; i < N; i++)
    fact[i] = mul(fact[i - 1], i);
}

lli ncr(lli n, lli r) { return mul(fact[n], inv(mul(fact[n - r], fact[r]))); }

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

  lli k;
  string s;
  cin >> k >> s;
  lli i, n = s.length(), ans = binpow(26, n + k);

  for (i = 0; i < n; i++)
    ans = sub(ans, mul(ncr(n + k, i), binpow(25, n + k - i)));
  cout << ans;
  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep_lr(i, l, r) for (int i = (l); i < (r); i++)
#define all(x) (x).begin(), (x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<int, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 1000000007;

ll modpow(ll p, ll q) {
  ll ans = 1;
  ll pp = p % MOD;
  while (q) {
    if (q & 1) {
      ans *= pp;
      ans %= MOD;
    }
    q = q >> 1;
    pp *= pp;
    pp %= MOD;
  }
  return ans;
}
V<ll> fac, invfac;
void precom(int n) {
  fac.resize(0);
  invfac.resize(0);
  rep(i, n + 1) {
    if (i == 0)
      fac.push_back(1);
    else
      fac.push_back((fac[i - 1] * i) % MOD);
    invfac.push_back(modpow(fac[i], MOD - 2));
  }
  return;
}
ll com(int n, int r) {
  if (n < r || n < 0 || r < 0)
    return 0;
  int k = n - r;
  ll ans = fac[n];
  ans *= invfac[r];
  ans %= MOD;
  ans *= invfac[k];
  ans %= MOD;

  return ans;
}

int main() {

  precom(2200000);

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

  int n = s.size();
  k += n;

  ll ans = 0;
  rep_lr(i, n, k + 1) {
    ll pt = 1;
    pt *= com(i - 1, n - 1);
    pt %= MOD;
    pt *= modpow(25, (ll)i - n);
    pt %= MOD;
    pt *= modpow(26, (ll)k - i);
    pt %= MOD;
    ans += pt;
    ans %= MOD;
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep_lr(i, l, r) for (int i = (l); i < (r); i++)
#define all(x) (x).begin(), (x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<int, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 1000000007;

ll modpow(ll p, ll q) {
  ll ans = 1;
  ll pp = p % MOD;
  while (q) {
    if (q & 1) {
      ans *= pp;
      ans %= MOD;
    }
    q = q >> 1;
    pp *= pp;
    pp %= MOD;
  }
  return ans;
}
V<ll> fac, invfac;
void precom(int n) {
  fac.resize(0);
  invfac.resize(0);
  rep(i, n + 1) {
    if (i == 0)
      fac.push_back(1);
    else
      fac.push_back((fac[i - 1] * i) % MOD);
    invfac.push_back(modpow(fac[i], MOD - 2));
  }
  return;
}
ll com(int n, int r) {
  if (n < r || n < 0 || r < 0)
    return 0;
  int k = n - r;
  ll ans = fac[n];
  ans *= invfac[r];
  ans %= MOD;
  ans *= invfac[k];
  ans %= MOD;

  return ans;
}

int main() {

  precom(220000);

  int k;
  string s;
  cin >> k >> s;
  int n = s.size();
  k += n;

  ll ans = 0;
  rep_lr(i, n, k + 1) {
    ll pt = 1;
    pt *= com(i - 1, n - 1);
    pt %= MOD;
    pt *= modpow(25, i - n);
    pt %= MOD;
    pt *= modpow(26, k - i);
    pt %= MOD;
    ans += pt;
    ans %= MOD;
  }
  cout << ans << endl;
}
Problem p02632 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;
typedef long long int ll;
#define mod 1000000007
map<int, ll> fact, inv_fact;
ll dmod(ll x) { return ((x + mod) % mod); }
ll power(ll x, ll y) {
  ll ans = 1;
  while (y > 0) {
    if (y & 1)
      ans = dmod(ans * x);
    y /= 2;
    x = dmod(x * x);
  }
  return ans;
}
void precompute(int x) {
  inv_fact[0] = 1;
  fact[0] = 1;
  for (int i = 1; i <= x; ++i) {
    fact[i] = dmod(fact[i - 1] * i);
  }
}
ll outsource(ll n, ll r) { return power(dmod(fact[r] * fact[n - r]), mod - 2); }
ll ncr(ll n, ll r) { return dmod(fact[n] * outsource(n, r)); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int k;
  cin >> k;
  string s;
  cin >> s;
  int n = s.length();
  precompute(n + k);
  ll ans = 0;
  for (int i = n; i <= n + k; ++i) {
    ans += dmod(ncr(n + k, i) * power(25, n + k - i));
  }
  cout << dmod(ans) << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;
typedef long long int ll;
#define mod 1000000007
map<int, ll> fact, inv_fact;
ll dmod(ll x) { return ((x + mod) % mod); }
ll power(ll x, ll y) {
  ll ans = 1;
  while (y > 0) {
    if (y & 1)
      ans = dmod(ans * x);
    y /= 2;
    x = dmod(x * x);
  }
  return ans;
}
void precompute() {
  inv_fact[0] = 1;
  fact[0] = 1;
  for (int i = 1; i <= 2000000; ++i) {
    fact[i] = dmod(fact[i - 1] * i);
  }
}
ll outsource(ll n, ll r) {
  if (inv_fact[n - r] && inv_fact[r])
    return dmod(inv_fact[n - r] * inv_fact[r]);
  if (!inv_fact[n - r])
    inv_fact[n - r] = power(fact[n - r], mod - 2);
  if (!inv_fact[r])
    inv_fact[r] = power(fact[r], mod - 2);
  return dmod(inv_fact[n - r] * inv_fact[r]);
}
ll ncr(ll n, ll r) { return dmod(fact[n] * outsource(n, r)); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int k;
  cin >> k;
  string s;
  cin >> s;
  int n = s.length();
  precompute();
  ll ans = 0;
  for (int i = n; i <= n + k; ++i) {
    ans += dmod(ncr(n + k, i) * power(25, n + k - i));
  }
  cout << dmod(ans) << endl;
  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pb push_back
#define endl '\\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL), cout.sync_with_stdio(true)

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

const int mod = 1e9 + 7;
const int N = 2000005;

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

int mul(int a, int b) { return 1ll * a * b % mod; }

int pwr(int a, int b) {
  int r = 1;
  for (; b; b >>= 1, a = mul(a, a))
    if (b & 1)
      r = mul(r, a);
  return r;
}

int fact[N], ifact[N];

void init() {
  fact[0] = 1;
  for (int i = 1; i < N; i++)
    fact[i] = mul(i, fact[i - 1]);
  ifact[N - 1] = pwr(fact[N - 1], mod - 2);
  for (int i = N - 2; i >= 0; i--)
    ifact[i] = mul(ifact[i + 1], i + 1);
}

int ncr(int n, int r) {
  if (n < r)
    return 0;
  return mul(fact[n], mul(ifact[r], ifact[n - r]));
}

void solve() {
  init();
  int k;
  string s;
  cin >> k >> s;
  int sum = 0, len = k + sz(s);
  for (int m = 0; m < sz(s); m++) {
    sum = add(sum, mul(ncr(len, m), pwr(25, len - m)));
  }
  int total = pwr(26, len);
  total = add(total, -sum + mod);
  cout << total << '\\n';
}

int main() {
  fastio;
  int t = 1;
  // cin >> t;
  while (t--)
    solve();
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pb push_back
#define endl '\\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL), cout.sync_with_stdio(true)

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

const int mod = 1e9 + 7;
const int N = 1000005;

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

int mul(int a, int b) { return 1ll * a * b % mod; }

int pwr(int a, int b) {
  int r = 1;
  for (; b; b >>= 1, a = mul(a, a))
    if (b & 1)
      r = mul(r, a);
  return r;
}

int fact[N + 5], ifact[N + 5];

void init() {
  fact[0] = 1;
  for (int i = 1; i < N; i++)
    fact[i] = mul(i, fact[i - 1]);
  ifact[N - 1] = pwr(fact[N - 1], mod - 2);
  for (int i = N - 2; i >= 0; i--)
    ifact[i] = mul(ifact[i + 1], i + 1);
}

int ncr(int n, int r) {
  if (n < r)
    return 0;
  return mul(fact[n], mul(ifact[r], ifact[n - r]));
}

void solve() {
  init();
  int k;
  string s;
  cin >> k >> s;
  int sum = 0, len = k + sz(s);
  for (int m = 0; m < sz(s); m++) {
    sum = add(sum, mul(ncr(len, m), pwr(25, len - m)));
  }
  int total = pwr(26, len);
  total = add(total, -sum + mod);
  cout << total << '\\n';
}

int main() {
  fastio;
  int t = 1;
  // cin >> t;
  while (t--)
    solve();
  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<vi> vvi;
#define INF (1e9)
const ll MOD = 1000000007;
ll FAC_MAX = 2e6;
ll mpow(ll a, ll n) { // a^n (mod MOD)
  // 二分累乗法 O(log n)
  ll ans = 1;
  while (n != 0) {
    if (n & 1)
      ans = (ans * a) % MOD;
    a = (a * a) % MOD;
    n >>= 1;
  }
  return ans;
}

vi fac_vec;
ll fac(ll n) { // n! (mod MOD)
  if (fac_vec.empty()) {
    fac_vec = vi(FAC_MAX + 10); // (FAC_MAX+10)! まで対応
    fac_vec[0] = 1;
    for (ll i = 1; i < fac_vec.size(); i++) {
      fac_vec[i] = (fac_vec[i - 1] * i) % MOD;
    }
  }
  return fac_vec[n];
}

vi ifac_vec;
ll ifac(ll n) { // (n!)^(-1) (mod MOD)
  // フェルマーの小定理より、k^(-1)≡k^(MOD-2) なので、
  // (n!)^(-1)≡(n!)^(MOD-2)
  if (ifac_vec.empty()) {
    ifac_vec = vi(FAC_MAX + 10); // {(FAC_MAX+10)!}^(-1) まで対応
    ifac_vec[0] = 1;
    for (ll i = 1; i < ifac_vec.size(); i++) {
      ifac_vec[i] = (ifac_vec[i - 1] * mpow(i, MOD - 2)) % MOD;
    }
  }
  return ifac_vec[n];
}

ll comb(ll a, ll b) { // aCb (mod MOD)
  // aCb = a! * (b!)^(-1) * {(a-b)!}^(-1)
  if (a < b || a < 0 || b < 0)
    return 0;
  return (fac(a) * ifac(b) % MOD) * ifac(a - b) % MOD;
}

int main() {
  ll K;
  string S;
  cin >> K >> S;
  ll l = S.length();

  ll ans = 0;
  for (ll i = l; i <= l + K; i++) { // i:Sの最後の文字の位置
    ll a = comb(i - 1, l - 1); // Sの最後以外の文字の位置の選び方
    a *= mpow(25, i - l); // Sの最後の文字の位置以前の、S以外の文字の選び方
    a %= MOD;
    a *= mpow(26, l + K - i); // Sの最後の文字の位置以降の、S以外の文字の選び方
    a %= MOD;
    ans += a;
    ans %= MOD;
  }

  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<vi> vvi;
#define INF (1e9)
const ll MOD = 1000000007;

int main() {
  ll K;
  cin >> K;
  string S;
  cin >> S;
  ll l = S.length();

  vvi DP(l + K + 10, vi(l + 10));
  DP[0][0] = 1;
  for (ll i = 0; i < l + K; i++) {
    for (ll j = 0; j < l; j++) {
      DP[i + 1][j] += DP[i][j] * 25;
      DP[i + 1][j] %= MOD;
      DP[i + 1][j + 1] += DP[i][j];
      DP[i + 1][j + 1] %= MOD;
    }
    DP[i + 1][l] += DP[i][l] * 26;
    DP[i + 1][l] %= MOD;
  }

  cout << DP[l + K][l] << endl;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define INF 1234567890
#define pii pair<LL, LL>
#define LL long long
using namespace std;

LL fpow(LL a, LL b) {
  LL ans = 1;
  while (b) {
    if (b & 1) {
      ans *= a;
      ans %= MOD;
    }
    a *= a;
    a %= MOD;
    b >>= 1;
  }
  return ans;
}

LL fac[2000005], inv[2000005];

void precompute(LL x) {
  fac[0] = 1;
  inv[0] = 1;
  for (LL i = 1; i <= x; i++) {
    fac[i] = fac[i - 1] * i;
    fac[i] %= MOD;
    inv[i] = fpow(fac[i], MOD - 2);
  }
}

LL c(LL n, LL k) {
  if (n < k)
    return 0;
  LL ret = fac[n];
  ret *= inv[k];
  ret %= MOD;
  ret *= inv[n - k];
  ret %= MOD;
  return ret;
}

int main() {
  // clock_t start = clock();
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  LL k;
  string s;
  cin >> k >> s;
  LL n = s.size();
  precompute(2000000);

  LL ans = 0;
  for (int i = 0; i <= k; i++) {
    LL tmp = 1;
    tmp *= fpow(26, i);
    tmp %= MOD;
    tmp *= fpow(25, k - i);
    tmp %= MOD;
    tmp *= c(n - 1 + k - i, n - 1);
    tmp %= MOD;
    ans += tmp;
    ans %= MOD;
  }
  cout << ans << endl;
  // cerr << fixed << setprecision(3) << (clock()-start)*1./CLOCKS_PER_SEC <<
  // endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define INF 1234567890
#define pii pair<LL, LL>
#define LL long long
using namespace std;

LL fac[1000005], inv[1000005];

LL fpow(LL a, LL b) {
  LL ans = 1;
  while (b) {
    if (b & 1) {
      ans *= a;
      ans %= MOD;
    }
    a *= a;
    a %= MOD;
    b >>= 1;
  }
  return ans;
}

// C function for extended Euclidean Algorithm
LL gcdExtended(LL a, LL b, LL *x, LL *y) {
  // Base Case
  if (a == 0) {
    *x = 0, *y = 1;
    return b;
  }

  LL x1, y1; // To store results of recursive call
  LL gcd = gcdExtended(b % a, a, &x1, &y1);

  // Update x and y using results of recursive
  // call
  *x = y1 - (b / a) * x1;
  *y = x1;

  return gcd;
}

LL c(LL n, LL k) {
  if (n < k)
    return 0;
  LL ret = fac[n];
  ret *= inv[k];
  ret %= MOD;
  ret *= inv[n - k];
  ret %= MOD;
  return ret;
}

int main() {
  // clock_t start = clock();
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  LL k;
  string s;
  cin >> k >> s;
  LL n = s.size();
  fac[0] = 1;
  inv[0] = 1;
  for (int i = 1; i <= 1000000; i++) {
    fac[i] = fac[i - 1] * i;
    fac[i] %= MOD;
    inv[i] = fpow(fac[i], MOD - 2);
  }

  LL ans = 0;
  for (int i = 0; i <= k; i++) {
    LL tmp = 1;
    tmp *= fpow(26, i);
    tmp %= MOD;
    tmp *= fpow(25, k - i);
    tmp %= MOD;
    tmp *= c(n - 1 + k - i, n - 1);
    tmp %= MOD;
    ans += tmp;
    ans %= MOD;
  }
  cout << ans << endl;
  // cerr << fixed << setprecision(3) << (clock()-start)*1./CLOCKS_PER_SEC <<
  // endl;
  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

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

typedef long long ll;

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

int f[N], inv[N], finv[N];
// inv[]: inverse element

int powMod(int u, int v) {
  int res = 1;
  while (v) {
    if (v & 1)
      res = (ll)res * u % MOD;
    v >>= 1;
    u = (ll)u * u % MOD;
  }
  return res;
}

void initInv() {
  f[0] = 1;
  for (int i = 1; i < N; i++) {
    f[i] = (ll)f[i - 1] * i % MOD;
  }
  inv[0] = inv[1] = 1;
  for (int i = 2; i < N; i++) {
    inv[i] = (ll)(MOD - MOD / i) * inv[MOD % i] % MOD;
  }
  finv[0] = finv[1] = 1;
  for (int i = 2; i < N; i++) {
    finv[i] = ((ll)finv[i - 1] * inv[i]) % MOD;
  }
}

int C(int x, int y) {
  if (y < 0)
    return 0;
  return ((ll)f[x] * finv[y] % MOD) * finv[x - y] % MOD;
}

int Lucas(int u, int v) {
  if (v == 0)
    return 1;
  return (ll)C(u % MOD, v % MOD) * Lucas(u / MOD, v / MOD) % MOD;
}

int k, n, ans;
string s;

int main() {
  ios::sync_with_stdio(false);
  initInv();
  cin >> k >> s;
  n = s.length();
  for (int pref = 0; pref <= k; pref++) {
    ans = (ans + ((ll)powMod(26ll, pref) * powMod(25ll, k - pref) % MOD *
                  Lucas(n + k - 1 - pref, n - 1) % MOD)) %
          MOD;
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

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

typedef long long ll;

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

int f[N], inv[N], finv[N];
// inv[]: inverse element

int powMod(int u, int v) {
  int res = 1;
  while (v) {
    if (v & 1)
      res = (ll)res * u % MOD;
    v >>= 1;
    u = (ll)u * u % MOD;
  }
  return res;
}

void initInv() {
  f[0] = 1;
  for (int i = 1; i < N; i++) {
    f[i] = (ll)f[i - 1] * i % MOD;
  }
  inv[0] = inv[1] = 1;
  for (int i = 2; i < N; i++) {
    inv[i] = (ll)(MOD - MOD / i) * inv[MOD % i] % MOD;
  }
  finv[0] = finv[1] = 1;
  for (int i = 2; i < N; i++) {
    finv[i] = ((ll)finv[i - 1] * inv[i]) % MOD;
  }
}

int C(int x, int y) {
  if (y < 0)
    return 0;
  return ((ll)f[x] * finv[y] % MOD) * finv[x - y] % MOD;
}

int Lucas(int u, int v) {
  if (v == 0)
    return 1;
  return (ll)C(u % MOD, v % MOD) * Lucas(u / MOD, v / MOD) % MOD;
}

int k, n, ans;
string s;

int main() {
  ios::sync_with_stdio(false);
  initInv();
  cin >> k >> s;
  n = s.length();
  for (int pref = 0; pref <= k; pref++) {
    ans = (ans + ((ll)powMod(26ll, pref) * powMod(25ll, k - pref) % MOD *
                  Lucas(n + k - 1 - pref, n - 1) % MOD)) %
          MOD;
  }
  cout << ans << endl;
  return 0;
}