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

#include <bits/stdc++.h>
using namespace std;
using Int = long long;
const Int MOD = 1000000007;
const Int MAX = 2000100;
Int fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = finv[0] = finv[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;
  }
}
Int COM(int n, int k) {
  if (n < k || n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
Int POW(Int n, Int m) {
  if (m == 0)
    return 1;
  if (m % 2 == 0)
    return POW(n * n % MOD, m / 2);
  return n * POW(n, m - 1) % MOD;
}
int main() {
  COMinit();
  int K;
  cin >> K;
  string S;
  cin >> S;
  int N = S.size();
  vector<Int> A(K + 1), B(K + 1);
  for (int i = 0; i <= K; i++) {
    A[i] = COM(N - 1 + i, i) * POW(25, i) % MOD;
  }
  for (int i = 0; i <= K; i++) {
    B[i] = A[i] + (i > 0 ? B[i - 1] * 26 : 0);
    B[i] %= MOD;
  }
  cout << B[K] << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using Int = long long;
const Int MOD = 1000000007;
const Int MAX = 1000100;
Int fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = finv[0] = finv[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;
  }
}
Int COM(int n, int k) {
  if (n < k || n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
Int POW(Int n, Int m) {
  if (m == 0)
    return 1;
  if (m % 2 == 0)
    return POW(n * n % MOD, m / 2);
  return n * POW(n, m - 1) % MOD;
}
int main() {
  COMinit();
  int K;
  cin >> K;
  string S;
  cin >> S;
  int N = S.size();
  vector<Int> A(K + 1), B(K + 1);
  for (int i = 0; i <= K; i++) {
    A[i] = COM(N - 1 + i, i) * POW(25, i) % MOD;
  }
  for (int i = 0; i <= K; i++) {
    B[i] = A[i] + (i > 0 ? B[i - 1] * 26 : 0);
    B[i] %= MOD;
  }
  cout << B[K] << endl;
  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

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

const int MAX = 2000000;
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 (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(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;
}

ll powmod(ll a, ll p) {
  ll res = 1;
  while (p > 0) {
    if (p & 1) {
      res *= a;
      res %= MOD;
    }
    a *= a;
    a %= MOD;
    p >>= 1;
  }
  return res;
}

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

Error: 0

Fixed submission:

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

const int MAX = 510000;
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 (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(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;
}

ll powmod(ll a, ll p) {
  ll res = 1;
  while (p > 0) {
    if (p & 1) {
      res *= a;
      res %= MOD;
    }
    a *= a;
    a %= MOD;
    p >>= 1;
  }
  return res;
}

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

#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 1000000007;
const int INF = 1e15;
using Graph = vector<vector<int>>;

// AのN乗(mod M)を高速に計算する(O(logN))
// Aの逆元を取る場合、modpow(A, MOD-2, 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 = 5100000;
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;
}

signed main() {
  COMinit();

  int K;
  cin >> K;
  string S;
  cin >> S;

  int N = (int)S.size();

  int ans = 0;
  for (int i = 0; i <= K; i++) {
    int now = 1;
    now = modpow(25, i, MOD);
    now %= MOD;
    now *= COM(i + N - 1, N - 1);
    now %= MOD;
    now *= modpow(26, K - i, MOD);
    now %= MOD;
    ans += now;
    ans %= MOD;
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 1000000007;
const int INF = 1e15;
using Graph = vector<vector<int>>;

// AのN乗(mod M)を高速に計算する(O(logN))
// Aの逆元を取る場合、modpow(A, MOD-2, 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 = 510000;
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;
}

signed main() {
  COMinit();

  int K;
  cin >> K;
  string S;
  cin >> S;

  int N = (int)S.size();

  int ans = 0;
  for (int i = 0; i <= K; i++) {
    int now = 1;
    now = modpow(25, i, MOD);
    now %= MOD;
    now *= COM(i + N - 1, N - 1);
    now %= MOD;
    now *= modpow(26, K - i, MOD);
    now %= MOD;
    ans += now;
    ans %= MOD;
  }
  cout << ans << endl;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;

const Int MOD = 1000000007;
const Int MAX = 2000010;

Int 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;
  }
}

Int 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 modpow(Int a, Int n) {
  Int res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return res;
}

int main() {

  COMinit(); // これをやっておくこと

  Int K;
  cin >> K;
  string S;
  cin >> S;
  Int N = S.size();

  Int sum = 0;

  for (Int i = N; i <= N + K; i++) {
    sum = (sum + (((COM(i - 1, N - 1) * modpow(25, i - N)) % MOD) *
                  modpow(26, N + K - i)) %
                     MOD) %
          MOD;
  }

  cout << sum << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;

const Int MOD = 1000000007;
const Int MAX = 1000010;

Int 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;
  }
}

Int 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 modpow(Int a, Int n) {
  Int res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return res;
}

int main() {

  COMinit(); // これをやっておくこと

  Int K;
  cin >> K;
  string S;
  cin >> S;
  Int N = S.size();

  Int sum = 0;

  for (Int i = N; i <= N + K; i++) {
    sum = (sum + (((COM(i - 1, N - 1) * modpow(25, i - N)) % MOD) *
                  modpow(26, N + K - i)) %
                     MOD) %
          MOD;
  }

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

#include <bits/stdc++.h>
#include <iomanip>
#include <numeric>
#define ll long long
#define intm INT_MAX
#define llm LLONG_MAX

using namespace std;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const ll mod = 1e9 + 7;
const int mxN = 2e6 + 9;

ll fact[mxN];

int mult(int a, int b) {
  ll a1 = ((ll)a) % MOD;
  ll b1 = ((ll)b) % MOD;
  return (int)((a1 * b1) % MOD);
}

int pow(int a, int b) {
  int res = 1;
  while (b > 0) {
    if (b % 2 == 1)
      res = mult(res, a);
    a = mult(a, a);
    b /= 2;
  }
  return res;
}

int inv(int n) { return pow(n, MOD - 2); }

int nCr(int n, int r) {
  if (n < r)
    return 0;
  return mult(fact[n], inv(mult(fact[r], fact[n - r])));
}

int subt(int a, int b) { return (((a - b) % MOD) + MOD) % MOD; }

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  n = 2000009;
  fact[0] = fact[1] = 1;
  for (int i = 2; i <= n; i++)
    fact[i] = (fact[i - 1] * ((ll)i)) % MOD;
  ll ans = 0;
  int N, K;
  string s;
  cin >> N >> s;
  K = s.length();
  swap(N, K);
  // cout << N << " " << K << endl;
  for (int i = N; i <= N + K; ++i) {
    ll tmp = ((ll)pow(25, N + K - i));
    ll tmp2 = nCr(N + K, i);
    ll tmp3 = ((tmp % MOD) * (tmp2 % MOD)) % MOD;
    //
    // cout << tmp << " " << tmp2 << " " << tmp3 << endl;
    //
    ans = (ans + (tmp3 % MOD)) % MOD;
  }
  cout << ans;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#include <iomanip>
#include <numeric>
#define ll long long
#define intm INT_MAX
#define llm LLONG_MAX

using namespace std;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const ll mod = 1e9 + 7;
const int mxN = 1e6 + 9;

ll fact[mxN];

int mult(int a, int b) {
  ll a1 = ((ll)a) % MOD;
  ll b1 = ((ll)b) % MOD;
  return (int)((a1 * b1) % MOD);
}

int pow(int a, int b) {
  int res = 1;
  while (b > 0) {
    if (b % 2 == 1)
      res = mult(res, a);
    a = mult(a, a);
    b /= 2;
  }
  return res;
}

int inv(int n) { return pow(n, MOD - 2); }

int nCr(int n, int r) {
  if (n < r)
    return 0;
  return mult(fact[n], inv(mult(fact[r], fact[n - r])));
}

int subt(int a, int b) { return (((a - b) % MOD) + MOD) % MOD; }

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  n = 1000009;
  fact[0] = fact[1] = 1;
  for (ll i = 2; i <= n; i++)
    fact[i] = (fact[i - 1] * i) % MOD;
  ll ans = 0;
  int N, K;
  string s;
  cin >> N >> s;
  K = s.length();
  swap(N, K);
  // cout << N << " " << K << endl;
  for (int i = N; i <= N + K; ++i) {
    ll tmp = ((ll)pow(25, N + K - i));
    ll tmp2 = nCr(N + K, i);
    ll tmp3 = ((tmp % MOD) * (tmp2 % MOD)) % MOD;
    //
    // cout << tmp << " " << tmp2 << " " << tmp3 << endl;
    //
    ans = (ans + (tmp3 % MOD)) % MOD;
  }
  cout << ans;
}
Problem p02632 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
const ll MOD = 1000000007; // 998244353;
const ll SIZE = 26;
ll power(ll x, ll n, ll M = MOD) {
  ll res = 1;
  if (n > 0) {
    res = power(x, n / 2, M);
    if (n % 2 == 0)
      res = (res * res) % M;
    else
      res = (((res * res) % M) * x) % M;
  }
  return res;
}
ll mod_inv(ll n, ll M = MOD) { return power(n, M - 2, M); }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll k;
  cin >> k;
  string s;
  cin >> s;
  ll size_s = s.size();
  vector<ll> power25, power26;
  power25.push_back(1);
  power26.push_back(1);
  rep(i, 2000000) {
    power25.push_back(power25[i] * (SIZE - 1));
    power26.push_back(power26[i] * SIZE);
    power25[i + 1] %= MOD;
    power26[i + 1] %= MOD;
  }
  vector<ll> nCk;
  nCk.push_back(1);
  rep(i, k) {
    nCk.push_back((nCk[i] * (size_s + i) % MOD) * mod_inv(i + 1));
    nCk[i + 1] %= MOD;
  }
  ll ans = 0;
  for (ll i = size_s; i <= size_s + k; i++) {
    ll y = nCk[i - size_s] * power25[i - size_s];
    y %= MOD;
    y *= power26[size_s + k - i];
    y %= MOD;
    ans += y;
    ans %= MOD;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
const ll MOD = 1000000007; // 998244353;
const ll SIZE = 26;
ll dp[1000001];
ll power(ll x, ll n, ll M = MOD) {
  ll res = 1;
  if (n > 0) {
    res = power(x, n / 2, M);
    if (n % 2 == 0)
      res = (res * res) % M;
    else
      res = (((res * res) % M) * x) % M;
  }
  return res;
}
ll mod_inv(ll n, ll M) { return power(n, M - 2, M); }

struct Combination {
  ll n, mod;
  vector<ll> factorial;
  Combination(ll n, ll mod) : n(n), mod(mod) { init(); }
  void init() {
    factorial.push_back(1);
    for (int i = 1; i <= n; i++) {
      factorial.push_back(factorial[i - 1] * i);
      factorial[i] %= mod;
    }
  }
  ll aCb(ll a, ll b) {
    if (a < b)
      return 0;
    ll y = factorial[a] * mod_inv(factorial[b], mod);
    y %= mod;
    y *= mod_inv(factorial[a - b], mod);
    y %= mod;
    return y;
  }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll k;
  cin >> k;
  string s;
  cin >> s;
  Combination c(2000000, MOD);
  ll ans = 0;
  for (ll i = s.size(); i <= s.size() + k; i++) {
    ll y = c.aCb(i - 1, s.size() - 1) * power(SIZE - 1, i - s.size());
    y %= MOD;
    y *= power(SIZE, s.size() + k - i);
    y %= MOD;
    ans += y;
    ans %= MOD;
  }
  cout << ans << endl;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7;
const int sz = 2e6 + 1;

int k;
string s;
ll fact[sz], inv_fact[sz];

ll bpow(ll x, ll p) {
  if (p == 0)
    return 1;
  if (p % 2)
    return (x * bpow(x, p - 1)) % mod;
  else {
    ll b = bpow(x, p / 2);
    return (b * b) % mod;
  }
}

ll inv(ll x) { return bpow(x, mod - 2); }

void calc_fact() {
  fact[0] = 1;
  inv_fact[0] = 1;
  for (int i = 1; i < sz; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
    inv_fact[i] = inv(fact[i]);
  }
}

ll cnk(ll nn, ll kk) {
  return fact[nn] * inv_fact[nn - kk] % mod * inv_fact[kk] % mod;
}

void solve() {
  cin >> k >> s;
  int n = s.size();
  calc_fact();
  ll ans = 0;
  for (int i = 0; i <= k; i++) {
    ans +=
        cnk(n + k - i - 1, n - 1) * bpow(25, k - i) % mod * bpow(26, i) % mod;
    ans %= mod;
  }
  cout << ans;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#if defined(_DEBUG)
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int q = 1;
  // cin >> q;
  for (; q > 0; q--) {
    solve();
    cout << endl;
  }
}

Error: 0

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7;
const int sz = 1e6 + 1;

int k;
string s;
ll fact[sz], inv_fact[sz];

ll bpow(ll x, ll p) {
  if (p == 0)
    return 1;
  if (p % 2)
    return (x * bpow(x, p - 1)) % mod;
  else {
    ll b = bpow(x, p / 2);
    return (b * b) % mod;
  }
}

ll inv(ll x) { return bpow(x, mod - 2); }

void calc_fact() {
  fact[0] = 1;
  inv_fact[0] = 1;
  for (int i = 1; i < sz; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
    inv_fact[i] = inv(fact[i]);
  }
}

ll cnk(ll nn, ll kk) {
  return fact[nn] * inv_fact[nn - kk] % mod * inv_fact[kk] % mod;
}

void solve() {
  cin >> k >> s;
  int n = s.size();
  calc_fact();
  ll ans = 0;
  for (int i = 0; i <= k; i++) {
    ans +=
        cnk(n + k - i - 1, n - 1) * bpow(25, k - i) % mod * bpow(26, i) % mod;
    ans %= mod;
  }
  cout << ans;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#if defined(_DEBUG)
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int q = 1;
  // cin >> q;
  for (; q > 0; q--) {
    solve();
    cout << endl;
  }
}
Problem p02632 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
long long p = 1000000007;
long long k, n, q, a;
char s[1000001];
long long inv[2000001];
long long rui(long long rui_a, long long rui_b) {
  if (rui_b == 0)
    return 1;
  if (rui_b == 1)
    return rui_a % p;
  long long rui_c;
  rui_c = rui(rui_a, rui_b / 2);
  rui_c = rui_c * rui_c % p;
  if (rui_b % 2) {
    return rui_c * rui_a % p;
  }
  return rui_c;
}
void makeinv(void) {
  long long arraynumber = sizeof inv / sizeof inv[0];
  inv[1] = 1;
  for (int invcount = 2; invcount < arraynumber; invcount++) {
    inv[invcount] = p - inv[p % invcount] * (p / invcount) % p;
  }
}
int main() {
  scanf("%lld", &k);
  scanf(" %s", s);
  makeinv();
  while (s[n] != NULL)
    n++;
  q = 1;
  for (int i = 0; i < n + k; i++) {
    q *= 25;
    q %= p;
  }
  for (long long i = 1; i <= k + n; i++) {
    q *= inv[25];
    q %= p;
    q *= (n + k + 1 - i);
    q %= p;
    q *= inv[i];
    q %= p;
    if (i >= n)
      a += q;
    a %= p;
  }
  printf("%lld\\n", a);
}

Error: TLE

Fixed submission:

#include <stdio.h>
long long p = 1000000007;
long long k, n, q, a;
char s[1000001];
long long rui(long long rui_a, long long rui_b) {
  if (rui_b == 0)
    return 1;
  if (rui_b == 1)
    return rui_a % p;
  long long rui_c;
  rui_c = rui(rui_a, rui_b / 2);
  rui_c = rui_c * rui_c % p;
  if (rui_b % 2) {
    return rui_c * rui_a % p;
  }
  return rui_c;
}
int main() {
  scanf("%lld", &k);
  scanf(" %s", s);
  while (s[n] != NULL)
    n++;
  q = 1;
  for (int i = 0; i < n + k; i++) {
    q *= 25;
    q %= p;
  }
  for (long long i = 1; i <= k + n; i++) {
    q *= rui(25, p - 2);
    q %= p;
    q *= (n + k + 1 - i);
    q %= p;
    q *= rui(i, p - 2);
    q %= p;
    if (i >= n)
      a += q;
    a %= p;
  }
  printf("%lld\\n", a);
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int MAX = 3000000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
// invの要素にはiの逆元が格納されている
// 前処理
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;                 // i!(mod MOD)を計算
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; // iの逆元を計算
    finv[i] = finv[i - 1] * inv[i] % MOD; // i!(mod 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; // nCk = n!/(k!*(n-k)!)を計算
}
long long mod_pow(long long x, long long y) {
  if (y == 0)
    return 1;
  long long res = 1;
  while (y != 0) {
    if (y & 1)
      res = res * x % MOD;
    x = x * x % MOD;
    y >>= 1;
  }
  return res;
}
int main() {
  COMinit();
  long long K;
  cin >> K;
  string S;
  cin >> S;
  long long siz = S.size();
  long long res = 0;
  for (int i = 0; i < siz; i++) {
    res = res + COM(siz + K, i) * mod_pow(25, siz + K - i) % MOD;
    res %= MOD;
  }
  long long ans = (mod_pow(26, K + siz) - res + MOD) % MOD;
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int MAX = 1000010;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
// invの要素にはiの逆元が格納されている
// 前処理
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;                 // i!(mod MOD)を計算
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; // iの逆元を計算
    finv[i] = finv[i - 1] * inv[i] % MOD; // i!(mod 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; // nCk = n!/(k!*(n-k)!)を計算
}
long long mod_pow(long long x, long long y) {
  if (y == 0)
    return 1;
  long long res = 1;
  while (y != 0) {
    if (y & 1)
      res = res * x % MOD;
    x = x * x % MOD;
    y >>= 1;
  }
  return res;
}
int main() {
  COMinit();
  long long K;
  cin >> K;
  string S;
  cin >> S;
  long long siz = S.size();
  long long res = 0;
  for (int i = 0; i < siz; i++) {
    res = res + COM(siz + K, i) * mod_pow(25, siz + K - i) % MOD;
    res %= MOD;
  }
  long long ans = (mod_pow(26, siz + K) - res + MOD) % MOD;
  cout << ans << endl;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define pb push_back
#define fi first
#define se second
#define eb emplace_back

using namespace std;

typedef pair<int, int> ii;
typedef long long ll;
const int N = 2000007, inf = 0x3f3f3f3f;

const int M = 1e9 + 7;

ll fat[N];
ll fast_pow(ll a, ll b) {
  ll ans = 1;

  while (b) {
    if (b & 1)
      ans = a * ans % M;
    b >>= 1;
    a = a * a % M;
  }
  return ans;
}

ll nchoosek(ll n, ll k) {
  ll den = fat[n - k] * fat[k] % M;
  return fat[n] * fast_pow(den, M - 2) % M;
}

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

  fat[0] = 1;
  for (int i = 1; i < N; ++i)
    fat[i] = fat[i - 1] * i % M;

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

  ll sum = 0;
  for (int x = 0; x <= k; ++x) {
    sum += (fast_pow(25, k - x) * fast_pow(26, x) % M) *
           nchoosek(n + k - x - 1, n - 1) % M;
    if (sum >= M)
      sum -= M;
  }
  cout << sum << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define pb push_back
#define fi first
#define se second
#define eb emplace_back

using namespace std;

typedef pair<int, int> ii;
typedef long long ll;
const int N = 1000007, inf = 0x3f3f3f3f;

const int M = 1e9 + 7;

ll fat[N];
ll fast_pow(ll a, ll b) {
  ll ans = 1;

  while (b) {
    if (b & 1)
      ans = a * ans % M;
    b >>= 1;
    a = a * a % M;
  }
  return ans;
}

ll nchoosek(ll n, ll k) {
  ll den = fat[n - k] * fat[k] % M;
  return fat[n] * fast_pow(den, M - 2) % M;
}

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

  fat[0] = 1;
  for (int i = 1; i < N; ++i)
    fat[i] = fat[i - 1] * i % M;

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

  ll sum = 0;
  for (int x = 0; x <= k; ++x) {
    sum += (fast_pow(25, k - x) * fast_pow(26, x) % M) *
           nchoosek(n + k - x - 1, n - 1) % M;
    if (sum >= M)
      sum -= M;
  }
  cout << sum << endl;
}