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

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

const long long MOD = 1000000007;
using ll = long long;

const int MAX = 2010000;

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

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

void solve(long long K, std::string S) {
  ll ans = 0;
  COMinit();
  for (int i = 0; i <= K; i++) {
    ans += (COM(K - i + (int)S.size() - 1, (int)S.size() - 1) *
            modpow(26, i, MOD)) %
           MOD * modpow(25, K - i, MOD);
    ans %= MOD;
  }
  cout << ans << endl;
}

int main() {
  long long K;
  scanf("%lld", &K);
  std::string S;
  std::cin >> S;
  solve(K, S);
  return 0;
}


Error: 0

Fixed submission:

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

const long long MOD = 1000000007;
using ll = long long;

const int MAX = 1010000;

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

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

void solve(long long K, std::string S) {
  ll ans = 0;
  COMinit();
  for (int i = 0; i <= K; i++) {
    ans += (COM(K - i + (int)S.size() - 1, (int)S.size() - 1) *
            modpow(26, i, MOD)) %
           MOD * modpow(25, K - i, MOD);
    ans %= MOD;
  }
  cout << ans << endl;
}

int main() {
  long long K;
  scanf("%lld", &K);
  std::string S;
  std::cin >> S;
  solve(K, S);
  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iomanip> // setprecisionを使用するのに必要 cout << fixed << setprecision(15) << p でpを小数点以下15桁表示
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
#define REPD(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) REPD(i, 0, n)
#define DIV0 1000000007
typedef long long ll;
#define fin(ans) cout << (ans) << '\\n'
const ll M = 1000000007;

vector<ll> fac(2000001); // n!(mod M)
vector<ll> ifac(2000001); // k!^{M-1} (mod M) //法Mの元でのkの逆元を求める

ll mpow(ll x, ll n) { // x^n (mod M)
  ll ans = 1;
  while (n != 0) {
    // したの桁から見ていって、その桁にあったら*xして、nをシフトするにつれxを二乗する
    if (n & 1)
      ans = ans * x % M;
    x = x * x % M;
    n = n >> 1;
  }
  return ans;
}

// aCbを求める
ll comb(ll a, ll b) {
  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() {
  int k, n;
  string s;
  cin >> k >> s;
  n = s.size();
  ll ans = 0;

  // 最初に階乗を求めておく
  fac[0] = 1;
  ifac[0] = 1;
  for (ll i = 0; i < 2000000; i++) {
    fac[i + 1] = fac[i] * (i + 1) % M;
    ifac[i + 1] = ifac[i] * mpow(i + 1, M - 2) % M; // 逆元を求めている
  }

  for (int i = 0; i <= k; ++i) {
    //
    ll now = mpow(26, k - i);
    now = now * mpow(25, i) % M;
    now = now * comb(i + n - 1, n - 1) % M;
    ans = (ans + now) % M;
  }
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iomanip> // setprecisionを使用するのに必要 cout << fixed << setprecision(15) << p でpを小数点以下15桁表示
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
#define REPD(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) REPD(i, 0, n)
#define DIV0 1000000007
typedef long long ll;
#define fin(ans) cout << (ans) << '\\n'
const ll M = 1000000007;

vector<ll> fac(1000001); // n!(mod M)
vector<ll> ifac(1000001); // k!^{M-1} (mod M) //法Mの元でのkの逆元を求める

ll mpow(ll x, ll n) { // x^n (mod M)
  ll ans = 1;
  while (n != 0) {
    // したの桁から見ていって、その桁にあったら*xして、nをシフトするにつれxを二乗する
    if (n & 1)
      ans = ans * x % M;
    x = x * x % M;
    n = n >> 1;
  }
  return ans;
}

// aCbを求める
ll comb(ll a, ll b) {
  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() {
  int k, n;
  string s;
  cin >> k >> s;
  n = s.size();
  ll ans = 0;

  // 最初に階乗を求めておく
  fac[0] = 1;
  ifac[0] = 1;
  for (ll i = 0; i < 1000000; i++) {
    fac[i + 1] = fac[i] * (i + 1) % M;
    ifac[i + 1] = ifac[i] * mpow(i + 1, M - 2) % M; // 逆元を求めている
  }

  for (int i = 0; i <= k; ++i) {
    //
    ll now = mpow(26, k - i);
    now = now * mpow(25, i) % M;
    now = now * comb(i + n - 1, n - 1) % M;
    ans = (ans + now) % M;
  }
  cout << ans << endl;
  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

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

// #define int long long
// signed main(){
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int k;
  string s;
  cin >> k >> s;

  COMinit();

  ll ts[k + 1];
  ll tf[k + 1];
  ts[0] = 1;
  tf[0] = 1;
  for (int i = 0; i < k; i++) {
    ts[i + 1] = (ts[i] * 26) % MOD;
    tf[i + 1] = (tf[i] * 25) % MOD;
  }

  ll ans = 0;
  int n = s.size() + k;

  for (int i = 0; i <= k; i++) {
    ll add = ((ts[i] * tf[k - i]) % MOD) * COM(n - i - 1, n - k - 1);
    ans += (add % MOD);
  }
  cout << ans % MOD << "\\n";
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

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

// #define int long long
// signed main(){
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int k;
  string s;
  cin >> k >> s;

  COMinit();

  ll ts[k + 1];
  ll tf[k + 1];
  ts[0] = 1;
  tf[0] = 1;
  for (int i = 0; i < k; i++) {
    ts[i + 1] = (ts[i] * 26) % MOD;
    tf[i + 1] = (tf[i] * 25) % MOD;
  }

  ll ans = 0;
  int n = s.size() + k;

  for (int i = 0; i <= k; i++) {
    ll add = ((ts[i] * tf[k - i]) % MOD) * COM(n - i - 1, n - k - 1);
    ans += (add % MOD);
  }
  cout << ans % MOD << "\\n";
  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

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

const int MOD = 1e9 + 7;
const int MAX_N = 2e6 + 10;
int K;
string S;

ll fact[MAX_N];
ll invf[MAX_N];

ll powmod(ll x, int y) {
  ll res = 1;
  while (y) {
    if (y & 1)
      (res *= x) %= MOD;
    (x *= x) %= MOD;
    y >>= 1;
  }
  return res;
}

ll nCk(int n, int k) {
  if (k < 0 || k > n)
    return 0;
  return (((fact[n] * invf[n - k]) % MOD) * invf[k]) % MOD;
}

void solve() {
  fact[0] = 1;
  for (int i = 1; i < MAX_N; ++i)
    fact[i] = 1LL * i * fact[i - 1] % MOD;
  invf[MAX_N - 1] = powmod(fact[MAX_N - 1], MOD - 2);
  for (int i = MAX_N - 2; i >= 0; --i)
    invf[i] = 1LL * invf[i + 1] * (i + 1) % MOD;

  ll res = 0;
  const int n = S.length();
  for (int len = 0; len < n; ++len) {
    (res += 1LL * nCk(n + K, len) * powmod(25, n + K - len) % MOD) %= MOD;
  }
  ll ans = (powmod(26, n + K) - res + MOD) % MOD;
  cout << ans;
}

int main() {
  cin >> K >> S;
  solve();
  return 0;
}

Error: WA

Fixed submission:

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

const int MOD = 1e9 + 7;
const int MAX_N = 1e6 + 10;
int K;
string S;

ll fact[MAX_N];
ll invf[MAX_N];

ll powmod(ll x, int y) {
  ll res = 1;
  while (y) {
    if (y & 1)
      (res *= x) %= MOD;
    (x *= x) %= MOD;
    y >>= 1;
  }
  return res;
}

ll nCk(int n, int k) {
  if (k < 0 || k > n)
    return 0;
  return (((fact[n] * invf[n - k]) % MOD) * invf[k]) % MOD;
}

void solve() {
  fact[0] = 1;
  for (int i = 1; i < MAX_N; ++i)
    fact[i] = 1LL * i * fact[i - 1] % MOD;
  invf[MAX_N - 1] = powmod(fact[MAX_N - 1], MOD - 2);
  for (int i = MAX_N - 2; i >= 0; --i)
    invf[i] = 1LL * invf[i + 1] * (i + 1) % MOD;

  ll res = 0;
  const int n = S.length();
  for (int len = 0; len < n; ++len) {
    (res += 1LL * nCk(n + K, len) * powmod(25, n + K - len) % MOD) %= MOD;
  }
  ll ans = (powmod(26, n + K) - res + MOD) % MOD;
  cout << ans;
}

int main() {
  cin >> K >> S;
  solve();
  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <fstream>
#include <iostream>

// BE CAREFUL WITH HASH TABLE & UNORDERED MAP
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;

#define MOD 1000000007
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, b) FOR(i, 0, b)
#define RFO(i, a, b) for (int i = (b - 1); i >= (a); i--)
#define RF0(i, b) RFO(i, 0, b)
#define lli long long int
#define pii pair<int, int>
#define add(a, b) ((int)(((lli)(a) + (b)) % MOD))
#define mul(a, b) ((int)(((lli)(a) * (b)) % MOD))
#define PB emplace_back

// ifstream cin ("cinput.in");
// ofstream cout ("coutput.out");

int K;
string S;
int fact[2000001];

int modexp(int a, int e) {
  int ans = 1;
  int cur = a;
  while (e) {
    if (e & 1) {
      ans = mul(ans, cur);
      e--;
    }
    e /= 2;
    cur = mul(cur, cur);
  }
  return ans;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> K >> S;
  fact[0] = 1;
  FOR(i, 1, K + S.size() + 1) fact[i] = mul(fact[i - 1], i);
  int ans = 0;
  FOR(av, S.size(), K + S.size() + 1) {
    int nck =
        mul(fact[av - 1],
            modexp(mul(fact[S.size() - 1], fact[av - S.size()]), MOD - 2));
    int p1 = modexp(25, av - S.size());
    int p2 = modexp(26, K + S.size() - av);
    ans = add(ans, mul(mul(p1, p2), nck));
  }
  cout << ans << '\\n';
}

Error: 0

Fixed submission:

#include <fstream>
#include <iostream>

// BE CAREFUL WITH HASH TABLE & UNORDERED MAP
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;

#define MOD 1000000007
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, b) FOR(i, 0, b)
#define RFO(i, a, b) for (int i = (b - 1); i >= (a); i--)
#define RF0(i, b) RFO(i, 0, b)
#define lli long long int
#define pii pair<int, int>
#define add(a, b) ((int)(((lli)(a) + (b)) % MOD))
#define mul(a, b) ((int)(((lli)(a) * (b)) % MOD))
#define PB emplace_back

// ifstream cin ("cinput.in");
// ofstream cout ("coutput.out");

int K;
string S;
int fact[2000000];

int modexp(int a, int e) {
  int ans = 1;
  int cur = a;
  while (e) {
    if (e & 1) {
      ans = mul(ans, cur);
      e--;
    }
    e /= 2;
    cur = mul(cur, cur);
  }
  return ans;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> K >> S;
  fact[0] = 1;
  FOR(i, 1, K + S.size() + 1) fact[i] = mul(fact[i - 1], i);
  int ans = 0;
  FOR(av, S.size(), K + S.size() + 1) {
    int nck =
        mul(fact[av - 1],
            modexp(mul(fact[S.size() - 1], fact[av - S.size()]), MOD - 2));
    int p1 = modexp(25, av - S.size());
    int p2 = modexp(26, K + S.size() - av);
    ans = add(ans, mul(mul(p1, p2), nck));
  }
  cout << ans << '\\n';
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

// This code was made by Chinese_zjc_
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define int long long
#define INF 0x3fffffffffffffff
#define MOD 1000000007
using namespace std;
const double PI = acos(-1);
int k, l, r, d[4000001], p[4000001], ans;
string s;
int ksm(int a, int b) {
  int tmp = 1;
  while (b) {
    if (b & 1) {
      tmp = (tmp * a) % MOD;
    }
    a = (a * a) % MOD;
    b >>= 1;
  }
  return tmp;
}
int C(int a, int b) { return d[b] * p[a] % MOD * p[b - a] % MOD; }
const int _25 = ksm(25, MOD - 2);
signed main() {
  ios::sync_with_stdio(false);
  cin >> k >> s;
  d[0] = p[0] = 1;
  for (int i = 1; i <= 4000000; ++i) {
    d[i] = (d[i - 1] * i) % MOD;
    p[i] = ksm(d[i], MOD - 2);
  }
  l = ksm(25, k + 1);
  r = ksm(26, MOD - 2);
  for (int i = 0; i <= k; ++i) {
    l = (l * _25) % MOD;
    r = (r * 26) % MOD;
    ans =
        (ans + l * r % MOD * C(k - i, k - i + (int)s.length() - 1) % MOD) % MOD;
  }
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

// This code was made by Chinese_zjc_
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define int long long
#define INF 0x3fffffffffffffff
#define MOD 1000000007
using namespace std;
const double PI = acos(-1);
int k, l = 1, r, d[1000001], p[1000001], ans;
string s;
int ksm(int a, int b) {
  int tmp = 1;
  while (b) {
    if (b & 1) {
      tmp = (tmp * a) % MOD;
    }
    a = (a * a) % MOD;
    b >>= 1;
  }
  return tmp;
}
int C(int a, int b) { return a != 0 ? d[b] * p[a] % MOD * p[b - a] % MOD : 1; }
const int _25 = ksm(25, MOD - 2);
signed main() {
  ios::sync_with_stdio(false);
  cin >> k >> s;
  d[0] = 1;
  for (int i = 1; i <= k + (int)s.length(); ++i) {
    d[i] = (d[i - 1] * i) % MOD;
    p[i] = ksm(d[i], MOD - 2);
  }
  l = ksm(25, k + 1);
  r = ksm(26, MOD - 2);
  for (int i = 0; i <= k; ++i) {
    l = (l * _25) % MOD;
    r = (r * 26) % MOD;
    ans = (ans + l * r % MOD * C(k - i, k - i + s.length() - 1)) % MOD;
  }
  cout << ans << endl;
  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
long long mod = 1000000007;
long long modpow(long long m, long long n) {
  long long res = 1;
  if (n > 0) {
    res = modpow(m, n / 2);
    if (n % 2 == 0) {
      res = (res * res) % mod;
    } else {
      res = (((res * res) % mod) * m) % mod;
    }
  }
  return res;
}

int main() {
  ll k;
  cin >> k;
  string s;
  cin >> s;
  ll size = 0;
  size = s.size();
  ll res = 0;
  vector<ll> fac(2000001);
  fac[0] = 1;
  for (int i = 1; i < 2000001; i++) {
    fac[i] = fac[i - 1] * i;
    fac[i] %= mod;
  }
  ll sizecon = 0;
  sizecon = modpow(fac[size - 1], mod - 2);
  for (int i = size - 1; i <= k + size - 1; i++) {
    ll now = 1;
    now *= fac[i];
    now *= sizecon, now %= mod;
    now *= modpow(fac[i - size + 1], mod - 2), now %= mod;
    now *= modpow(25, i + 1 - size), now %= mod;
    now *= modpow(26, size + k - i - 1), now %= mod;
    res += now;
    // cout << i << " " << now << endl;
    res %= mod;
  }
  cout << res << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
long long mod = 1000000007;
long long modpow(long long m, long long n) {
  long long res = 1;
  if (n > 0) {
    res = modpow(m, n / 2);
    if (n % 2 == 0) {
      res = (res * res) % mod;
    } else {
      res = (((res * res) % mod) * m) % mod;
    }
  }
  return res;
}

int main() {
  ll k;
  cin >> k;
  string s;
  cin >> s;
  ll size = 0;
  size = s.size();
  ll res = 0;
  vector<ll> fac(2000001);
  fac[0] = 1;
  for (int i = 1; i < 2000001; i++) {
    fac[i] = fac[i - 1] * i;
    fac[i] %= mod;
  }
  for (int i = size - 1; i <= k + size - 1; i++) {
    ll now = 1;
    now *= fac[i];
    now *= modpow(fac[size - 1], mod - 2), now %= mod;
    now *= modpow(fac[i - size + 1], mod - 2), now %= mod;
    now *= modpow(25, i + 1 - size), now %= mod;
    now *= modpow(26, size + k - i - 1), now %= mod;
    res += now;
    // cout << i << " " << now << endl;
    res %= mod;
  }
  cout << res << endl;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

// abc171_f.cpp
// Sun Jun 21 20:54:45 2020

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

using namespace std;
using ll = long long;
typedef pair<int, int> P;

// nCk を1000000007で割った余りの計算。
const ll MAX = 2000010;
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;
  }
}

// 二項係数計算
ll 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;
}

ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) {
    return 1;
  }
  ll res = mod_pow(x * x % mod, n / 2, mod);
  if (n & 1) {
    res = res * x % mod; // nが奇数の場合はxを余分にかける。
  }
  return res;
}

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

  ll length = (ll)s.length();

  COMinit();
  ll ans = 0;
  for (ll i = length - 1; i < length + k; i++) {
    ll tmp = COM(i, length - 1);
    tmp = tmp * mod_pow(25LL, i - length + 1, MOD) % MOD;
    tmp = tmp * mod_pow(26LL, length + k - i - 1, MOD) % MOD;
    ans = (ans + tmp) % MOD;
  }

  cout << ans << endl;
  //	printf("%.4f\\n",ans);
}

Error: 0

Fixed submission:

// abc171_f.cpp
// Sun Jun 21 20:54:45 2020

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

using namespace std;
using ll = long long;
typedef pair<int, int> P;

// nCk を1000000007で割った余りの計算。
const ll MAX = 1000010;
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;
  }
}

// 二項係数計算
ll 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 mod_pow(ll x, ll n, ll mod) {
  if (n == 0) {
    return 1;
  }
  ll res = mod_pow(x * x % mod, n / 2, mod);
  if (n & 1) {
    res = res * x % mod; // nが奇数の場合はxを余分にかける。
  }
  return res;
}

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

  ll length = (ll)s.length();

  COMinit();
  ll ans = 0;
  for (ll i = length - 1; i < length + k; i++) {
    ll tmp = COM(i, length - 1);
    tmp = tmp * mod_pow(25LL, i - length + 1, MOD) % MOD;
    tmp = tmp * mod_pow(26LL, length + k - i - 1, MOD) % MOD;
    ans = (ans + tmp) % MOD;
  }

  cout << ans << endl;
  //	printf("%.4f\\n",ans);
}
Problem p02632 (C++) — buggy submission, verdict: Time Limit Exceeded

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

typedef unsigned long long ull;
typedef __uint128_t L;
struct FastMod {
  ull b, m;
  FastMod(ull b) : b(b), m(ull((L(1) << 64) / b)) {}
  ull reduce(ull a) {
    ull q = (ull)((L(m) * a) >> 64);
    ull r = a - q * b; // can be proven that 0 <= r < 2*b
    return r >= b ? r - b : r;
  }
};
FastMod F(2);

int exp(int A, int B, int C) {
  if (A == 0)
    return 0;
  if (B == 0)
    return 1;
  ull y;
  if (B % 2 == 0) {
    y = exp(A, B / 2, C);
    y = (y * y) % C;
  } else {
    y = A % C;
    y = (y * exp(A, B - 1, C) % C) % C;
  }
  return (int)((y + C) % C);
}

int main() {
  ull MOD = 1000000007;
  int K;
  string S;
  cin >> K >> S;
  ull ans = 0;
  int size = K + S.size() + 10;
  ull fact[size];
  ull inv[size];
  fact[0] = 1;
  inv[0] = 1;
  for (int a = 1; a < size; a++) {
    fact[a] = (fact[a - 1] * a) % MOD;
    inv[a] = exp(fact[a], MOD - 2, MOD);
  }
  ull tf[size];
  ull ts[size];
  tf[0] = 1;
  ts[0] = 1;
  for (int a = 1; a < size; a++) {
    tf[a] = (tf[a - 1] * 25) % MOD;
    ts[a] = (ts[a - 1] * 26) % MOD;
  }
  for (int a = 0; a <= K; a++)
    ans = (ans + ((((fact[K - a + S.size() - 1] * inv[K - a]) % MOD *
                    inv[S.size() - 1]) %
                   MOD * tf[K - a]) %
                  MOD * ts[a]) %
                     MOD) %
          MOD;
  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

int exp(int A, int B, int C) {
  if (A == 0)
    return 0;
  if (B == 0)
    return 1;
  long long y;
  if (B % 2 == 0) {
    y = exp(A, B / 2, C);
    y = (y * y) % C;
  } else {
    y = A % C;
    y = (y * exp(A, B - 1, C) % C) % C;
  }
  return (int)((y + C) % C);
}

int main() {
  long long MOD = 1000000007;
  int K;
  string S;
  cin >> K >> S;
  long long ans = 0;
  int size = K + S.size() + 10;
  long long fact[size];
  long long inv[size];
  fact[0] = 1;
  inv[0] = 1;
  for (int a = 1; a < size; a++) {
    fact[a] = (fact[a - 1] * a) % MOD;
    inv[a] = exp(fact[a], MOD - 2, MOD);
  }
  long long tf[size];
  long long ts[size];
  tf[0] = 1;
  ts[0] = 1;
  for (int a = 1; a < size; a++) {
    tf[a] = (tf[a - 1] * 25) % MOD;
    ts[a] = (ts[a - 1] * 26) % MOD;
  }
  for (int a = 0; a <= K; a++)
    ans = (ans + ((((fact[K - a + S.size() - 1] * inv[K - a]) % MOD *
                    inv[S.size() - 1]) %
                   MOD * tf[K - a]) %
                  MOD * ts[a]) %
                     MOD) %
          MOD;
  cout << ans << endl;
}