alexjercan/bugnet huggingface dataset:
Problem p02632 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int N = 2222222;
vector<ll> fact(N);
const int mod = 1e9 + 7;

ll power(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 c(ll a, ll b) {
  return fact[a] * power(fact[b], mod - 2) % mod * power(fact[a - b], mod - 2) %
         mod;
}

void solve() {
  ll k;
  cin >> k;
  string s;
  cin >> s;
  ll n = s.length();
  vector<ll> pw25(k + 1, 1), pw26(k + 1, 1);
  for (ll i = 1; i <= k; i++) {
    pw25[i] = pw25[i - 1] * 25 % mod;
    pw26[i] = pw26[i - 1] * 26 % mod;
  }
  fact[0] = 1;
  for (ll i = 1; i < N; i++)
    fact[i] = 1ll * fact[i - 1] * i % mod;
  // for (ll i : fact)cout << i << ' '; cout << endl;
  ll ans = 0;
  for (ll i = 0; i <= k; i++) {
    ll cur = pw25[k - i] * pw26[i] % mod * c(n + k - i - 1, n - 1) % mod;
    ans += cur;
    ans %= mod;
  }
  cout << ans << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  // int t; cin >> t;
  // while (t--)
  solve();
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
ll power(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 c(ll a, ll b) {
  ll res = 1;
  for (ll i = 1; i <= b; i++)
    res = res * (a + 1 - i) % mod * power(i, mod - 2) % mod;
  return res;
}

void solve() {
  ll k;
  cin >> k;
  string s;
  cin >> s;
  ll n = s.length();
  vector<ll> pw25(k + 1, 1), pw26(k + 1, 1);
  for (ll i = 1; i <= k; i++) {
    pw25[i] = pw25[i - 1] * 25 % mod;
    pw26[i] = pw26[i - 1] * 26 % mod;
  }
  ll ans = 0;
  for (ll i = 0; i <= k; i++) {
    ll cur = k - i;
    ans +=
        pw25[k - i] * pw26[i] % mod * c(n + k - i - 1, min(n - 1, k - i)) % mod;
    ans %= mod;
  }
  cout << ans << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  // int t; cin >> t;
  // while (t--)
  solve();
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<long long> vll;
typedef vector<int> vi;

#define io ios_base::sync_with_stdio(false)
#define pb push_back
#define eb emplace_back
#define mod 1000000007
#define PI 2 * acos(0.0)

const int N = 2000005;
vi fac(N);

void fcalc() {
  fac[0] = 1;
  for (int i = 1; i < N; i++)
    fac[i] = (1LL * fac[i - 1] * i) % mod;
}

ll bigmod(ll x, ll po) {
  ll res = 1;
  while (po) {
    if (po & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    po >>= 1;
  }
  return res;
}

ll bin(int n, int i) {
  return (fac[n] * (bigmod(1LL * fac[n - i] * fac[i] % mod, mod - 2) % mod)) %
         mod;
  // return ((fac[n]*bigmod(fac[i], mod-2)%mod)%mod * bigmod(fac[n-i],
  // mod-2)%mod)%mod;
}

int32_t main() {
  io;
  fcalc();
  int n;
  string s;
  cin >> n >> s;
  int m = s.size();
  n += m;
  ll ans = 1, sub = 0;
  vi p(n + 1);
  p[0] = 1;
  for (int i = 1; i <= n; i++)
    p[i] = (p[i - 1] * 25LL) % mod;
  for (int i = 1; i <= n; i++)
    ans = (ans * 26) % mod;
  for (int i = 0; i < m; i++)
    sub = (sub + bin(n, i) * p[n - i] % mod) % mod;
  cout << (ans - sub + mod) % mod;
  return 0;
}


Error: WA

Fixed submission:

/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<long long> vll;
typedef vector<int> vi;

#define io ios_base::sync_with_stdio(false)
#define pb push_back
#define eb emplace_back
#define mod 1000000007
#define PI 2 * acos(0.0)

const int N = 1000005;
vi fac(N);

void fcalc() {
  fac[0] = 1;
  for (int i = 1; i < N; i++)
    fac[i] = (1LL * fac[i - 1] * i) % mod;
}

ll bigmod(ll x, ll po) {
  ll res = 1;
  while (po) {
    if (po & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    po >>= 1;
  }
  return res;
}

ll bin(int n, int i) {
  return (fac[n] * (bigmod(1LL * fac[n - i] * fac[i] % mod, mod - 2) % mod)) %
         mod;
  // return ((fac[n]*bigmod(fac[i], mod-2)%mod)%mod * bigmod(fac[n-i],
  // mod-2)%mod)%mod;
}

int32_t main() {
  io;
  fcalc();
  int n;
  string s;
  cin >> n >> s;
  int m = s.size();
  n += m;
  ll ans = 1, sub = 0;
  vi p(n + 1);
  p[0] = 1;
  for (int i = 1; i <= n; i++)
    p[i] = (p[i - 1] * 25LL) % mod;
  for (int i = 1; i <= n; i++)
    ans = (ans * 26) % mod;
  for (int i = 0; i < m; i++)
    sub = (sub + bin(n, i) * p[n - i] % mod) % mod;
  cout << (ans - sub + mod) % mod;
  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

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

#define DIV 1000000007

long long K;
string S;
long long memo[2000006];
long long downmemo[2000006];

long long modpow(long long ori, long long po) {
  long long res = 1;
  while (po > 0) {
    if (po & 1) {
      res *= ori;
      res %= DIV;
    }
    ori *= ori;
    ori %= DIV;
    po >>= 1;
  }
  return res;
}

int main() {
  cin >> K;
  cin >> S;

  long long Ssize = S.size();

  memo[0] = 1;
  downmemo[0] = 1;
  for (long long i = 1; i < 2000006; i++) {
    memo[i] = memo[i - 1] * i;
    memo[i] %= DIV;
    downmemo[i] = downmemo[i - 1] * modpow(i, DIV - 2);
    downmemo[i] %= DIV;
  }

  long long ans = 0;
  for (long long endidx = (long long)S.size() - 1; endidx < Ssize + K;
       endidx++) {
    long long tmp = 1;
    // enddx C S.size() - 1
    tmp *= memo[endidx];
    tmp %= DIV;
    tmp *= downmemo[endidx - (Ssize - 1)];
    tmp %= DIV;
    tmp *= downmemo[Ssize - 1];
    tmp %= DIV;

    // 25 ** (end + 1 - S.size())
    tmp *= modpow(25, endidx + 1 - Ssize);
    tmp %= DIV;

    // 26 ** (K + S.size() - endidx)
    tmp *= modpow(26, K + Ssize - endidx - 1);
    tmp %= DIV;

    ans += tmp;
    ans %= DIV;
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

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

#define DIV 1000000007

long long K;
string S;
long long memo[1000006];
long long downmemo[1000006];

long long modpow(long long ori, long long po) {
  long long res = 1;
  while (po > 0) {
    if (po & 1) {
      res *= ori;
      res %= DIV;
    }
    ori *= ori;
    ori %= DIV;
    po >>= 1;
  }
  return res;
}

int main() {
  cin >> K;
  cin >> S;

  long long Ssize = S.size();

  memo[0] = 1;
  downmemo[0] = 1;
  for (long long i = 1; i < 1000006; i++) {
    memo[i] = memo[i - 1] * i;
    memo[i] %= DIV;
    downmemo[i] = downmemo[i - 1] * modpow(i, DIV - 2);
    downmemo[i] %= DIV;
  }

  long long ans = 0;
  for (long long endidx = (long long)S.size() - 1; endidx < Ssize + K;
       endidx++) {
    long long tmp = 1;
    // enddx C S.size() - 1
    tmp *= memo[endidx];
    tmp %= DIV;
    tmp *= downmemo[endidx - (Ssize - 1)];
    tmp %= DIV;
    tmp *= downmemo[Ssize - 1];
    tmp %= DIV;

    // 25 ** (end + 1 - S.size())
    tmp *= modpow(25, endidx + 1 - Ssize);
    tmp %= DIV;

    // 26 ** (K + S.size() - endidx)
    tmp *= modpow(26, K + Ssize - endidx - 1);
    tmp %= DIV;

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

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define sz(a) ((int)a.size())
#define mp make_pair
#define fi first
#define se second

const int maxn = 2e6 + 5;

const int maxv = 1e9;
const int mod = 1e9 + 7;

int T, tc;
int n;
int a[maxn];
long long fact[maxn], inv[maxn];
string s;

long long power_mod(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b % 2)
      res = res * a % mod;
    a = a * a % mod;
    b /= 2ll;
  }
  return res;
}

long long C(int n, int k) { return fact[n] * inv[k] % mod * inv[n - k] % mod; }

int main() {
  //	freopen("inp.txt", "r", stdin);

  cin >> n;

  fact[0] = inv[0] = 1;
  for (int i = 1; i < maxn; i++) {
    fact[i] = fact[i - 1] * i % mod;
    inv[i] = power_mod(fact[i], mod - 2);
  }

  cin >> s;

  long long len = (long long)s.size();

  long long ans = 0;
  for (int i = 0; i <= n; i++) {
    int rem = n - i;
    //		cout << power_mod(25, rem) << ' ' << C(rem + len - 1, len - 1) << ' '
    //<< power_mod(26, i) << endl;
    (ans += power_mod(25, rem) * C(rem + len - 1, len - 1) % mod *
            power_mod(26, i) % mod) %= mod;
  }

  cout << ans;

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define sz(a) ((int)a.size())
#define mp make_pair
#define fi first
#define se second

const int maxn = 1e6 + 5;

const int maxv = 1e9;
const int mod = 1e9 + 7;

int T, tc;
int n;
int a[maxn];
long long fact[maxn], inv[maxn];
string s;

long long power_mod(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b % 2)
      res = res * a % mod;
    a = a * a % mod;
    b /= 2ll;
  }
  return res;
}

long long C(int n, int k) { return fact[n] * inv[k] % mod * inv[n - k] % mod; }

int main() {
  //	freopen("inp.txt", "r", stdin);

  cin >> n;

  fact[0] = inv[0] = 1;
  for (int i = 1; i < maxn; i++) {
    fact[i] = fact[i - 1] * i % mod;
    inv[i] = power_mod(fact[i], mod - 2);
  }

  cin >> s;

  long long len = (long long)s.size();

  long long ans = 0;
  for (int i = 0; i <= n; i++) {
    int rem = n - i;
    //		cout << power_mod(25, rem) << ' ' << C(rem + len - 1, len - 1) << ' '
    //<< power_mod(26, i) << endl;
    (ans += power_mod(25, rem) * C(rem + len - 1, len - 1) % mod *
            power_mod(26, i) % mod) %= mod;
  }

  cout << ans;

  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define INF (1ll << 60)
#define mod 1000000007
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

#define MAX 2000100
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 combi(ll n, ll k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
// mainに   COMinit();   を入れる

ll modpow(ll x, ll n) {
  ll ret = 1;
  while (n > 0) {
    if (n & 1)
      ret = ret * x % mod; // n の最下位bitが 1 ならば x^(2^i) をかける
    x = x * x % mod;
    n >>= 1; // n を1bit 左にずらす
  }
  return ret;
}

int main() {
  COMinit();
  ll k;
  string s;
  cin >> k >> s;
  ll n = s.size();

  ll minus = 0, ans = modpow(26ll, n + k);
  rep(i, n) {
    minus += (combi(n + k, i) * modpow(25ll, n + k - i)) % mod;
    minus %= mod;
  }

  ans -= minus;
  if (ans < 0)
    ans += mod;
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define INF (1ll << 60)
#define mod 1000000007
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

#define MAX 1000100
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 combi(ll n, ll k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
// mainに   COMinit();   を入れる

ll modpow(ll x, ll n) {
  ll ret = 1;
  while (n > 0) {
    if (n & 1)
      ret = ret * x % mod; // n の最下位bitが 1 ならば x^(2^i) をかける
    x = x * x % mod;
    n >>= 1; // n を1bit 左にずらす
  }
  return ret;
}

int main() {
  COMinit();
  ll k;
  string s;
  cin >> k >> s;
  ll n = s.size();

  ll minus = 0, ans = modpow(26ll, n + k);
  rep(i, n) {
    minus += (combi(n + k, i) * modpow(25ll, n + k - i)) % mod;
    minus %= mod;
  }

  ans -= minus;
  if (ans < 0)
    ans += mod;
  cout << ans << endl;
  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cassert>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

const int mod = (int)1e9 + 7;

// a^n % mod
long long modpow(long long a, long long n, long long mod) {
  long long ret = 1;

  while (n > 0) {
    if (n & 1) {
      ret = ret * a % mod;
    }

    a = a * a % mod;
    n >>= 1;
  }

  return ret;
}

// aの逆元
long long modinv(long long a, long long mod) {
  assert(gcd(a, mod) == 1);
  // TODO assert(modが素数)
  return modpow(a, mod - 2, mod);
}

class Combination {
public:
  vector<long long> fact, ifact;
  long long mod;

public:
  Combination(int n, int mod) : fact(n + 1), ifact(n + 1), mod(mod) {
    fact[0] = 1;
    for (int i = 1; i <= n; i++) {
      fact[i] = fact[i - 1] * i % mod;
    }
    ifact[n] = modinv(fact[n], mod);
    for (int i = n; i > 0; i--) {
      ifact[i - 1] = ifact[i] * i % mod;
    }
  };
  // ~Combination();

  // nCk
  long long comb(int n, int k) {
    assert(n >= 0);
    assert(0 <= k && k <= n);
    return fact[n] * ifact[k] % mod * ifact[n - k] % mod;
  }

  // nPk
  long long perm(int n, int k) {
    assert(n >= 0);
    assert(0 <= k && k <= n);
    return fact[n] * ifact[n - k] % mod;
  }

  // nHk n種類から重複を許してk個
  long long h(int n, int k) { return comb(n - k + 1, k); }
};

int main() {
  int k, n;
  string s;
  cin >> k >> s;

  n = s.size();
  Combination com(n + k, mod);

  long long sum = 0;
  for (int i = 0; i <= k; i++) {
    sum += modpow(25, i, mod) * modpow(26, k - i, mod) % mod *
           com.comb(i + n - 1, n - 1) % mod;
    sum %= mod;
  }

  cout << sum << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

const int mod = (int)1e9 + 7;

int main() {
  int k;
  string s;
  cin >> k >> s;

  int m = s.size();
  int n = k + s.size();
  // i文字[0,n]確定したときに、sの先頭j文字が存在する数
  vector<vector<long long>> dp(n + 1, vector<long long>(m + 1, 0));

  dp[0][0] = 1;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= m; j++) {
      auto x = dp[i][j];
      if (x == 0) {
        continue;
      }

      if (j < m) {
        dp[i + 1][j] += x * 25;
        dp[i + 1][j + 1] += x;
      } else {
        dp[i + 1][j] += x * 26;
      }
    }

    for (int j = 0; j <= m; j++) {
      dp[i + 1][j] %= mod;
    }
  }

  cout << dp[n][m] << endl;
  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int M = 2e6 + 5;
const int mod = 1e9 + 7;
int k, ans, f[M], inv[M];
string s;

int power(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1)
      res = (res * a) % mod;
    b >>= 1;
    a = (a * a) % mod;
  }
  return res % mod;
}

int modInv(int a) { return power(a, mod - 2); }

void precompute() {
  f[0] = f[1] = 1;
  for (int i = 2; i < M; i++)
    f[i] = (f[i - 1] * i) % mod;
  inv[M - 1] = modInv(f[M - 1]);
  for (int i = M - 2; i >= 0; i--)
    inv[i] = (inv[i + 1] * (i + 1)) % mod;
}

int nCr(int n, int r) {
  if (n < r)
    return 0;
  int res = f[n];
  res = (res * inv[r]) % mod;
  res = (res * inv[n - r]) % mod;
  return res % mod;
}

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  precompute();
  cin >> k >> s;
  int n = s.size();
  for (int i = 0; i <= k; i++) {
    int cur = nCr(n + k, n + i);
    cur = (cur * power(25, k - i)) % mod;
    ans = (ans + cur) % mod;
  }
  cout << ans << "\\n";
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int M = 1e6 + 5;
const int mod = 1e9 + 7;
int k, ans, f[M], inv[M];
string s;

int power(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1)
      res = (res * a) % mod;
    b >>= 1;
    a = (a * a) % mod;
  }
  return res % mod;
}

int modInv(int a) { return power(a, mod - 2); }

void precompute() {
  f[0] = f[1] = 1;
  for (int i = 2; i < M; i++)
    f[i] = (f[i - 1] * i) % mod;
  inv[M - 1] = modInv(f[M - 1]);
  for (int i = M - 2; i >= 0; i--)
    inv[i] = (inv[i + 1] * (i + 1)) % mod;
}

int nCr(int n, int r) {
  if (n < r)
    return 0;
  int res = f[n];
  res = (res * inv[r]) % mod;
  res = (res * inv[n - r]) % mod;
  return res % mod;
}

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  precompute();
  cin >> k >> s;
  int n = s.size();
  for (int i = 0; i <= k; i++) {
    int cur = nCr(n + k, n + i);
    cur = (cur * power(25, k - i)) % mod;
    ans = (ans + cur) % mod;
  }
  cout << ans << "\\n";
  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

const long long mod = 1e9 + 7ll;

long long modpower(long long a, long long b) {
  if (b == 0)
    return 1ll;
  long long x = modpower(a, b / 2ll);
  x = (x * x) % mod;
  if (b & 1)
    return (x * a) % mod;
  return (x % mod);
}

struct combination {
  vector<long long> fact, inv;
  combination(int sz) : fact(sz + 1), inv(sz + 1) {
    fact[0] = 1ll;
    inv[0] = 1ll;
    for (long long i = 1; i <= sz; ++i)
      fact[i] = (fact[i - 1] * i) % mod;
    inv[sz] = modpower(fact[sz], mod - 2ll);
    for (long long i = sz - 1; i >= 1; --i)
      inv[i] = (inv[i + 1] * (i + 1)) % mod;
  }
  long long choose(int n, int k) const {
    if (k < 0 || n < k)
      return 0;
    return ((((fact[n] * inv[k]) % mod) * inv[n - k]) % mod);
  }
};

const int MAX = 2e6 + 10;

combination comb(MAX);
int n, m;
string s;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  cin >> s;
  m = s.size();
  n += m;
  long long ans = 0ll;
  for (int i = m; i <= n; ++i) {
    long long x = modpower(26, n - i);
    long long a = comb.choose(i - 1, m - 1);
    long long y = (a * modpower(25, i - m)) % mod;
    x = (x * y) % mod;
    ans = (ans + x) % mod;
  }
  return cout << ans << "\\n", 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

const long long mod = 1e9 + 7ll;

long long modpower(long long a, long long b) {
  if (b == 0)
    return 1ll;
  long long x = modpower(a, b / 2ll);
  x = (x * x) % mod;
  if (b & 1)
    return (x * a) % mod;
  return (x % mod);
}

struct combination {
  vector<long long> fact, inv;
  combination(int sz) : fact(sz + 1), inv(sz + 1) {
    fact[0] = 1ll;
    inv[0] = 1ll;
    for (long long i = 1; i <= sz; ++i)
      fact[i] = (fact[i - 1] * i) % mod;
    inv[sz] = modpower(fact[sz], mod - 2ll);
    for (long long i = sz - 1; i >= 1; --i)
      inv[i] = (inv[i + 1] * (i + 1)) % mod;
  }
  long long choose(int n, int k) const {
    if (k < 0 || n < k)
      return 0;
    return ((((fact[n] * inv[k]) % mod) * inv[n - k]) % mod);
  }
};

const int MAX = 1e6 + 10;

combination comb(MAX);
int n, m;
string s;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  cin >> s;
  m = s.size();
  n += m;
  long long ans = 0ll;
  for (int i = m; i <= n; ++i) {
    long long x = modpower(26, n - i);
    long long a = comb.choose(i - 1, m - 1);
    long long y = (a * modpower(25, i - m)) % mod;
    x = (x * y) % mod;
    ans = (ans + x) % mod;
  }
  return cout << ans << "\\n", 0;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

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

#define N 2000000 // size of array
const ll MOD = 1e9 + 7;

ll fac[N], inv[N], finv[N];

void com_init() {
  fac[0] = 1;
  fac[1] = 1;
  finv[0] = 1;
  finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < N; 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 combination(int a, int b) {
  if (a < b)
    return 0;
  if (a < 0 || b < 0)
    return 0;
  return fac[a] * (finv[b] * finv[a - b] % MOD) % MOD;
}

int main() {
  int K;
  string S;
  cin >> K >> S;
  int n = S.size();
  ll p = 1, ans = 0;
  com_init();
  for (int i = 0; i < K; i++) {
    p *= 25;
    p %= MOD;
  }
  for (int i = 0; i <= K; i++) {
    ans += combination(n + K - i - 1, n - 1) * p % MOD;
    ans %= MOD;
    p *= 26;
    p %= MOD;
    p *= inv[25];
    p %= MOD;
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

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

#define N 1000001 // size of array
const ll MOD = 1e9 + 7;

ll fac[N], inv[N], finv[N];

void com_init() {
  fac[0] = 1;
  fac[1] = 1;
  finv[0] = 1;
  finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < N; 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 combination(int a, int b) {
  if (a < b)
    return 0;
  if (a < 0 || b < 0)
    return 0;
  return fac[a] * (finv[b] * finv[a - b] % MOD) % MOD;
}

int main() {
  int K;
  string S;
  cin >> K >> S;
  int n = S.size();
  ll p = 1, ans = 0;
  com_init();
  for (int i = 0; i < K; i++) {
    p *= 25;
    p %= MOD;
  }
  for (int i = 0; i <= K; i++) {
    ans += combination(n + K - i - 1, n - 1) * p % MOD;
    ans %= MOD;
    p *= 26;
    p %= MOD;
    p *= inv[25];
    p %= MOD;
  }
  cout << ans << endl;
  return 0;
}