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

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, n) for (int i = 0; i < (int)n; i++)
#define PB push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;

int fat[2000007];
int inv[2000007];

int binExp(int x, int p) {
  int ans = 1;
  while (p) {
    if (p & 1)
      ans = 1LL * ans * x % MOD;
    x = 1LL * x * x % MOD;
    p >>= 1;
  }
  return ans;
}

int comb(int a, int b) {
  int up = 1LL * fat[a] * inv[b] % MOD;
  up = 1LL * up * inv[a - b] % MOD;
  return up;
}

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

  fat[0] = inv[0] = 1;
  for (int i = 1; i < 2000007; i++) {
    fat[i] = 1LL * fat[i - 1] * i % MOD;
    inv[i] = binExp(fat[i], MOD - 2);
  }

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

  ll ans = 0;
  for (int i = 0; i <= k; i++) {
    int add = 1LL * comb(n + k, i + n) * binExp(25, k - i) % MOD;
    ans = (ans + add) % MOD;
  }

  cout << ans << '\\n';

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, n) for (int i = 0; i < (int)n; i++)
#define PB push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;

int fat[1000007];
int inv[1000007];

int binExp(int x, int p) {
  int ans = 1;
  while (p) {
    if (p & 1)
      ans = 1LL * ans * x % MOD;
    x = 1LL * x * x % MOD;
    p >>= 1;
  }
  return ans;
}

int comb(int a, int b) {
  int up = 1LL * fat[a] * inv[b] % MOD;
  up = 1LL * up * inv[a - b] % MOD;
  return up;
}

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

  fat[0] = inv[0] = 1;
  for (int i = 1; i < 1000007; i++) {
    fat[i] = 1LL * fat[i - 1] * i % MOD;
    inv[i] = binExp(fat[i], MOD - 2);
  }

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

  ll ans = 0;
  for (int i = 0; i <= k; i++) {
    int add = 1LL * comb(n + k, i + n) * binExp(25, k - i) % MOD;
    ans = (ans + add) % MOD;
  }

  cout << ans << '\\n';

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

#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for (ll i = 0; i < n; i++)
#define ll long long
#define MOD 1000000007LL
#define llMAX 9223372036854775807LL
#define llMIN -9223372036854775808LL
using vi = vector<ll>;  // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll k, n;

// moddivとnCk
ll moddiv(ll a, ll b) {
  ll x0 = MOD, x1 = b, x2, n0 = 0LL, n1 = 1LL, n2, t = a % b, m, ans;
  if (t == 0LL)
    return a / b;
  for (int i = 0; i < 900; i++) {
    m = x0 / x1;
    x2 = x0 - x1 * m;
    n2 = (n0 - m * n1) % MOD;
    if (x2 == 1LL) {
      ans = (n2 + MOD) % MOD;
      break;
    }
    x0 = x1;
    x1 = x2;
    n0 = n1;
    n1 = n2;
  }
  return (a + ((t * ans) % MOD) * b - t) / b;
}
// 剰余の割ざん

// aのn乗 mod c
ll expmod(ll a, ll n) {
  ll ans = 1LL, aa = a, beki = n;
  for (int i = 0; i < 64; i++) {
    if (beki % 2 == 1LL)
      ans = ans * aa % MOD;
    aa = aa * aa % MOD;
    beki /= 2LL;
    if (beki == 0LL)
      break;
  }
  return ans;
}

// nCk
vi mulmod(2000002); // 0!,1!,2!,3!,4!,,,,
void first_nCk() {
  mulmod[0] = 1LL;
  for (ll i = 1; i < 2000002; i++) {
    mulmod[i] = mulmod[i - 1] * i % MOD;
  }
}
ll nCk(ll nn, ll kk) {
  return moddiv(mulmod[nn], mulmod[kk] * mulmod[nn - kk] % MOD);
}

int main() {
  ll ans = 0;
  first_nCk();
  cin >> k;
  string s;
  cin >> s;

  n = s.length();
  for (ll i = 0; i <= k; i++) {
    ans = (ans + expmod(25, k - i) * nCk(n + k, i + n)) % MOD;
  }

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

Error: 0

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for (ll i = 0; i < n; i++)
#define ll long long
#define MOD 1000000007LL
#define llMAX 9223372036854775807LL
#define llMIN -9223372036854775808LL
using vi = vector<ll>;  // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll k, n;

// moddivとnCk
ll moddiv(ll a, ll b) {
  ll x0 = MOD, x1 = b, x2, n0 = 0LL, n1 = 1LL, n2, t = a % b, m, ans;
  if (t == 0LL)
    return a / b;
  for (int i = 0; i < 900; i++) {
    m = x0 / x1;
    x2 = x0 - x1 * m;
    n2 = (n0 - m * n1) % MOD;
    if (x2 == 1LL) {
      ans = (n2 + MOD) % MOD;
      break;
    }
    x0 = x1;
    x1 = x2;
    n0 = n1;
    n1 = n2;
  }
  return (a + ((t * ans) % MOD) * b - t) / b;
}
// 剰余の割ざん

// aのn乗 mod c
ll expmod(ll a, ll n) {
  ll ans = 1LL, aa = a, beki = n;
  for (int i = 0; i < 64; i++) {
    if (beki % 2 == 1LL)
      ans = ans * aa % MOD;
    aa = aa * aa % MOD;
    beki /= 2LL;
    if (beki == 0LL)
      break;
  }
  return ans;
}

// nCk
vi mulmod(1000002); // 0!,1!,2!,3!,4!,,,,
void first_nCk() {
  mulmod[0] = 1LL;
  for (ll i = 1; i < 1000002; i++) {
    mulmod[i] = mulmod[i - 1] * i % MOD;
  }
}
ll nCk(ll nn, ll kk) {
  return moddiv(mulmod[nn], mulmod[kk] * mulmod[nn - kk] % MOD);
}

int main() {
  ll ans = 0;
  first_nCk();
  cin >> k;
  string s;
  cin >> s;

  n = s.length();
  for (ll i = 0; i <= k; i++) {
    ans = (ans + expmod(25, k - i) * nCk(n + k, i + n)) % MOD;
  }

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

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string.h>
#define maxn 2000005
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
ll fac[maxn], inv[maxn];
ll pow25[maxn], pow26[maxn];
ll quickpow(ll p, ll k) {
  ll ans = 1;
  while (k) {
    if (k & 1)
      ans = (ans * p) % mod;
    p = (p * p) % mod;
    k >>= 1;
  }
  return ans;
}
ll c(ll n, ll m) {
  if (n < m)
    return 0;
  return (((fac[n] * inv[m]) % mod) * inv[n - m]) % mod;
}
char s[maxn];
int main() {
  pow25[0] = 1;
  pow26[0] = 1;
  fac[0] = 1;
  for (int i = 1; i <= 2e6; i++) {
    pow25[i] = (pow25[i - 1] * 25) % mod;
    pow26[i] = (pow26[i - 1] * 26) % mod;
    fac[i] = (fac[i - 1] * i) % mod;
  }
  inv[2000000] = quickpow(fac[2000000], mod - 2);
  for (int i = 2e6 - 1; i >= 0; i--)
    inv[i] = (inv[i + 1] * (i + 1)) % mod;
  ll ans = 0;
  int k, len;
  scanf("%d", &k);
  scanf("%s", s + 1);
  len = strlen(s + 1);
  for (int i = 1; i <= k + len; i++) {
    ll temp1 = pow26[i - 1];
    ll temp2 = c(k + len - i, len - 1);
    if (temp2 == 0)
      break;
    temp1 = (temp1 * temp2) % mod;
    ll temp3 = pow25[k - i + 1];
    temp1 = (temp1 * temp3) % mod;
    ans = (ans + temp1) % mod;
  }
  printf("%lld\\n", ans);
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string.h>
#define maxn 1000005
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
ll fac[maxn], inv[maxn];
ll pow25[maxn], pow26[maxn];
ll quickpow(ll p, ll k) {
  ll ans = 1;
  while (k) {
    if (k & 1)
      ans = (ans * p) % mod;
    p = (p * p) % mod;
    k >>= 1;
  }
  return ans;
}
ll c(ll n, ll m) {
  if (n < m)
    return 0;
  return (((fac[n] * inv[m]) % mod) * inv[n - m]) % mod;
}
char s[maxn];
int main() {
  pow25[0] = 1;
  pow26[0] = 1;
  fac[0] = 1;
  for (int i = 1; i <= 1e6; i++) {
    pow25[i] = (pow25[i - 1] * 25) % mod;
    pow26[i] = (pow26[i - 1] * 26) % mod;
    fac[i] = (fac[i - 1] * i) % mod;
  }
  inv[1000000] = quickpow(fac[1000000], mod - 2);
  for (int i = 1e6 - 1; i >= 0; i--)
    inv[i] = (inv[i + 1] * (i + 1)) % mod;
  ll ans = 0;
  int k, len;
  scanf("%d", &k);
  scanf("%s", s + 1);
  len = strlen(s + 1);
  for (int i = 1; i <= k + len; i++) {
    ll temp1 = pow26[i - 1];
    ll temp2 = c(k + len - i, len - 1);
    if (temp2 == 0)
      break;
    temp1 = (temp1 * temp2) % mod;
    ll temp3 = pow25[k - i + 1];
    temp1 = (temp1 * temp3) % mod;
    ans = (ans + temp1) % mod;
  }
  printf("%lld\\n", ans);
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

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

ll modpow(ll a, ll n, ll p) {
  if (n == 0)
    return 1;
  if (n % 2)
    return (a * modpow(a, n - 1, p)) % p;
  if (!(n % 2)) {
    ll t = modpow(a, n / 2, p);
    return (t * t) % p;
  }
}

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

Error: 0

Fixed submission:

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

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

ll modpow(ll a, ll n, ll p) {
  if (n == 0)
    return 1;
  if (n % 2)
    return (a * modpow(a, n - 1, p)) % p;
  if (!(n % 2)) {
    ll t = modpow(a, n / 2, p);
    return (t * t) % p;
  }
}

int main() {
  int k;
  string s;
  cin >> k >> s;
  int n = s.size();
  ll ans = 0;
  COMinit();
  for (int i = 0; i <= k; i++) {
    ans += ((COM(k - i + n - 1, n - 1) * modpow(25, k - i, mod)) % mod *
            modpow(26, i, mod)) %
           mod;
    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 all(x) (x).begin(), (x).end()

typedef long long ll;
typedef pair<ll, ll> P;

const int mod =
    1000000007; // 出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60; // INF = 11

#define N_MAX 2010100
ll f[N_MAX], rf[N_MAX];
// f[n]  := n!
// rf[n] := (n!)^-1

ll modpow(ll a, ll b) { // aのb乗
  ll ans = 1;
  while (b > 0) {
    if (b & 1)
      ans = ans * a % mod;
    a = a * a % mod;
    b /= 2;
  }
  return ans;
}

void init() {
  f[0] = 1;
  for (ll i = 1; i < N_MAX; i++) {
    f[i] = (i * f[i - 1]) % mod;
  }
  for (ll i = 0; i < N_MAX; i++) {
    rf[i] = modpow(f[i], mod - 2);
  }
}

ll com(ll n, ll k) {
  // init();
  ll a = f[n];
  ll b = rf[k];
  ll c = rf[n - k];

  ll bc = (b * c) % mod;

  return ((a * bc) % mod);
}

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

  ll ans = 0;

  for (ll i = 0; i <= k; i++) {

    ans += com((n - 1 + k - i), (n - 1)) * modpow(25, k - i) % mod *
           modpow(26, i) % mod;
    ans %= mod;
  }

  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef pair<ll, ll> P;

const int mod =
    1000000007; // 出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60; // INF = 11

#define N_MAX 201010
ll f[N_MAX], rf[N_MAX];
// f[n]  := n!
// rf[n] := (n!)^-1

ll modpow(ll a, ll b) { // aのb乗
  ll ans = 1;
  while (b > 0) {
    if (b & 1)
      ans = ans * a % mod;
    a = a * a % mod;
    b /= 2;
  }
  return ans;
}

void init() {
  f[0] = 1;
  for (ll i = 1; i < N_MAX; i++) {
    f[i] = (i * f[i - 1]) % mod;
  }
  for (ll i = 0; i < N_MAX; i++) {
    rf[i] = modpow(f[i], mod - 2);
  }
}

ll com(ll n, ll k) {
  // init();
  ll a = f[n];
  ll b = rf[k];
  ll c = rf[n - k];

  ll bc = (b * c) % mod;

  return ((a * bc) % mod);
}

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

  ll ans = 0;

  for (ll i = 0; i <= k; i++) {

    ans += com((n - 1 + k - i), (n - 1)) * modpow(25, k - i) % mod *
           modpow(26, i) % mod;
    ans %= mod;
  }

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;
ll kai[(1 << 21)];
ll dp[(1 << 21)];
void init() {
  kai[0] = 1;
  kai[1] = 1;
  for (ll i = 2; i < (1 << 21); i++) {
    kai[i] = kai[i - 1] * i % mod;
  }
}

ll mp(ll a, ll b) {
  if (b == 0)
    return 1LL;
  ll ret = mp(a, b / 2);
  ret *= ret;
  ret %= mod;
  if (b & 1)
    ret *= a;
  return ret % mod;
}

ll inv(ll k) { return mp(k, mod - 2); }

ll c(ll n, ll k) {
  if (k == 0)
    return 1;
  if (n == k)
    return 1;
  return kai[n] * inv(kai[k]) % mod * inv(kai[n - k]) % mod;
}

int main() {
  init();
  int k;
  string s;
  cin >> k >> s;
  int n = s.size();
  dp[n] = 1LL;
  for (ll i = n + 1; i <= n + k; i++) {
    dp[i] = dp[i - 1] * 26LL % mod;
    dp[i] += c(i - 1, n - 1) * mp(25LL, i - n);
    dp[i] %= mod;
  }
  cout << dp[n + k] << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;
ll kai[(1 << 20)];
ll dp[(1 << 21)];
void init() {
  kai[0] = 1;
  kai[1] = 1;
  for (ll i = 2; i < (1 << 20); i++) {
    kai[i] = kai[i - 1] * i % mod;
  }
}

ll mp(ll a, ll b) {
  if (b == 0)
    return 1LL;
  ll ret = mp(a, b / 2);
  ret *= ret;
  ret %= mod;
  if (b & 1)
    ret *= a;
  return ret % mod;
}

ll inv(ll k) { return mp(k, mod - 2); }

ll c(ll n, ll k) {
  if (k == 0)
    return 1;
  if (n == k)
    return 1;
  return kai[n] * inv(kai[k]) % mod * inv(kai[n - k]) % mod;
}

int main() {
  init();
  int k;
  string s;
  cin >> k >> s;
  int n = s.size();
  dp[n] = 1LL;
  for (ll i = n + 1; i <= n + k; i++) {
    dp[i] = dp[i - 1] * 26LL % mod;
    dp[i] += c(i - 1, n - 1) * mp(25LL, i - n);
    dp[i] %= mod;
  }
  cout << dp[n + k] << endl;
  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
const int MAX = 2000010;
const int MOD = 1000000007;

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

ll mod_pow(ll a, ll n) {
  a %= MOD;
  ll ret = 1;
  while (n > 0) {
    if (n & 1LL)
      ret = (ret * a) % MOD;
    a = (a * a) % MOD;
    n = n >> 1;
  }
  return ret;
}

// テーブルを作る前処理
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();
  ll k;
  string s;
  cin >> k >> s;
  ll n = s.size();
  ll sum = n + k;
  ll ans = 0;
  rep(b, 0, k + 1) {
    ll f = sum - b;
    ll tmp = (COM(f - 1, n - 1) * mod_pow(25, k - b)) % MOD;
    tmp = (tmp * mod_pow(26, b)) % MOD;
    ans = (ans + tmp) % MOD;
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
const int MAX = 510000;
const int MOD = 1000000007;

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

ll mod_pow(ll a, ll n) {
  a %= MOD;
  ll ret = 1;
  while (n > 0) {
    if (n & 1LL)
      ret = (ret * a) % MOD;
    a = (a * a) % MOD;
    n = n >> 1;
  }
  return ret;
}

// テーブルを作る前処理
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();
  ll k;
  string s;
  cin >> k >> s;
  ll n = s.size();
  ll sum = n + k;
  ll ans = 0;
  rep(b, 0, k + 1) {
    ll f = sum - b;
    ll tmp = (COM(f - 1, n - 1) * mod_pow(25, k - b)) % MOD;
    tmp = (tmp * mod_pow(26, b)) % MOD;
    ans = (ans + tmp) % MOD;
  }
  cout << ans << endl;
  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (ll i = a; i < b; i++)
typedef pair<ll, ll> pi;
typedef vector<ll> vi;
ll mod = 1e9 + 7;
ll k;
string s;

ll f[2000005];
ll invf[2000005];
ll p26[2000005];
ll p25[2000005];

ll power(ll a, ll b) {
  a %= mod;
  if (b == 0)
    return 1;
  if (b == 1)
    return a;
  ll half = power(a, b / 2);
  half *= half;
  half %= mod;
  if (b % 2 == 1) {
    half *= a;
    half %= mod;
  }
  return half;
}

void init() {
  f[0] = 1;
  p25[0] = 1;
  p26[0] = 1;
  invf[0] = power(f[0], mod - 2);
  REP(i, 1, 2000001) {
    f[i] = i * f[i - 1];
    f[i] %= mod;
    invf[i] = power(f[i], mod - 2);
    p25[i] = p25[i - 1] * 25;
    p25[i] %= mod;
    p26[i] = p26[i - 1] * 26;
    p26[i] %= mod;
  }
}

ll choose(ll n, ll k) { return (((f[n] * invf[n - k]) % mod) * invf[k]) % mod; }

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  init();
  cin >> k;
  cin >> s;
  ll answer = 0;
  ll t = k + s.length();
  REP(i, (int)s.length() - 1, t) {
    ll curans = 1;
    curans *= p26[t - 1 - i];
    // curans *= power((ll)26, t - 1 - i);
    curans *= choose(i, (ll)s.length() - 1);
    curans %= mod;
    // curans *= power((ll)25, i - (s.length()-1));
    curans *= p25[i - (s.length() - 1)];
    curans %= mod;
    answer += curans;
    answer %= mod;
  }
  cout << answer << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (ll i = a; i < b; i++)
typedef pair<ll, ll> pi;
typedef vector<ll> vi;
ll mod = 1e9 + 7;
ll k;
string s;

ll f[2000005];
ll invf[2000005];

ll power(ll a, ll b) {
  a %= mod;
  if (b == 0)
    return 1;
  if (b == 1)
    return a;
  ll half = power(a, b / 2);
  half *= half;
  half %= mod;
  if (b % 2 == 1) {
    half *= a;
    half %= mod;
  }
  return half;
}

void init() {
  f[0] = 1;
  invf[0] = power(f[0], mod - 2);
  REP(i, 1, 2000001) {
    f[i] = i * f[i - 1];
    f[i] %= mod;
    invf[i] = power(f[i], mod - 2);
  }
}

ll choose(ll n, ll k) { return (((f[n] * invf[n - k]) % mod) * invf[k]) % mod; }

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  init();
  cin >> k;
  cin >> s;
  ll answer = 0;
  ll t = k + s.length();
  REP(i, (int)s.length() - 1, t) {
    ll curans = 1;
    curans *= power((ll)26, t - 1 - i);
    curans *= choose(i, (ll)s.length() - 1);
    curans %= mod;
    curans *= power((ll)25, i - (s.length() - 1));
    curans %= mod;
    answer += curans;
    answer %= mod;
  }
  cout << answer << endl;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <utility>
#include <vector>

using namespace std;

typedef long long LL;
typedef pair<int, int> pii;

const LL MOD = 1000000007;
const int MAXN = 2000005;

LL pow25[MAXN];
LL pow26[MAXN];
LL fact[MAXN];

LL expsq(LL x, LL p, LL M) {
  LL res = 1LL;
  while (p > 0LL) {
    if (p & 1LL) {
      res = (res * x) % M;
    }
    x = (x * x) % M;
    p /= 2LL;
  }
  return res;
}

LL modinv(LL x, LL M) { return expsq(x, M - 2, M); }

LL nCr_fermat(int N, int K, LL M) {
  return (fact[N] * modinv(fact[K] * fact[N - K] % M, M)) % M;
}

int main() {
  ios::sync_with_stdio(false);
  string S;
  int K;
  cin >> K >> S;
  int Z = S.size();
  int N = K + Z;

  pow25[0] = pow26[0] = 1LL;
  fact[0] = 1LL;
  for (int i = 1; i <= N; i++) {
    pow25[i] = (pow25[i - 1] * 25LL) % MOD;
    pow26[i] = (pow26[i - 1] * 26LL) % MOD;
    fact[i] = (fact[i - 1] * (LL)i) % MOD;
  }
  LL ans = 0;
  for (int x = Z - 1; x < N; x++) {
    LL res = 1LL;
    res = (res * nCr_fermat(x, Z - 1, MOD)) % MOD;
    res = (res * pow25[x - Z + 1]) % MOD;
    res = (res * pow26[N - x - 1]) % MOD;
    ans = (ans + res) % MOD;
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <utility>
#include <vector>

using namespace std;

typedef long long LL;
typedef pair<int, int> pii;

const LL MOD = 1000000007;
const int MAXN = 1000005;

LL pow25[MAXN];
LL pow26[MAXN];
LL fact[MAXN];

LL expsq(LL x, LL p, int M) {
  LL res = 1LL;
  while (p > 0LL) {
    if (p & 1LL) {
      res = (res * x) % M;
    }
    x = (x * x) % M;
    p /= 2LL;
  }
  return res;
}

LL modinv(LL x, int M) { return expsq(x, M - 2, M); }

LL nCr_fermat(int N, int K, int M) {
  return (fact[N] * modinv(fact[K] * fact[N - K] % M, M)) % M;
}

int main() {
  ios::sync_with_stdio(false);
  string S;
  int K;
  cin >> K >> S;
  int Z = S.size();
  int N = K + Z;

  pow25[0] = pow26[0] = 1LL;
  fact[0] = 1LL;
  for (int i = 1; i <= N; i++) {
    pow25[i] = (pow25[i - 1] * 25LL) % MOD;
    pow26[i] = (pow26[i - 1] * 26LL) % MOD;
    fact[i] = (fact[i - 1] * (LL)i) % MOD;
  }
  LL ans = 0;
  for (int x = Z - 1; x < N; x++) {
    LL res = 1LL;
    res = (res * nCr_fermat(x, Z - 1, MOD)) % MOD;
    res = (res * pow25[x - Z + 1]) % MOD;
    res = (res * pow26[N - x - 1]) % MOD;
    ans = (ans + res) % MOD;
  }
  cout << ans << endl;
}