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

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <vector>
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define sz(a) (int)a.size()
using namespace std;

ll inf = 1e9 + 7;

// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

const int MAX = 2000100;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  // 前処理
  COMinit();
  int k;
  cin >> k;
  string s;
  cin >> s;
  int a = sz(s);
  ll ans = 0;
  rep(i, k + 1) {
    ll ansi = COM(a + k - 1 - i, a - 1);
    ansi *= modpow((ll)25, ll(k - i), inf);
    ansi %= inf;
    ansi *= modpow((ll)26, (ll)i, inf);
    ansi %= inf;
    ans += ansi;
    ans %= inf;
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <vector>
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define sz(a) (int)a.size()
using namespace std;

ll inf = 1e9 + 7;

// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

int main() {
  // 前処理
  COMinit();
  int k;
  cin >> k;
  string s;
  cin >> s;
  int a = sz(s);
  ll ans = 0;
  rep(i, k + 1) {
    ll ansi = COM(a + k - 1 - i, a - 1);
    ansi *= modpow((ll)25, (ll)k - i, inf);
    ansi %= inf;
    ansi *= modpow((ll)26, (ll)i, inf);
    ansi %= inf;
    ans += ansi;
    ans %= inf;
  }
  cout << ans << endl;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int N = 2000005;
const long long MOD = 1000000007;
int n;
char s[N];
int k;
long long ksm(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1)
      res = res * a % MOD;
    a = a * a % MOD, b >>= 1;
  }
  return res;
}
long long fac[N], inv[N];
void init(int n = 2000000) {
  fac[0] = 1;
  for (int i = 1; i <= n; i++)
    fac[i] = fac[i - 1] * i % MOD;
  inv[n] = ksm(fac[n], MOD - 2);
  for (int i = n; i >= 1; i--)
    inv[i - 1] = inv[i] * i % MOD;
  return;
}
long long C(int m, int n) {
  if (m > n)
    return 0;
  return fac[n] * inv[m] % MOD * inv[n - m] % MOD;
}
int main() {
  init();
  scanf("%d", &n);
  scanf("%s", s + 1);
  k = n + strlen(s + 1);
  n = strlen(s + 1);
  long long ans = 0;
  for (int i = 1; i <= k - n + 1; i++)
    ans = (ans + ksm(26, i - 1) * ksm(25, k - i - n + 1) % MOD *
                     C(n - 1, k - i) % MOD) %
          MOD;
  printf("%lld", ans);
  return 0;
}

Error: WA

Fixed submission:

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int N = 1000005;
const long long MOD = 1000000007;
int n;
char s[N];
int k;
long long ksm(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1)
      res = res * a % MOD;
    a = a * a % MOD, b >>= 1;
  }
  return res;
}
long long fac[N], inv[N];
void init(int n = 1000000) {
  fac[0] = 1;
  for (int i = 1; i <= n; i++)
    fac[i] = fac[i - 1] * i % MOD;
  inv[n] = ksm(fac[n], MOD - 2);
  for (int i = n; i >= 1; i--)
    inv[i - 1] = inv[i] * i % MOD;
  return;
}
long long C(int m, int n) {
  if (m > n)
    return 0;
  return fac[n] * inv[m] % MOD * inv[n - m] % MOD;
}
int main() {
  init();
  scanf("%d", &n);
  scanf("%s", s + 1);
  k = n + strlen(s + 1);
  n = strlen(s + 1);
  long long ans = 0;
  for (int i = 1; i <= k - n + 1; i++)
    ans = (ans + ksm(26, i - 1) * ksm(25, k - i - n + 1) % MOD *
                     C(n - 1, k - i) % MOD) %
          MOD;
  printf("%lld", ans);
  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAX = 2000007;
const int MOD = 1000000007;
//
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 mod) {
  int res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
signed main() {
  COMinit();
  int k;
  string s;
  cin >> k >> s;
  int ans = 0;
  for (int i = 0; i <= k; i++) {
    ans = (ans + modpow(25, i, MOD) * COM(i + s.size() - 1, s.size() - 1) %
                     MOD * modpow(26, k - i, MOD) % MOD) %
          MOD;
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAX = 510000;
const int MOD = 1000000007;
//
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 mod) {
  int res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
signed main() {
  COMinit();
  int k;
  string s;
  cin >> k >> s;
  int ans = 0;
  for (int i = 0; i <= k; i++) {
    ans = (ans + modpow(25, i, MOD) * COM(i + s.size() - 1, s.size() - 1) %
                     MOD * modpow(26, k - i, MOD) % MOD) %
          MOD;
  }
  cout << ans << endl;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 3e6 + 17;
const int MOD = 1e9 + 7;
int fac[N], invfac[N];
int binpow(int a, int n) {
  if (n == 0)
    return 1;
  else {
    if (n % 2 == 0) {
      int k = binpow(a, n / 2) % MOD;
      return k * k % MOD;
    } else {
      int k = binpow(a, n - 1) % MOD;
      return k * a % MOD;
    }
  }
}
int C(int n, int k) {
  if (n - k < 0)
    return 0;
  return (fac[n] % MOD * invfac[k] % MOD * invfac[n - k] % MOD) % MOD;
}
signed main() {
  fac[0] = invfac[0] = 1;
  for (int i = 1; i < N; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    invfac[i] = binpow(fac[i], MOD - 2);
  }
  int K;
  string S;
  cin >> K >> S;
  int n = S.size();
  int ans = 0;
  for (int i = n; i <= n + K; ++i) {
    ans = (ans + (C(n + K, i) * binpow(25, n + K - i)) % MOD) % MOD;
  }
  cout << ans;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e6 + 7;
const int MOD = 1e9 + 7;
int fac[N], invfac[N];
int binpow(int a, int n) {
  if (n == 0)
    return 1;
  else {
    if (n % 2 == 0) {
      int k = binpow(a, n / 2) % MOD;
      return k * k % MOD;
    } else {
      int k = binpow(a, n - 1) % MOD;
      return k * a % MOD;
    }
  }
}
int C(int n, int k) {
  if (n - k < 0)
    return 0;
  return (fac[n] % MOD * invfac[k] % MOD * invfac[n - k] % MOD) % MOD;
}
signed main() {
  fac[0] = invfac[0] = 1;
  for (int i = 1; i < N; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    invfac[i] = binpow(fac[i], MOD - 2);
  }
  int K;
  string S;
  cin >> K >> S;
  int n = S.size();
  int ans = 0;
  for (int i = n; i <= n + K; ++i) {
    ans = (ans + C(n + K, i) * binpow(25, n + K - i)) % MOD;
  }
  cout << ans;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define ll long long
#define MAX_N 2000001

using namespace std;

long long MOD = 1000000007;

long long fact[MAX_N];
void factorial(int N) {
  fact[0] = 1;
  for (int i = 0; i < N; i++) {
    fact[i + 1] = (i + 1) * fact[i] % MOD;
  }
}

map<long long, long long> inv;
long long inverse(long long x) {
  if (inv.count(x)) {
    return inv[x];
  }
  long long p = MOD - 2;
  long long ret = 1;
  long long tmp = x;
  while (p > 0) {
    if (p % 2 == 1)
      ret = ret * tmp % MOD;
    tmp = tmp * tmp % MOD;
    p /= 2;
  }
  inv[x] = ret;
  return ret;
}

long long comb(int a, int b) {
  long long ret = fact[a] * inverse(fact[a - b]) % MOD;
  return ret * inverse(fact[b]) % MOD;
}

ll pow(int x, int n) {
  ll ret = 1;
  for (int i = 0; i < n; i++) {
    ret *= (ll)x;
    ret %= MOD;
  }
  return ret;
}

int main() {
  ll K;
  string S;
  cin >> K >> S;
  ll ans = 0;
  ll M = S.size();

  vector<ll> p25(K + 1, 1);
  vector<ll> p26(K + 1, 1);
  for (int i = 0; i < K; i++) {
    p25[i + 1] = p25[i] * 25 % MOD;
    p26[i + 1] = p26[i] * 26 % MOD;
  }

  factorial(2000000);
  for (int i = 0; i <= K; i++) {
    ans +=
        comb((int)K + M - 1 - i, (int)M - 1) * p25[K - i] % MOD * p26[i] % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define ll long long
#define MAX_N 1000001

using namespace std;

long long MOD = 1000000007;

long long fact[MAX_N];
void factorial(int N) {
  fact[0] = 1;
  for (int i = 0; i < N; i++) {
    fact[i + 1] = (i + 1) * fact[i] % MOD;
  }
}

map<long long, long long> inv;
long long inverse(long long x) {
  if (inv.count(x)) {
    return inv[x];
  }
  long long p = MOD - 2;
  long long ret = 1;
  long long tmp = x;
  while (p > 0) {
    if (p % 2 == 1)
      ret = ret * tmp % MOD;
    tmp = tmp * tmp % MOD;
    p /= 2;
  }
  inv[x] = ret;
  return ret;
}

long long comb(int a, int b) {
  long long ret = fact[a] * inverse(fact[a - b]) % MOD;
  return ret * inverse(fact[b]) % MOD;
}

ll pow(int x, int n) {
  ll ret = 1;
  for (int i = 0; i < n; i++) {
    ret *= (ll)x;
    ret %= MOD;
  }
  return ret;
}

int main() {
  ll K;
  string S;
  cin >> K >> S;
  ll ans = 0;
  ll M = S.size();

  vector<ll> p25(K + 1, 1);
  vector<ll> p26(K + 1, 1);
  for (int i = 0; i < K; i++) {
    p25[i + 1] = p25[i] * 25 % MOD;
    p26[i + 1] = p26[i] * 26 % MOD;
  }

  factorial(1000000);
  for (int i = 0; i <= K; i++) {
    ans +=
        comb((int)K + M - 1 - i, (int)M - 1) * p25[K - i] % MOD * p26[i] % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

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

typedef long long ll;

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

ll mod_pow(ll x, ll n) { // べき乗
  ll ans = 1;
  x %= MOD;
  while (n != 0) {
    if (n & 1)
      ans = ans * x % MOD;
    x = x * x % MOD;
    n = n >> 1;
  }
  return ans % MOD;
}

void com_init() { // 初期化
  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;
    finv[i] = finv[i - 1] * mod_pow(i, MOD - 2) % MOD; // フェルマーの小定理より
  }
}

ll comb(ll n, ll k) { // nCk
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  int k;
  cin >> k;
  string s;
  cin >> s;
  com_init();
  int N = s.size();
  ll ans = 0;
  for (int i = 1; i <= (k + N); i++) {
    if (N <= i) {
      ans += ((comb(i - 1, N - 1) * mod_pow(25, i - N)) % MOD *
              mod_pow(26, k + N - i)) %
             MOD;
    }
    ans %= MOD;
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

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

typedef long long ll;

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

ll mod_pow(ll x, ll n) { // べき乗
  ll ans = 1;
  x %= MOD;
  while (n != 0) {
    if (n & 1)
      ans = ans * x % MOD;
    x = x * x % MOD;
    n = n >> 1;
  }
  return ans % MOD;
}

void com_init() { // 初期化
  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;
    finv[i] = finv[i - 1] * mod_pow(i, MOD - 2) % MOD; // フェルマーの小定理より
  }
}

ll comb(ll n, ll k) { // nCk
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <utility>
#include <vector>
using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

vector<ll> fac(2000001);
vector<ll> ifac(2000001);

ll pow(ll x, ll n) {
  if (n == 0)
    return 1;
  if (n == 1)
    return x % MOD;
  ll tmp = pow(x, n / 2) % MOD;
  ll tmp2 = (tmp * tmp) % MOD;
  if (n % 2)
    return tmp2 * x % MOD;
  return tmp2;
}

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] % MOD;
  return tmp * fac[a] % MOD;
}

int main() {
  fac[0] = 1;
  ifac[0] = 1;
  for (int i = 0; i < 2000000; i++) {
    fac[i + 1] = fac[i] * (i + 1) % MOD;
    ifac[i + 1] = ifac[i] * pow(i + 1, MOD - 2) % MOD;
  }

  int K, l;
  string S;

  cin >> K;
  cin >> S;
  l = S.length();
  ll ans = 0;

  for (int i = l; i <= K + l; i++) {
    ll tmp = pow(25, i - l) % MOD;
    tmp *= comb(i - 1, l - 1) % MOD;
    tmp %= MOD;
    tmp *= pow(26, K + l - i) % MOD;
    tmp %= MOD;
    ans += tmp;
    ans %= MOD;
  }

  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <utility>
#include <vector>
using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

vector<ll> fac(1000001);
vector<ll> ifac(1000001);

ll pow(ll x, ll n) {
  if (n == 0)
    return 1;
  if (n == 1)
    return x % MOD;
  ll tmp = pow(x, n / 2) % MOD;
  ll tmp2 = (tmp * tmp) % MOD;
  if (n % 2)
    return tmp2 * x % MOD;
  return tmp2;
}

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] % MOD;
  return tmp * fac[a] % MOD;
}

int main() {
  fac[0] = 1;
  ifac[0] = 1;
  for (int i = 0; i < 1000000; i++) {
    fac[i + 1] = fac[i] * (i + 1) % MOD;
    ifac[i + 1] = ifac[i] * pow(i + 1, MOD - 2) % MOD;
  }

  int K, l;
  string S;

  cin >> K;
  cin >> S;
  l = S.length();
  ll ans = 0;

  for (int i = l; i <= K + l; i++) {
    ll tmp = pow(25, i - l) % MOD;
    tmp *= comb(i - 1, l - 1) % MOD;
    tmp %= MOD;
    tmp *= pow(26, K + l - i) % MOD;
    tmp %= MOD;
    ans += tmp;
    ans %= MOD;
  }

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

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

const long long mod = 1e9 + 7;
const long long N = 2e6 + 10;

long long fact[N];

template <typename T> void add_self(T &a, T b) {
  a += b;
  if (a > mod) {
    a -= mod;
  }
}

template <typename T> void substract_self(T &a, T b) {
  a -= b;
  if (a < 0) {
    a += mod;
  }
}

template <typename T> long long mul(T a, T b) { return (a * b) % mod; }

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

long long modInverse(long long a) { return power(a, (long long)(mod - 2)); }

long long nCr(long long n, long long r) {
  long long val =
      mul(fact[n], mul(modInverse(fact[n - r]), modInverse(fact[r])));
  return val;
}

int main() {
  fact[0] = 1;
  for (int i = 1; i < N; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
  }
  long long n, k;
  cin >> k;
  string s;
  cin >> s;
  n = s.length();
  long long sol = power(26ll, n + k);
  for (int i = 0; i < n; i++) {
    long long val = mul(nCr(n + k, i), power(25ll, n + k - i));
    substract_self(sol, val);
  }
  cout << sol;

  return 0;
}

Error: WA

Fixed submission:

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

const long long mod = 1e9 + 7;
const long long N = 1e6 + 10;

long long fact[N];

template <typename T> void add_self(T &a, T b) {
  a += b;
  if (a > mod) {
    a -= mod;
  }
}

template <typename T> void substract_self(T &a, T b) {
  a -= b;
  if (a < 0) {
    a += mod;
  }
}

template <typename T> long long mul(T a, T b) { return (a * b) % mod; }

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

long long modInverse(long long a) { return power(a, (long long)(mod - 2)); }

long long nCr(long long n, long long r) {
  long long val =
      mul(fact[n], mul(modInverse(fact[n - r]), modInverse(fact[r])));
  return val;
}

int main() {
  fact[0] = 1;
  for (int i = 1; i < N; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
  }
  long long n, k;
  cin >> k;
  string s;
  cin >> s;
  n = s.length();
  long long sol = power(26ll, n + k);
  for (int i = 0; i < n; i++) {
    long long val = mul(nCr(n + k, i), power(25ll, n + k - i));
    substract_self(sol, val);
  }
  cout << sol;

  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
long long fac[2000005], inv[2000005];
long long modpow(long long x, long long e) {
  if (x == 1 || e == 0)
    return 1;
  long long c = modpow(x, e / 2);
  long long c1 = (c * c) % MOD;
  if (e % 2 == 0)
    return c1;
  else
    return (c1 * x) % MOD;
}
long long C(long long n, long long k) {
  if (k > n || k < 0)
    return 0;
  return ((fac[n] * inv[k]) % MOD * inv[n - k]) % MOD;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  fac[0] = inv[0] = 1;
  for (int i = 1; i < 2000005; i++) {
    fac[i] = (fac[i - 1] * i) % MOD;
    if (i < 1000005)
      inv[i] = (inv[i - 1] * modpow(i, MOD - 2)) % MOD;
  }
  int k, n;
  string s;
  cin >> k >> s;
  n = s.size();
  long long ans = 0;
  for (int i = n; i <= n + k; i++) {
    long long add = (C(i - 1, n - 1) * modpow(25, i - n)) % MOD;
    add = (add * modpow(26, n + k - i)) % MOD;
    ans = (add + ans) % MOD;
  }
  cout << ans;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
long long fac[2000005], inv[2000005];
long long modpow(long long x, long long e) {
  if (x == 1 || e == 0)
    return 1;
  long long c = modpow(x, e / 2);
  long long c1 = (c * c) % MOD;
  if (e % 2 == 0)
    return c1;
  else
    return (c1 * x) % MOD;
}
long long C(long long n, long long k) {
  if (k > n || k < 0)
    return 0;
  return ((fac[n] * inv[k]) % MOD * inv[n - k]) % MOD;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  fac[0] = inv[0] = 1;
  for (int i = 1; i < 2000005; i++) {
    fac[i] = (fac[i - 1] * i) % MOD;
    inv[i] = (inv[i - 1] * modpow(i, MOD - 2)) % MOD;
  }
  int k, n;
  string s;
  cin >> k >> s;
  n = s.size();
  long long ans = 0;
  for (int i = n; i <= n + k; i++) {
    long long add = (C(i - 1, n - 1) * modpow(25, i - n)) % MOD;
    add = (add * modpow(26, n + k - i)) % MOD;
    ans = (add + ans) % MOD;
  }
  cout << ans;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

long long power(long long a, long long b, long long m) {

  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}

const int mod = 1e9 + 7;

int fac[2000005];
int ncr(int n, int r) {
  if (n < r)
    return 0;
  int z = fac[n];
  z = (z * power(fac[n - r], mod - 2, mod)) % mod;
  z = (z * power(fac[r], mod - 2, mod)) % mod;
  return z;
}

signed main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);

#ifndef ONLINE_JUDGE
  if (fopen("INPUT.txt", "r")) {
    freopen("INPUT.txt", "r", stdin);
    freopen("OUTPUT.txt", "w", stdout);
  }
#endif

  fac[0] = 1;
  for (int i = 1; i <= 2000000; i++)
    fac[i] = (fac[i - 1] * i) % mod;

  int k;
  cin >> k;
  string a;
  cin >> a;
  int n = a.length();
  int tot = 0;
  for (int i = n; i <= n + k; i++) {
    int z = power(25, i - n, mod) * ncr(i - 1, n - 1) % mod *
            power(26, n + k - i, mod) % mod;
    tot += z;
    tot %= mod;
  }
  cout << tot;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

long long power(long long a, long long b, long long m) {

  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}

const int mod = 1e9 + 7;

int fac[1000005];
int ncr(int n, int r) {
  if (n < r)
    return 0;
  int z = fac[n];
  z = (z * power(fac[n - r], mod - 2, mod)) % mod;
  z = (z * power(fac[r], mod - 2, mod)) % mod;
  return z;
}

signed main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);

#ifndef ONLINE_JUDGE
  if (fopen("INPUT.txt", "r")) {
    freopen("INPUT.txt", "r", stdin);
    freopen("OUTPUT.txt", "w", stdout);
  }
#endif

  fac[0] = 1;
  for (int i = 1; i <= 1000000; i++)
    fac[i] = (fac[i - 1] * i) % mod;

  int k;
  cin >> k;
  string a;
  cin >> a;
  int n = a.length();
  int tot = 0;
  for (int i = n; i <= n + k; i++) {
    int z = power(25, i - n, mod) * ncr(i - 1, n - 1) % mod *
            power(26, n + k - i, mod) % mod;
    tot += z;
    tot %= mod;
  }
  cout << tot;
}