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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll Max = 2e6 + 10, N = 2e6 + 100, mod = 1e9 + 7;

ll fct[N], k, ans, n;
string s;

ll qmi(ll a, ll b) {
  ll res = 1;
  while (b) {
    if (b & 1)
      res = res * a % mod;
    b >>= 1;
    a = a * a % mod;
  }
  return res;
}
ll C(ll a, ll b) {
  if (a < b)
    return 0;
  return fct[a] * qmi(fct[b], mod - 2) % mod * qmi(fct[a - b], mod - 2) % mod;
}
void init() {
  fct[0] = 1;
  for (ll i = 1; i <= Max; i++)
    fct[i] = fct[i - 1] * i % mod;
}

int main() {
  cin >> k;
  cin >> s;
  init();
  // wa
  ll len = s.size();
  n = len + k;
  ans = 0;
  for (ll i = len; i <= n; i++) {
    // C(i-1,len-1);
    // qmi(25,i-len);
    // qmi(26,n-i)%mod;
    // ans+C(i-1,len-1)*qmi(25,i-len)%mod;
    // ans+C(i-1,len-1)*qmi(25,i-len)%mod*qmi(26,n-i)%mod;
    // ll t=(C(i-1,len-1)*qmi(25,i-len)%mod*qmi(26,n-i)%mod)%mod;
    // ans = ((ans+t)%mod+mod)%mod;
    ans = (ans +
           C(i - 1, len - 1) * qmi(25, i - len) % mod * qmi(26, n - i) % mod) %
          mod;
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll Max = 1e6 + 10, N = 1e6 + 100, mod = 1e9 + 7;

ll fct[N], k, ans, n;
string s;

ll qmi(ll a, ll b) {
  ll res = 1;
  while (b) {
    if (b & 1)
      res = res * a % mod;
    b >>= 1;
    a = a * a % mod;
  }
  return res;
}
ll C(ll a, ll b) {
  if (a < b)
    return 0;
  return fct[a] * qmi(fct[b], mod - 2) % mod * qmi(fct[a - b], mod - 2) % mod;
}
void init() {
  fct[0] = 1;
  for (ll i = 1; i <= Max; i++)
    fct[i] = fct[i - 1] * i % mod;
}
int main() {
  cin >> k;
  cin >> s;
  init();
  // wa
  ll len = s.size();
  n = len + k;
  ans = 0;
  for (ll i = len; i <= n; i++) {
    // C(i-1,len-1);
    // qmi(25,i-len);
    // qmi(26,n-i)%mod;
    // ans+C(i-1,len-1)*qmi(25,i-len)%mod;
    // ans+C(i-1,len-1)*qmi(25,i-len)%mod*qmi(26,n-i)%mod;
    ll t = (C(i - 1, len - 1) * qmi(25, i - len) % mod * qmi(26, n - i) % mod) %
           mod;
    ans = ((ans + t) % mod + mod) % mod;
    // ans=(ans+C(i-1,len-1)*qmi(25,i-len)%mod*qmi(26,n-i)%mod)%mod;
  }
  cout << ans << endl;
  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1 << 21;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

// DAME:
ll power(ll x, ll n, ll M) {
  ll res = 1;
  if (n > 0) {
    res = power(x, n / 2, M);
    if (n % 2 == 0)
      res = (res * res) % M;
    else
      res = (((res * res) % M) * x) % M;
  }
  return res;
}

const ll MAX = 4000000;
ll fac[MAX], finv[MAX], inv[MAX];
void cominit() {
  fac[0] = fac[1] = 1LL;
  finv[0] = finv[1] = 1LL;
  inv[1] = 1LL;

  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 0LL;
  if (n < 0 or k < 0)
    return 0LL;
  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cominit();
  ll k;
  string s;
  cin >> k;
  cin >> s;
  ll n = s.size();
  ll ans = 0;

  for (ll i = n; i <= n + k; i++) {
    ll aa = power(26LL, n + k - i, mod) * power(25LL, i - n, mod) % mod;
    aa = aa * com(i - 1, n - 1) % mod;
    ans = (ans + aa) % mod;
  }
  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1 << 21;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

// DAME:
ll power(ll x, ll n, ll M) {
  ll res = 1;
  if (n > 0) {
    res = power(x, n / 2, M);
    if (n % 2 == 0)
      res = (res * res) % M;
    else
      res = (((res * res) % M) * x) % M;
  }
  return res;
}

const ll MAX = 40000000;
ll fac[MAX], finv[MAX], inv[MAX];
void cominit() {
  fac[0] = fac[1] = 1LL;
  finv[0] = finv[1] = 1LL;
  inv[1] = 1LL;

  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 0LL;
  if (n < 0 or k < 0)
    return 0LL;
  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cominit();
  ll k;
  string s;
  cin >> k;
  cin >> s;
  ll n = s.size();
  ll ans = 0;

  for (ll i = n; i <= n + k; i++) {
    ll aa = power(26LL, n + k - i, mod) * power(25LL, i - n, mod) % mod;
    aa = aa * com(i - 1, n - 1) % mod;
    ans = (ans + aa) % mod;
  }
  cout << ans << endl;

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

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

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

int main() {
  // 前処理
  COMinit();
  int k;
  cin >> k;
  string s;
  cin >> s;
  int n = s.size();
  vector<long long> a(n + k + 1, 1), b(n + k + 1, 1);
  for (int i = 0; i < n + k; ++i) {
    a[i + 1] = a[i] * 25;
    a[i + 1] %= MOD;
    b[i + 1] = b[i] * 26;
    b[i + 1] %= MOD;
  }
  long long ans = 0;
  for (int i = 0; i <= k; ++i) {
    ans += COM(n + i - 1, n - 1) * a[i] % MOD * b[k - i];
    ans %= MOD;
  }
  // 計算例
  cout << ans << endl;
}


Error: 0

Fixed submission:

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

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 n = s.size();
  vector<long long> a(n + k + 1, 1), b(n + k + 1, 1);
  for (int i = 0; i < n + k; ++i) {
    a[i + 1] = a[i] * 25;
    a[i + 1] %= MOD;
    b[i + 1] = b[i] * 26;
    b[i + 1] %= MOD;
  }
  long long ans = 0;
  for (int i = 0; i <= k; ++i) {
    ans += COM(n + i - 1, n - 1) * a[i] * b[k - i];
    ans %= MOD;
  }
  // 計算例
  cout << ans << endl;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long

using namespace std;

const ll mod = 1e9 + 7;
ll k, fact[2000005], ans;
string s;

ll find(ll x) {
  if (x == 1)
    return x;
  return (mod - mod / x) * find(mod % x) % mod;
}

ll comb(ll x, ll y) {
  return (fact[y] * find(fact[y - x]) % mod * find(fact[x])) % mod;
}

int main() {
  cin >> k >> s;
  fact[0] = 1;
  for (ll i = 1; i <= 2000000; i++) {
    fact[i] = fact[i - 1] * i % mod;
  }
  ll pow = 1;
  for (ll i = 1; i <= k; i++)
    pow = pow * 25 % mod;
  for (ll i = 0; i <= k; i++) {
    ans = (ans + pow * comb(s.length() - 1, k - i + s.length() - 1)) % mod;
    pow = (pow * find(25) * 26) % mod;
  }
  if (ans < 0)
    ans += mod;
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long

using namespace std;

const ll mod = 1e9 + 7;
ll k, fact[1000005], ans;
string s;

ll find(ll x) {
  if (x == 1)
    return x;
  return (mod - mod / x) * find(mod % x) % mod;
}

ll comb(ll x, ll y) {
  return (fact[y] * find(fact[y - x]) % mod * find(fact[x])) % mod;
}

int main() {
  cin >> k >> s;
  fact[0] = 1;
  for (ll i = 1; i <= 1000000; i++) {
    fact[i] = fact[i - 1] * i % mod;
  }
  ll pow = 1;
  for (ll i = 1; i <= k; i++)
    pow = pow * 25 % mod;
  for (ll i = 0; i <= k; i++) {
    ans = (ans + pow * comb(s.length() - 1, k - i + s.length() - 1)) % mod;
    pow = (pow * find(25) * 26) % mod;
  }
  if (ans < 0)
    ans += mod;
  cout << ans << endl;
  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

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

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

int K;
string s;

int main() {
  COMinit();

  cin >> K >> s;
  int S = static_cast<int>(s.size());

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

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

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

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

int K;
string s;

int main() {
  COMinit();

  cin >> K >> s;
  int S = static_cast<int>(s.size());

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

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

#include <bits/stdc++.h>

#define endl '\\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
const int MOD = 1e9 + 7;
const int maxn = 2e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;
const double PI = acos(-1.0);

void header() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

ll fac[maxn], inv[maxn];

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

void init() {
  fac[0] = 1;
  for (int i = 1; i < maxn; i++)
    fac[i] = fac[i - 1] * i % MOD;
  inv[maxn - 1] = qpow(fac[maxn - 1], MOD - 2);
  for (int i = maxn - 2; i >= 0; i--)
    inv[i] = inv[i + 1] * (i + 1) % MOD;
}

ll C(int n, int m) { return fac[n] * inv[m] % MOD * inv[n - m] % MOD; }

void solve() {
  int k;
  string s;
  cin >> k >> s;
  init();
  ll res = 0;
  int n = s.size();
  for (int i = 0; i <= k; i++) {
    int last = k - i;
    res += qpow(26, i) * qpow(25, last) % MOD * C(last + n - 1, n - 1) % MOD;
    res %= MOD;
  }
  cout << res << endl;
}

int main() {
  header();
  solve();
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define endl '\\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;
const double PI = acos(-1.0);

void header() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

ll fac[maxn], inv[maxn];

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

void init() {
  fac[0] = 1;
  for (int i = 1; i < maxn; i++)
    fac[i] = fac[i - 1] * i % MOD;
  inv[maxn - 1] = qpow(fac[maxn - 1], MOD - 2);
  for (int i = maxn - 2; i >= 0; i--)
    inv[i] = inv[i + 1] * (i + 1) % MOD;
}

ll C(int n, int m) { return fac[n] * inv[m] % MOD * inv[n - m] % MOD; }

void solve() {
  int k;
  string s;
  cin >> k >> s;
  init();
  ll res = 0;
  int n = s.size();
  for (int i = 0; i <= k; i++) {
    int last = k - i;
    res += qpow(26, i) * qpow(25, last) % MOD * C(last + n - 1, n - 1) % MOD;
    res %= MOD;
  }
  cout << res << endl;
}

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

#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ll long long
#define maxn 2000005
#define inf 1e9
#define pb push_back
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
using namespace std;

inline ll read() {
  ll x = 0, w = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      w = -1;
    c = getchar();
  }
  while (c <= '9' && c >= '0') {
    x = (x << 1) + (x << 3) + c - '0';
    c = getchar();
  }
  return w == 1 ? x : -x;
}

ll fac[maxn], inv[maxn], n, k;
char s[maxn];
const ll mod = 1000000007;

inline ll pw(ll a, ll b) {
  ll ans = 1, base = a;
  while (b) {
    if (b & 1)
      ans = (ans * base) % mod;
    base = (base * base) % mod;
    b >>= 1;
  }
  return ans;
}

inline ll C(int N, int M) { return (fac[N] * inv[M] % mod) * inv[N - M] % mod; }

int main() {
  fac[0] = 1;
  inv[0] = 1;
  ll n = read(), ans = 0;
  scanf("%s", s + 1);
  k = strlen(s + 1);
  rep(i, 1, (maxn - 5)) fac[i] = (fac[i - 1] * i) % mod;
  rep(i, 1, (maxn - 5)) inv[i] = pw(fac[i], mod - 2);
  rep(i, 0, n) {
    ll p = (pw(26, n - i) % mod * pw(25, i) % mod) % mod;
    p = (p * C(k + i - 1, i)) % mod;
    ans = (ans + p) % mod;
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
using namespace std;

inline int read() {
  int x = 0, w = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      w = -1;
    c = getchar();
  }
  while (c <= '9' && c >= '0') {
    x = (x << 1) + (x << 3) + c - '0';
    c = getchar();
  }
  return w == 1 ? x : -x;
}

ll fac[maxn], inv[maxn], n, k;
char s[maxn];
const ll mod = 1000000007;

inline ll pw(ll a, ll b) {
  ll ans = 1, base = a;
  while (b) {
    if (b & 1)
      ans = (ans * base) % mod;
    base = (base * base) % mod;
    b >>= 1;
  }
  return ans;
}

inline ll C(int N, int M) { return (fac[N] * inv[M] % mod) * inv[N - M] % mod; }

int main() {
  fac[0] = 1;
  inv[0] = 1;
  ll n = read(), ans = 0;
  scanf("%s", s + 1);
  k = strlen(s + 1);
  rep(i, 1, (maxn - 5)) fac[i] = (fac[i - 1] * i) % mod;
  rep(i, 1, (maxn - 5)) inv[i] = pw(fac[i], mod - 2);
  rep(i, 0, n) {
    ll p = (pw(26, n - i) * pw(25, i)) % mod;
    p = (p * C(k + i - 1, i)) % mod;
    ans = (ans + p) % mod;
  }
  cout << ans << endl;
  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int Max_N = 1e6;
const long long Mod = (1e9) + 7;
int n, m;
char s[Max_N + 10];
long long ans = 0, p[Max_N * 2 + 10] = {}, inv[Max_N * 2 + 10] = {};
inline long long Mul(int x, int y) {
  long long a = 1, b = x;
  for (; y; b = b * b % Mod, y >>= 1)
    if (y & 1)
      a = a * b % Mod;
  return a;
}
inline long long C(int n, int m) {
  return p[n] * inv[m] % Mod * inv[n - m] % Mod;
}
int main() {
  scanf("%d", &n);
  scanf("%s", s);
  m = strlen(s);
  p[0] = 1;
  for (int i = 1; i <= n + m; i++)
    p[i] = p[i - 1] * i % Mod;
  inv[0] = inv[1] = 1;
  for (int i = 2; i <= n + m; i++)
    inv[i] = inv[Mod % i] * (Mod - Mod / i) % Mod;
  for (int i = 1; i <= n + m; i++)
    inv[i] = inv[i - 1] * inv[i] % Mod;
  for (int i = 0; i <= n; i++)
    ans += C(n + m - i - 1, m - 1) * Mul(26, i) % Mod * Mul(25, n - i) % Mod,
        ans %= Mod;
  printf("%lld\\n", ans);
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int Max_N = 1e5;
const long long Mod = (1e9) + 7;
int n, m;
char s[Max_N + 10];
long long ans = 0, p[Max_N * 2 + 10] = {}, inv[Max_N * 2 + 10] = {};
inline long long Mul(int x, int y) {
  long long a = 1, b = x;
  for (; y; b = b * b % Mod, y >>= 1)
    if (y & 1)
      a = a * b % Mod;
  return a;
}
inline long long C(int n, int m) {
  return p[n] * inv[m] % Mod * inv[n - m] % Mod;
}
int main() {
  scanf("%d", &n);
  scanf("%s", s);
  m = strlen(s);
  p[0] = 1;
  for (int i = 1; i <= n + m; i++)
    p[i] = p[i - 1] * i % Mod;
  inv[0] = inv[1] = 1;
  for (int i = 2; i <= n + m; i++)
    inv[i] = inv[Mod % i] * (Mod - Mod / i) % Mod;
  for (int i = 1; i <= n; i++)
    inv[i] = inv[i - 1] * inv[i] % Mod;
  for (int i = 0; i <= n; i++)
    ans += C(n + m - i - 1, m - 1) * Mul(26, i) % Mod * Mul(25, n - i) % Mod,
        ans %= Mod;
  printf("%lld\\n", ans);
  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int, int> ii;

int fact[2000005];
int mod = 1000000007;
long long qexp(long long b, long long p) {
  long long res = 1;
  while (p) {
    if (p & 1)
      res = (res * b) % mod;
    b = (b * b) % mod;
    p >>= 1;
  }
  return res;
}
int inv(long long b) { return qexp(b, mod - 2); }
int choose(int N, int C) {
  if (N < C)
    return 0;
  int res = fact[N];
  res *= inv(fact[C]);
  res %= mod;
  res *= inv(fact[N - C]);
  res %= mod;
  return res;
}

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

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

  int N;
  cin >> N;

  string S;
  cin >> S;

  int M = S.size();

  int ans = 0;
  for (int e = 0; e <= N; e++) {
    int other = N - e;

    int res = qexp(26, e) * qexp(25, other);
    res %= mod;

    res *= choose(M + other - 1, other);
    res %= mod;

    ans += res;
    ans %= mod;

    // cout << qexp(26, e) << " " << qexp(25, other) << " " << choose(M+other-1,
    // other) << " " << M << " " << other << "\\n";

    // cout << ans << "\\n";
  }

  cout << ans;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int, int> ii;

int fact[1000005];
int mod = 1000000007;
long long qexp(long long b, long long p) {
  long long res = 1;
  while (p) {
    if (p & 1)
      res = (res * b) % mod;
    b = (b * b) % mod;
    p >>= 1;
  }
  return res;
}
int inv(long long b) { return qexp(b, mod - 2); }
int choose(int N, int C) {
  int res = fact[N];
  res *= inv(fact[C]);
  res %= mod;
  res *= inv(fact[N - C]);
  res %= mod;
  return res;
}

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

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

  int N;
  cin >> N;

  string S;
  cin >> S;

  int M = S.size();

  int ans = 0;
  for (int e = 0; e <= N; e++) {
    int other = N - e;

    int res = qexp(26, e) * qexp(25, other);
    res %= mod;

    res *= choose(M + other - 1, other);
    res %= mod;

    ans += res;
    ans %= mod;

    // cout << qexp(26, e) << " " << qexp(25, other) << " " << choose(M+other-1,
    // other) << " " << M << " " << other << "\\n";

    // cout << ans << "\\n";
  }

  cout << ans;
}
Problem p02632 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
#include <string>
using ull = unsigned long long;
const static int MOD = 1000000007;
ull RepeatSquaring(ull N, ull P) {
  if (P == 0 || N == 1)
    return 1;
  if (N == -1)
    return P & 1 ? -1 : 1;
  if (!(P & 1)) {
    ull t = RepeatSquaring(N, P >> 1);
    return t * t % MOD;
  }
  // Pが偶数のときN^(P/2)を求めてからそれの2乗を返す
  return N * RepeatSquaring(N, P - 1) % MOD;
  // Pが奇数のときN^((P - 1)/2)を求めてからそれの2乗を返す
}

/*
組合せ(nCr)
O(min(r, n - r) + log(MOD))
*/
ull Combination(ull n, ull r) {
  if (n - r < r)
    r = n - r;
  ull numerator = 1, denominator = 1;
  for (ull i = 0; i < r; ++i) {
    numerator = numerator * ((n - i) % MOD) % MOD;
    denominator = denominator * ((i + 1) % MOD) % MOD;
  }
  return numerator * RepeatSquaring(denominator, MOD - 2) % MOD;
}

int main() {
  ull K;
  scanf("%llu", &K);
  std::string S;
  std::cin >> S;
  ull sz = S.size();
  ull answer = 1;
  ull power = 1, cmb = sz;
  for (size_t i = sz; i < K + sz; i++) {
    power = power * 25 % MOD;
    answer = (answer * 26 % MOD + cmb * power % MOD) % MOD;
    cmb = cmb * (i + 1) % MOD * RepeatSquaring(i + 2 - sz, MOD - 2) % MOD;
  }
  printf("%llu\\n", answer);
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
#include <string>
using ull = unsigned long long;
const static int MOD = 1000000007;
ull RepeatSquaring(ull N, ull P) {
  if (P == 0 || N == 1)
    return 1;
  if (N == -1)
    return P & 1 ? -1 : 1;
  if (!(P & 1)) {
    ull t = RepeatSquaring(N, P >> 1);
    return t * t % MOD;
  }
  // Pが偶数のときN^(P/2)を求めてからそれの2乗を返す
  return N * RepeatSquaring(N, P - 1) % MOD;
  // Pが奇数のときN^((P - 1)/2)を求めてからそれの2乗を返す
}

/*
組合せ(nCr)
O(min(r, n - r) + log(MOD))
*/
ull Combination(ull n, ull r) {
  if (n - r < r)
    r = n - r;
  ull numerator = 1, denominator = 1;
  for (ull i = 0; i < r; ++i) {
    numerator = numerator * ((n - i) % MOD) % MOD;
    denominator = denominator * ((i + 1) % MOD) % MOD;
  }
  return numerator * RepeatSquaring(denominator, MOD - 2) % MOD;
}

int main() {
  ull K;
  scanf("%llu", &K);
  std::string S;
  std::cin >> S;
  ull sz = S.size();
  ull answer = 1;
  for (size_t i = sz; i < K + sz; i++) {
    answer = (answer * 26 % MOD +
              Combination(i, sz - 1) * RepeatSquaring(25, i - sz + 1)) %
             MOD;
  }
  printf("%llu\\n", answer);
  return 0;
}