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

#include <stdio.h>

#define ULL unsigned long long

#define MOD 1000000007
#define MAX 10000000

ULL RepSq(ULL n, ULL m, ULL mod);
void nCk_init(int mod);
ULL nCk(int n, int k, int mod);

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

int main() {
  nCk_init(MOD);

  int K, a, iCnt = 0;
  scanf("%d", &K);

  getchar();
  while ((a = getchar()) != '\\n')
    iCnt++;
  ULL ans = 0;

  for (int i = 0; i <= K; i++) {
    // inserted place patterns
    ULL tmpChairs4OtherLetters = iCnt + K - i - 1;
    ULL insPlacePatterns = nCk((int)tmpChairs4OtherLetters, iCnt - 1, MOD);

    // inserted letter patterns
    ULL insLetsBeforeLastLet = K - i;
    ULL insLetPatterns = RepSq((ULL)26, (ULL)i, (ULL)MOD);
    insLetPatterns *= RepSq((ULL)25, insLetsBeforeLastLet, (ULL)MOD);
    insLetPatterns %= MOD;

    ans += (insPlacePatterns * insLetPatterns % MOD);
    ans %= MOD;
  }

  printf("%lld\\n", ans);

  return 0;
}

ULL RepSq(ULL x, ULL n, ULL mod) {
  if (n == 0)
    return 1;

  ULL ret = 1;
  while (0 < n) {
    if (n & 1)
      ret = ret * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return ret;
}

void nCk_init(int mod) {
  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;
  }
}

ULL nCk(int n, int k, int mod) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  // Fermat's little theorem
  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}


Error: TLE

Fixed submission:

#include <stdio.h>

#define ULL unsigned long long

#define MOD 1000000007
#define MAX 30000000

ULL RepSq(ULL n, ULL m, ULL mod);
void nCk_init(int mod);
ULL nCk(int n, int k, int mod);

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

int main() {
  nCk_init(MOD);

  int K, a, iCnt = 0;
  scanf("%d", &K);

  getchar();
  while ((a = getchar()) != '\\n')
    iCnt++;
  ULL ans = 0;

  for (int i = 0; i <= K; i++) {
    // inserted place patterns
    ULL tmpChairs4OtherLetters = iCnt + K - i - 1;
    ULL insPlacePatterns = nCk((int)tmpChairs4OtherLetters, iCnt - 1, MOD);

    // inserted letter patterns
    ULL insLetsBeforeLastLet = K - i;
    ULL insLetPatterns = RepSq((ULL)26, (ULL)i, (ULL)MOD);
    insLetPatterns *= RepSq((ULL)25, insLetsBeforeLastLet, (ULL)MOD);
    insLetPatterns %= MOD;

    ans += (insPlacePatterns * insLetPatterns % MOD);
    ans %= MOD;
  }

  printf("%lld\\n", ans);

  return 0;
}

ULL RepSq(ULL x, ULL n, ULL mod) {
  if (n == 0)
    return 1;

  ULL ret = 1;
  while (0 < n) {
    if (n & 1)
      ret = ret * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return ret;
}

void nCk_init(int mod) {
  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;
  }
}

ULL nCk(int n, int k, int mod) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  // Fermat's little theorem
  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\\n"
#define se second
#define ll long long
#define inf 0x3f3f3f3f
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
const int N = 2e6 + 5;
const ll mod = 1e9 + 7;
int k, n;
ll ans;
string s;
int fac[N], inv[N];
int po(int x, int y) {
  int res = 1;
  while (y) {
    if (y & 1)
      res = 1ll * res * x % mod;
    y >>= 1;
    x = 1ll * x * x % mod;
  }
  return res % mod;
}
int ncr(int n, int r) {
  if (r > n)
    return 0;
  return 1ll * fac[n] * inv[r] % mod * inv[n - r] % mod;
}
int main() {
  fast cin >> k >> s;
  fac[0] = 1;
  for (int i = 1; i < N; i++)
    fac[i] = 1ll * i * fac[i - 1] % mod;
  inv[N - 1] = po(fac[N - 1], mod - 2);
  for (int i = N - 2; i >= 0; i--)
    inv[i] = 1ll * (i + 1) * (inv[i + 1]) % mod;
  n = s.size();
  for (int i = 0; i <= k; i++) {
    ans = (ans +
           1ll * po(25, k - i) * po(26, i) % mod * ncr(n - 1 + k - i, n - 1)) %
          mod;
  }
  cout << ans;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\\n"
#define se second
#define ll long long
#define inf 0x3f3f3f3f
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
const int N = 1e6 + 5;
const ll mod = 1e9 + 7;
int k, n;
ll ans;
string s;
int fac[N], inv[N];
int po(int x, int y) {
  int res = 1;
  while (y) {
    if (y & 1)
      res = 1ll * res * x % mod;
    y >>= 1;
    x = 1ll * x * x % mod;
  }
  return res % mod;
}
int ncr(int n, int r) {
  if (r > n)
    return 0;
  return 1ll * fac[n] * inv[r] % mod * inv[n - r] % mod;
}
int main() {
  fast cin >> k >> s;
  fac[0] = 1;
  for (int i = 1; i < N; i++)
    fac[i] = 1ll * i * fac[i - 1] % mod;
  inv[N - 1] = po(fac[N - 1], mod - 2);
  for (int i = N - 2; i >= 0; i--)
    inv[i] = 1ll * (i + 1) * (inv[i + 1]) % mod;
  n = s.size();
  for (int i = 0; i <= k; i++) {
    ans = (ans +
           1ll * po(25, k - i) * po(26, i) % mod * ncr(n - 1 + k - i, n - 1)) %
          mod;
  }
  cout << ans;
}
Problem p02632 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll md = 1e9 + 7;
const ll mx = 1e6;
vector<ll> fact(2 * mx + 1);
vector<ll> invfact(mx + 1);

ll mul(ll a, ll b) { return (((a * b) % md) + md) % md; }

ll pow(ll a, ll b) {
  if (b == 0) {
    return 1LL;
  }
  ll ans = pow(a, b / 2);
  ans = mul(ans, ans);
  if (b % 2 == 1) {
    ans = mul(ans, a);
  }
  return ans;
}

ll lad(ll a, ll b) { return (((a + b) % md) + md) % md; }

ll choose(ll a, ll b) { return mul(mul(fact[a], invfact[b]), invfact[a - b]); }

int main() {
  fact[0] = 1;
  invfact[0] = 1;
  for (ll q = 1; q <= 2 * mx; q++) {
    fact[q] = mul(fact[q - 1], q);
  }
  for (ll q = 1; q <= mx; q++) {
    invfact[q] = pow(fact[q], md - 2);
  }
  ll inv25 = pow(25LL, md - 2);
  ll k;
  string s;
  cin >> k >> s;
  ll t = s.length();
  ll ss = pow(25LL, (ll)k);
  ll s26 = 1;
  ll ans = 0;
  for (ll q = 0; q <= k; q++) {
    ans = lad(ans, mul(choose(k + t - q - 1, t - 1), mul(ss, s26)));
    ss = mul(ss, inv25);
    s26 = mul(s26, 26);
  }
  cout << ans << "\\n";
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll md = 1e9 + 7;
const ll mx = 1e6;
vector<ll> fact(2 * mx + 1);
vector<ll> invfact(2 * mx + 1);

ll mul(ll a, ll b) { return (((a * b) % md) + md) % md; }

ll pow(ll a, ll b) {
  if (b == 0) {
    return 1LL;
  }
  ll ans = pow(a, b / 2);
  ans = mul(ans, ans);
  if (b % 2 == 1) {
    ans = mul(ans, a);
  }
  return ans;
}

ll lad(ll a, ll b) { return (((a + b) % md) + md) % md; }

ll choose(ll a, ll b) { return mul(mul(fact[a], invfact[b]), invfact[a - b]); }

int main() {
  fact[0] = 1;
  invfact[0] = 1;
  for (ll q = 1; q <= 2 * mx; q++) {
    fact[q] = mul(fact[q - 1], q);
    invfact[q] = pow(fact[q], md - 2);
  }
  ll inv25 = pow(25LL, md - 2);
  ll k;
  string s;
  cin >> k >> s;
  ll t = s.length();
  ll ss = pow(25LL, (ll)k);
  ll s26 = 1;
  ll ans = 0;
  for (ll q = 0; q <= k; q++) {
    ans = lad(ans, mul(choose(k + t - q - 1, t - 1), mul(ss, s26)));
    ss = mul(ss, inv25);
    s26 = mul(s26, 26);
  }
  cout << ans << "\\n";
  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define pii pair<int, int>
using namespace std;
const int mod = 1e9 + 7;
const int N = 2e6 + 3;
ll k, fact[N];

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

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

ll cal(ll x, ll p) {
  return fact[x] * modpow(fact[p], (mod - 2)) % mod *
         modpow(fact[x - p], (mod - 2)) % mod;
}

int main() {
  fast factor();
  cin >> k;
  string s;
  cin >> s;
  int p = s.size();
  ll ans = 0;
  for (int i = p; i <= p + k; i++) {
    ll temp =
        cal(i - 1, p - 1) * modpow(25, i - p) % mod * modpow(26, k + p - i);
    ans = (ans + temp) % mod;
  }
  cout << ans;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define pii pair<int, int>
using namespace std;
const int mod = 1e9 + 7;
const int N = 1e6 + 2;
int k, fact[N];

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

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

ll cal(ll x, ll p) {
  return fact[x] * modpow(fact[p], (mod - 2)) % mod *
         modpow(fact[x - p], (mod - 2)) % mod;
}

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

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

#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define pli pair<long long, int>
#define pil pair<int, long long>
#define ll long long
#define el '\\n'

using namespace std;

const int N = 2e6 + 10;
// const int N = 1e3 + 10;
const ll MOD = 1e9 + 7;

ll n, k;
string s;
// ll dp[N][N]; // pointer s last,
ll fac[N];

ll fpow(ll a, ll b) {
  ll ret = 1;
  while (b) {
    if (b & 1) {
      ret = ret * a % MOD;
    }
    b >>= 1;
    a = a * a % MOD;
  }
  return ret;
}
ll inv(ll a) { return fpow(a, MOD - 2); }
ll comb(ll n, ll k) { return fac[n] * inv(fac[n - k] * fac[k] % MOD) % MOD; }

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

  fac[0] = 1;
  for (ll i = 1; i < N; i++) {
    fac[i] = fac[i - 1] * i % MOD;
  }

  cin >> k;
  cin >> s;
  n = (ll)s.length();
  s = "*" + s;
  ll ans = 0;
  for (ll i = 0; i <= k; i++) {
    ll temp = (fpow(26, i) * fpow(25, k - i) % MOD) *
              comb(n + (k - i) - 1, (k - i)) % MOD;
    ans = (ans + temp) % MOD;
  }
  cout << ans << el;

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define pli pair<long long, int>
#define pil pair<int, long long>
#define ll long long
#define el '\\n'

using namespace std;

const int N = 1e6 + 10;
// const int N = 1e3 + 10;
const ll MOD = 1e9 + 7;

ll n, k;
string s;
// ll dp[N][N]; // pointer s last,
ll fac[N];

ll fpow(ll a, ll b) {
  ll ret = 1;
  while (b) {
    if (b & 1) {
      ret = ret * a % MOD;
    }
    b >>= 1;
    a = a * a % MOD;
  }
  return ret;
}
ll inv(ll a) { return fpow(a, MOD - 2); }
ll comb(ll n, ll k) { return fac[n] * inv(fac[n - k] * fac[k] % MOD) % MOD; }

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

  fac[0] = 1;
  for (ll i = 1; i < N; i++) {
    fac[i] = fac[i - 1] * i % MOD;
  }

  cin >> k;
  cin >> s;
  n = (ll)s.length();
  s = "*" + s;
  ll ans = 0;
  for (ll i = 0; i <= k; i++) {
    ll temp = (fpow(26, i) * fpow(25, k - i) % MOD) *
              comb(n + (k - i) - 1, (k - i)) % MOD;
    ans = ans + temp % MOD;
  }
  cout << ans << el;

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

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define DEBUG(x) cout << #x << "=" << x << endl
#define DEBUG2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
typedef long long ll;
// #define LOCAL
const int MAXN = 2e6 + 10;
const ll MOD = 1e9 + 7;
ll _gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return _gcd(b, a % b);
}
ll gcd(ll a, ll b) {
  a = abs(a), b = abs(b);
  if (a < b)
    swap(a, b);
  return _gcd(a, b);
}
ll qpow(ll a, ll n) {
  ll rt = 1;
  while (n) {
    if (n & 1)
      rt = (rt * a) % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return rt;
}
ll factor[MAXN];
void cal_factor() {
  factor[0] = 1;
  for (int u = 1; u < MAXN; u++) {
    factor[u] = (factor[u - 1] * u) % MOD;
  }
}
ll C(ll n, ll k) {
  return factor[n] * qpow(factor[n - k], MOD - 2) % MOD *
         qpow(factor[k], MOD - 2) % MOD;
}
void solve() {
  cal_factor();
  ll K, N;
  string s;
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> K >> s;
  N = K + s.size();
  ll ans = qpow(26, N);
  for (ll k = 0; k < s.size(); k++) {
    ans = (ans - C(N, k) * qpow(25, N - k) % MOD + MOD) % MOD;
  }
  cout << ans;
}
int main() {
#ifdef LOCAL
  freopen("in.txt", "r", stdin);
#endif
  solve();
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define DEBUG(x) cout << #x << "=" << x << endl
#define DEBUG2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
typedef long long ll;
// #define LOCAL
const int MAXN = 1e6 + 10;
const ll MOD = 1e9 + 7;
ll _gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return _gcd(b, a % b);
}
ll gcd(ll a, ll b) {
  a = abs(a), b = abs(b);
  if (a < b)
    swap(a, b);
  return _gcd(a, b);
}
ll qpow(ll a, ll n) {
  ll rt = 1;
  while (n) {
    if (n & 1)
      rt = (rt * a) % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return rt;
}
ll factor[MAXN];
void cal_factor() {
  factor[0] = 1;
  for (int u = 1; u < MAXN; u++) {
    factor[u] = (factor[u - 1] * u) % MOD;
  }
}
ll C(ll n, ll k) {
  return factor[n] * qpow(factor[n - k], MOD - 2) % MOD *
         qpow(factor[k], MOD - 2) % MOD;
}
void solve() {
  cal_factor();
  ll K, N;
  string s;
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> K >> s;
  N = K + s.size();
  ll ans = qpow(26, N);
  for (ll k = 0; k < s.size(); k++) {
    ans = (ans - C(N, k) * qpow(25, N - k) % MOD + MOD) % MOD;
  }
  cout << ans;
}
int main() {
#ifdef LOCAL
  freopen("in.txt", "r", stdin);
#endif
  solve();
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
#define _rep(n, a, b) for (int n = (a); n <= (b); ++n)
#define _rev(n, a, b) for (int n = (a); n >= (b); --n)
#define _for(n, a, b) for (int n = (a); n < (b); ++n)
#define _rof(n, a, b) for (int n = (a); n > (b); --n)
#define oo 0x3f3f3f3f3f3f
#define ll long long
#define db double
#define eps 1e-3
#define bin(x) cout << bitset<10>(x) << endl;
#define what_is(x) cerr << #x << " is " << x << endl
#define met(a, b) memset(a, b, sizeof(a))
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pdd pair<db, db>
#define endl "\\n"
const int mod = 1e9 + 7;
const int maxn = 2e6 + 10;
vector<ll> f(maxn), invf(maxn);
ll qpow(ll a, ll b) {
  ll ret = 1;
  for (; b; a = a * a % mod, b >>= 1) {
    if (b & 1) {
      ret = ret * a % mod;
    }
  }
  return ret;
}

void prework() {
  f[0] = 1;
  _rep(i, 1, maxn - 1) { f[i] = f[i - 1] * i % mod; }
  invf[maxn - 1] = qpow(f[maxn - 1], mod - 2);
  for (int i = maxn - 2; i >= 0; i--) {
    invf[i] = invf[i + 1] * (i + 1) % mod;
  }
}

ll C(ll n, ll m) {
  if (n > m || m < 0)
    return 0;
  if (n == 0 || m == n)
    return 1;
  ll res = (f[m] * invf[m - n] % mod * invf[n]) % mod;
  return res;
}
signed main() {
  int k;
  string s;
  cin >> k >> s;
  prework();
  ll len = s.size();
  ll res = 0;
  _rep(i, 0, k) {
    res = (res + qpow(26, i) * qpow(25, k - i) % mod *
                     C(len - 1, k + len - 1 - i) % mod) %
          mod;
  }
  cout << res << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
#define _rep(n, a, b) for (int n = (a); n <= (b); ++n)
#define _rev(n, a, b) for (int n = (a); n >= (b); --n)
#define _for(n, a, b) for (int n = (a); n < (b); ++n)
#define _rof(n, a, b) for (int n = (a); n > (b); --n)
#define oo 0x3f3f3f3f3f3f
#define ll long long
#define db double
#define eps 1e-3
#define bin(x) cout << bitset<10>(x) << endl;
#define what_is(x) cerr << #x << " is " << x << endl
#define met(a, b) memset(a, b, sizeof(a))
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pdd pair<db, db>
#define endl "\\n"
const int mod = 1e9 + 7;
const int maxn = 1e6 + 10;
vector<ll> f(maxn), invf(maxn);
ll qpow(ll a, ll b) {
  ll ret = 1;
  for (; b; a = a * a % mod, b >>= 1) {
    if (b & 1) {
      ret = ret * a % mod;
    }
  }
  return ret;
}

void prework() {
  f[0] = 1;
  _rep(i, 1, maxn - 1) { f[i] = f[i - 1] * i % mod; }
  invf[maxn - 1] = qpow(f[maxn - 1], mod - 2);
  for (int i = maxn - 2; i >= 0; i--) {
    invf[i] = invf[i + 1] * (i + 1) % mod;
  }
}

ll C(ll n, ll m) {
  if (n > m || m < 0)
    return 0;
  if (n == 0 || m == n)
    return 1;
  ll res = (f[m] * invf[m - n] % mod * invf[n]) % mod;
  return res;
}
signed main() {
  int k;
  string s;
  cin >> k >> s;
  prework();
  ll len = s.size();
  ll res = 0;
  _rep(i, 0, k) {
    res = (res + qpow(26, i) * qpow(25, k - i) % mod *
                     C(len - 1, k + len - 1 - i) % mod) %
          mod;
  }
  cout << res << endl;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
// #define int long long
#define ll long long
#define fi first
#define vi vector<int>
#define pii pair<int, int>
#define se second
using namespace std;
int t, a, b, c, x, y, k, n, q;
int F[2000006];
string s;
const int mod = 1e9 + 7;
int pw(int a, int n) {
  int y = 1;
  for (; n; n /= 2) {
    if (n & 1)
      y = 1ll * y * a % mod;
    a = 1ll * a * a % mod;
  }
  return y;
}
int inv(int n) { return pw(n, mod - 2); }

int C(int a, int b) {
  if (a < b || a == 0)
    return 0;
  return (1ll * F[a] * pw(F[b], mod - 2) % mod) * pw(F[a - b], mod - 2) % mod;
}

void factorial() {
  F[0] = 1;
  for (int i = 1; i < 2000003; i++)
    F[i] = 1ll * F[i - 1] * i % mod;
}

ll ans;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  factorial();
  cin >> k >> s;
  int m = s.size();
  int n = k + s.size();
  int ans = 0;
  for (int i = m; i <= n; i++) {
    ans = (ans + 1ll * C(n, i) * pw(25, n - i) % mod) % mod;
    //		cout << ans <<' ';
  }
  cout << ans;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
// #define int long long
#define ll long long
#define fi first
#define vi vector<int>
#define pii pair<int, int>
#define se second
using namespace std;
int t, a, b, c, x, y, k, n, q;
int F[1000006];
string s;
const int mod = 1e9 + 7;
int pw(int a, int n) {
  int y = 1;
  for (; n; n /= 2) {
    if (n & 1)
      y = 1ll * y * a % mod;
    a = 1ll * a * a % mod;
  }
  return y;
}
int inv(int n) { return pw(n, mod - 2); }

int C(int a, int b) {
  if (a < b || a == 0)
    return 0;
  return (1ll * F[a] * pw(F[b], mod - 2) % mod) * pw(F[a - b], mod - 2) % mod;
}

void factorial() {
  F[0] = 1;
  for (int i = 1; i < 1000003; i++)
    F[i] = 1ll * F[i - 1] * i % mod;
}

ll ans;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  factorial();
  cin >> k >> s;
  int m = s.size();
  int n = k + s.size();
  int ans = 0;
  for (int i = m; i <= n; i++) {
    ans = (ans + 1ll * C(n, i) * pw(25, n - i) % mod) % mod;
    //		cout << ans <<' ';
  }
  cout << ans;
}
Problem p02632 (C++) — buggy submission, verdict: Time Limit Exceeded

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

ll k, mod = 1e9 + 7, fac[2000010], pa[2][2000010];
string s;

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

ll comb(ll a, ll b) {
  if (a == b || b == 0)
    return 1;
  ll ans = fac[a];
  ans *= p(fac[b], mod - 2);
  ans %= mod;
  ans *= p(fac[a - b], mod - 2);
  ans %= mod;
  return ans;
}

int main() {
  cin >> k;
  cin >> s;
  pa[0][0] = 1, pa[1][0] = 1;
  for (int i = 0; i < 2000010; i++) {
    if (i < 2)
      fac[i] = 1;
    else
      fac[i] = fac[i - 1] * i;
    fac[i] %= mod;
    if (i > 0) {
      pa[0][i] = pa[0][i - 1] * 25;
      pa[0][i] %= mod;
      pa[1][i] = pa[1][i - 1] * 26;
      pa[1][i] %= mod;
    }
  }
  ll len = s.size(), n = len + k, ans = 0;
  for (int i = len - 1; i < n; i++) {
    // cout<<"i: "<<i<<endl;
    ll tambah = comb(i, len - 1) * pa[0][i - len + 1];
    tambah %= mod;
    // cout<<"test"<<endl;
    tambah *= pa[1][n - i - 1];
    tambah %= mod;
    ans += tambah;
    ans %= mod;
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

ll k, mod = 1e9 + 7, fac[2000010];
string s;

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

ll comb(ll a, ll b) {
  if (a == b || b == 0)
    return 1;
  ll ans = fac[a];
  ans *= p(fac[b], mod - 2);
  ans %= mod;
  ans *= p(fac[a - b], mod - 2);
  ans %= mod;
  return ans;
}

int main() {
  cin >> k;
  cin >> s;
  for (int i = 0; i < 2000010; i++) {
    if (i < 2)
      fac[i] = 1;
    else
      fac[i] = fac[i - 1] * i;
    fac[i] %= mod;
  }
  ll len = s.size(), n = len + k, ans = 0;
  for (int i = len - 1; i < n; i++) {
    // cout<<"i: "<<i<<endl;
    ll tambah = comb(i, len - 1) * p(25, i - len + 1);
    tambah %= mod;
    // cout<<"test"<<endl;
    tambah *= p(26, n - i - 1);
    tambah %= mod;
    ans += tambah;
    ans %= mod;
  }
  cout << ans << endl;
}