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

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const int N = 2e6 + 5;
const ll mod = 1e9 + 7;
int k, n;
string s;
ll f[N], inv[N];

ll pw(ll x, ll i) {
  ll b = 1;
  for (; i; i >>= 1, x = x * x % mod)
    if (i & 1)
      b = b * x % mod;
  return b;
}
ll ckn(int n, int k) { return f[n] * inv[k] % mod * inv[n - k] % mod; }

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

  cin >> k >> s;
  n = s.size();
  s = ' ' + s;

  ll ans = 0;
  f[0] = 1;
  for (int i = 1; i <= n + k; ++i)
    f[i] = f[i - 1] * i % mod;
  inv[n + k] = pw(f[n + k], mod - 2);
  for (int i = n + k; i >= 1; --i)
    inv[i - 1] = inv[i] * i % mod;
  for (int i = 0; i <= k; ++i) {
    ll tmp = pw(25, k - i) * pw(26, i) % mod * ckn(k - i + n - 1, n - 1) % mod;
    ans = (ans + tmp) % mod;
  }
  cout << ans << '\\n';
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const int N = 1e6 + 5;
const ll mod = 1e9 + 7;
int k, n;
string s;
ll f[N], inv[N];

ll pw(ll x, ll i) {
  ll b = 1;
  for (; i; i >>= 1, x = x * x % mod)
    if (i & 1)
      b = b * x % mod;
  return b;
}
ll ckn(int n, int k) { return f[n] * inv[k] % mod * inv[n - k] % mod; }

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

  cin >> k >> s;
  n = s.size();
  s = ' ' + s;

  ll ans = 0;
  f[0] = 1;
  for (int i = 1; i <= n + k; ++i)
    f[i] = f[i - 1] * i % mod;
  inv[n + k] = pw(f[n + k], mod - 2);
  for (int i = n + k; i >= 1; --i)
    inv[i - 1] = inv[i] * i % mod;
  for (int i = 0; i <= k; ++i) {
    ll tmp = pw(25, k - i) * pw(26, i) % mod * ckn(k - i + n - 1, n - 1) % mod;
    ans = (ans + tmp) % mod;
  }
  cout << ans << '\\n';
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cassert>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string.h>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 2e18;
const ll MOD = 1e9 + 7;

ll modpow(ll x, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

const ll MAX = 2000000;
ll fac[MAX], finv[MAX], inv[MAX];
// nCk初期化
void nCkInit(const ll MOD) { // O(max(n,r)logmax(n,r) mは素数)
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (ll 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 nCk(ll n, ll k, const ll MOD) { // init後,O(1)
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll K;
string S;
map<char, ll> mp;
int main() {
  cin >> K >> S;
  nCkInit(MOD);
  ll ans = 0;
  for (ll i = 0; i <= K; i++) {
    ans = (ans + nCk(K + S.length() - 1 - i, S.length() - 1, MOD) *
                     modpow(25, K - i, MOD) % MOD * modpow(26, i, MOD) % MOD) %
          MOD;
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cassert>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string.h>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 2e18;
const ll MOD = 1e9 + 7;

ll modpow(ll x, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

const ll MAX = 1000000;
ll fac[MAX], finv[MAX], inv[MAX];
// nCk初期化
void nCkInit(const ll MOD) { // O(max(n,r)logmax(n,r) mは素数)
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (ll 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 nCk(ll n, ll k, const ll MOD) { // init後,O(1)
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll K;
string S;
map<char, ll> mp;
int main() {
  cin >> K >> S;
  nCkInit(MOD);
  ll ans = 0;
  for (ll i = 0; i <= K; i++) {
    ans = (ans + nCk(K + S.length() - 1 - i, S.length() - 1, MOD) *
                     modpow(25, K - i, MOD) % MOD * modpow(26, i, MOD) % MOD) %
          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 int N = 2e6 + 5;
long long fac[N] = {};
long long inv(long long x) {
  if (x == 1)
    return 1;
  return (mod - mod / x) * inv(mod % x) % mod;
}
void init() {
  fac[0] = 1;
  for (long long i = 1; i < N; i++)
    fac[i] = fac[i - 1] * i % mod;
}
long long ksm(long long a, long long b) {
  if (b == 0)
    return 1;
  if (b & 1)
    return a * ksm(a * a % mod, b >> 1) % mod;
  return ksm(a * a % mod, b >> 1);
}
long long C(long long a, long long b) {
  return fac[a] * inv(fac[b] * fac[a - b] % mod) % mod;
}
int main() {
  string str;
  init();
  long long k, len;
  cin >> k >> str;
  len = str.size();
  long long ans = 0;
  for (long long i = len; i <= k + len; i++)
    ans = (ans + (C(i - 1, len - 1) * ksm(26, len + k - i) % mod) *
                     ksm(25, i - len)) %
          mod;
  cout << ans << '\\n';
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int N = 1e6 + 5;
bool cnt[30] = {};
long long fac[N] = {};
long long inv(long long x) {
  if (x == 1)
    return 1;
  return (mod - mod / x) * inv(mod % x) % mod;
}
void init() {
  fac[0] = 1;
  for (long long i = 1; i < N; i++)
    fac[i] = fac[i - 1] * i % mod;
}
long long ksm(long long a, long long b) {
  if (b == 0)
    return 1;
  if (b & 1)
    return a * ksm(a * a % mod, b >> 1) % mod;
  return ksm(a * a % mod, b >> 1);
}
long long C(long long a, long long b) {
  return fac[a] * inv(fac[b] * fac[a - b] % mod) % mod;
}
int main() {
  string str;
  init();
  long long k, len;
  cin >> k >> str;
  len = str.size();
  long long ans = 0;
  for (long long i = len; i <= k + len; i++)
    ans = (ans + (C(i - 1, len - 1) * ksm(26, len + k - i) % mod) *
                     ksm(25, i - len)) %
          mod;
  cout << ans << '\\n';
  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
typedef long double ldouble;

using Graph = vector<vector<int>>;

llong POW(llong a, llong b) {
  if (b == 0)
    return 1;
  else {
    if (b % 2 == 0)
      return POW(a * a % MOD, b / 2) % MOD;
    else
      return a * POW(a * a % MOD, b / 2) % MOD;
  }
}

llong COMB(llong a, llong b) {
  llong ans = 1;
  for (llong i = 1; i <= b; ++i) {
    ans *= a + 1 - i;
    ans %= MOD;
    ans *= POW(i, MOD - 2);
    ans %= MOD;
  }
  return ans;
}

int main() {
  llong K;
  cin >> K;
  string S;
  cin >> S;
  llong SIZE = S.length();
  llong ans = 0;
  llong comb = COMB(K + SIZE - 1, SIZE - 1) % MOD;
  for (llong i = 0; i <= K; ++i) {
    if (i != 0) {
      comb *= POW(K + SIZE - 1 - i + 1, MOD - 2);
      comb %= MOD;
      comb *= K - i + 1;
      comb %= MOD;
    }
    ans += comb % MOD * POW(25, K - i) % MOD * POW(26, i) % MOD;
    ans %= MOD;
  }
  if (ans < 0)
    ans += MOD;
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
typedef long double ldouble;

using Graph = vector<vector<int>>;

llong POW(llong a, llong b) {
  if (b == 0)
    return 1;
  else {
    if (b % 2 == 0)
      return POW(a * a % MOD, b / 2) % MOD;
    else
      return a * POW(a * a % MOD, b / 2) % MOD;
  }
}

llong COMB(llong a, llong b) {
  llong ans = 1;
  for (llong i = 1; i <= b; ++i) {
    ans *= a + 1 - i;
    ans %= MOD;
    ans *= POW(i, MOD - 2);
    ans %= MOD;
  }
  return ans;
}

int main() {
  llong K;
  cin >> K;
  string S;
  cin >> S;
  llong SIZE = S.length();
  llong ans = 0;
  for (llong i = 0; i <= K; ++i) {
    ans += COMB(K + SIZE - i - 1, SIZE - 1) % MOD * POW(25, K - i) % MOD *
           POW(26, i) % MOD;
    ans %= MOD;
  }
  if (ans < 0)
    ans += MOD;
  cout << ans << endl;
}
Problem p02632 (C++) — buggy submission, verdict: Time Limit Exceeded

#pragma GCC optimize("O2")
#pragma GCC target("avx2")
// #include<bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int mod = 1e9 + 7;
const int IMAX = 2000010;
constexpr ll modpow(ll A, ll B) {
  ll kotae = 1;
  while (B > 0) {
    if (B & 1)
      kotae = kotae * A % mod;
    A = A * A % mod;
    B >>= 1;
  }
  return kotae;
}
class unko {
public:
  int inv[IMAX + 1];
  unko() : inv() {
    inv[0] = 1;
    inv[1] = 1;
    rep1(i, IMAX - 1) inv[i + 1] = ll(inv[i]) * i % mod;
    ll tmp = modpow(ll(inv[IMAX]) * IMAX % mod, mod - 2);
    for (int i = IMAX; i > 0; i--) {
      inv[i] = inv[i] * tmp % mod;
      tmp = tmp * i % mod;
    }
  }
} f;

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

  int K;
  cin >> K;

  string S;
  cin >> S;

  int M = S.size();

  const ll are = 423076927;
  ll tmp = modpow(26, K);
  ll kotae = 0;
  rep(i, K + 1) {
    tmp = tmp * f.inv[i] % mod;
    kotae += tmp;
    tmp = tmp * (M + i) % mod;
    tmp = tmp * are % mod;
  }

  co(kotae % mod);

  Would you please return 0;
}

Error: TLE

Fixed submission:

#pragma GCC optimize("O2")
#pragma GCC target("avx2")
// #include<bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int mod = 1e9 + 7;
const int IMAX = 2000010;
constexpr ll modpow(ll A, ll B) {
  ll kotae = 1;
  while (B > 0) {
    if (B & 1)
      kotae = kotae * A % mod;
    A = A * A % mod;
    B >>= 1;
  }
  return kotae;
}
class unko {
public:
  int inv[IMAX + 1];
  unko() : inv() {
    inv[0] = 1;
    inv[1] = 1;
    rep1(i, IMAX - 1) inv[i + 1] = ll(inv[i]) * i % mod;
    ll tmp = modpow(ll(inv[IMAX]) * IMAX % mod, mod - 2);
    for (int i = IMAX; i > 0; i--) {
      inv[i] = inv[i] * tmp % mod;
      tmp = tmp * i % mod;
    }
  }
} f;

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

  int K;
  cin >> K;

  string S;
  cin >> S;

  int M = S.size();

  const ll are = 423076927;
  ll tmp = modpow(26, K);
  ll kotae = 0;
  rep(i, K + 1) {
    ce(f.inv[i]);
    tmp = tmp * f.inv[i] % mod;
    kotae += tmp;
    tmp = tmp * (M + i) % mod;
    tmp = tmp * are % mod;
  }

  co(kotae % mod);

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

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

using ll = long long;

const ll MOD = 1e9 + 7;
const int MX = 2e6 + 5;

ll n;
ll ans = 1;

ll fac[MX], inv[MX];

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

ll combo(ll t, ll k) {
  ll res = 1;
  res = res * fac[t] % MOD;
  res = res * inv[k] % MOD;
  res = res * inv[t - k] % MOD;
  return res;
}

int main() {
  int k;
  string ss;
  cin >> k >> ss;

  int sz = ss.size();
  fac[0] = fac[1] = 1;
  inv[0] = inv[1] = 1;
  for (int i = 2; i <= MX - 5; ++i) {
    fac[i] = i * fac[i - 1] % MOD;
    inv[i] = binpow(fac[i], MOD - 2);
  }

  long long answer = 0;
  for (int i = sz; i <= sz + k; i++) {
    answer += (combo(sz + k, i) * binpow(25, sz + k - i) % MOD);
    answer %= MOD;
  }

  cout << answer % MOD << endl;
}


Error: 0

Fixed submission:

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

using ll = long long;

const ll MOD = 1e9 + 7;
const int MX = 1e6 + 5;

ll n;
ll ans = 1;

ll fac[MX], inv[MX];

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

ll combo(ll t, ll k) {
  ll res = 1;
  res = res * fac[t] % MOD;
  res = res * inv[k] % MOD;
  res = res * inv[t - k] % MOD;
  return res;
}

int main() {
  int k;
  string ss;
  cin >> k >> ss;

  int sz = ss.size();
  fac[0] = fac[1] = 1;
  inv[0] = inv[1] = 1;
  for (int i = 2; i <= MX - 5; ++i) {
    fac[i] = i * fac[i - 1] % MOD;
    inv[i] = binpow(fac[i], MOD - 2);
  }

  long long answer = 0;
  for (int i = sz; i <= sz + k; i++) {
    answer +=
        ((combo(sz + k, i) % MOD) * 1LL * (binpow(25, sz + k - i) % MOD)) % MOD;
    answer %= MOD;
  }

  cout << answer % MOD << endl;
}
Problem p02632 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define ld long double
#define f first
#define s second
const int N = 2e6 + 5;

ll fact[N], inv[N], pw[N], pw2[N], mod = 1e9 + 7, k;
string s;

ll fp(ll base, ll exp) {
  if (exp == 0)
    return 1;
  ll ans = fp(base, exp / 2);
  ans = (ans * ans) % mod;
  if (exp % 2 != 0)
    ans = (ans * (base % mod)) % mod;
  return ans;
}

void calcFacAndInv(ll n) {
  pw[0] = 1, pw2[0] = 1;
  fact[0] = inv[0] = 1;
  for (ll i = 1; i <= n; i++) {
    pw[i] = (25 * pw[i - 1]) % mod;
    pw2[i] = (26 * pw2[i - 1]) % mod;
    fact[i] = (i * fact[i - 1]) % mod;
    inv[i] = fp(fact[i], mod - 2);
  }
}

ll ncr(ll n, ll r) { return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod; }

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

  calcFacAndInv(N - 1);

  cin >> k >> s;

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

  for (int i = sz; i <= n; i++) {
    ll tmp = (ncr(i - 1, sz - 1) * pw[i - sz]) % mod;
    tmp = (tmp * pw2[n - i]) % mod;
    ans = (ans + tmp) % mod;
  }

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

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define ld long double
#define f first
#define s second
const int N = 2e6 + 5;

ll fact[N], inv[N], mod = 1e9 + 7, k;
string s;

ll fp(ll base, ll exp) {
  if (exp == 0)
    return 1;
  ll ans = fp(base, exp / 2);
  ans = (ans * ans) % mod;
  if (exp % 2 != 0)
    ans = (ans * (base % mod)) % mod;
  return ans;
}

void calcFacAndInv(ll n) {
  fact[0] = inv[0] = 1;
  for (ll i = 1; i <= n; i++) {
    fact[i] = (i * fact[i - 1]) % mod;
    inv[i] = fp(fact[i], mod - 2);
  }
}

ll ncr(ll n, ll r) { return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod; }

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

  calcFacAndInv(N - 1);

  cin >> k >> s;

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

  for (int i = sz; i <= n; i++) {
    ll tmp = (ncr(i - 1, sz - 1) * fp(25, i - sz)) % mod;
    tmp = (tmp * fp(26, n - i)) % mod;
    ans = (ans + tmp) % mod;
  }

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

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

#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits.h>
#include <map>
#include <set>
#include <utility>
#include <vector>
using namespace std;
using P = pair<int, int>;
using ll = long long;
constexpr int MOD = 1000000007;
constexpr int MAX = 2000100;
long long fac[MAX], finv[MAX], inv[MAX];
bool COMinited = false;
long long COM(int n, int k) {
  if (COMinited == false) {
    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;
    }
    COMinited = true;
  }
  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 = MOD) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); }
int main() {
  int k;
  cin >> k;
  string s;
  cin >> s;
  int t = s.size();
  int ret = 0;
  for (int i = t; i <= k + t; i++) {
    ret += modpow(25, k + t - i) * COM(k + t, i) % MOD;
    ret %= MOD;
  }
  cout << ret << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits.h>
#include <map>
#include <set>
#include <utility>
#include <vector>
using namespace std;
using P = pair<int, int>;
using ll = long long;
constexpr int MOD = 1000000007;
constexpr int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
bool COMinited = false;
long long COM(int n, int k) {
  if (COMinited == false) {
    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;
    }
    COMinited = true;
  }
  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 = MOD) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); }
int main() {
  int k;
  cin >> k;
  string s;
  cin >> s;
  int t = s.size();
  int ret = 0;
  for (int i = t; i <= k + t; i++) {
    ret += modpow(25, k + t - i) * COM(k + t, i) % MOD;
    ret %= MOD;
  }
  cout << ret << endl;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

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

const int MAX = 2 * 1000005; // 適当に変更する
const long long 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();
  long long k;
  string str_in;
  cin >> k;
  cin >> str_in;
  long long n = str_in.size();

  long long p_25[1000005], p_26[1000005];
  p_25[0] = 1;
  p_26[0] = 1;
  for (int i = 0; i < 1000003; i++) {
    p_25[i + 1] = (p_25[i] * 25) % MOD;
    p_26[i + 1] = (p_26[i] * 26) % MOD;
  }
  long long ans = 0;
  for (int i = 0; i <= k; i++) {
    long long x;
    x = p_26[i] * p_25[k - i];
    x %= MOD;
    // cout <<  COM(k+n-1-i, n-1) << endl;
    x *= COM(k + n - 1 - i, n - 1);
    x %= MOD;
    ans += x;
    ans %= MOD;
    // cout << x << endl;
  }
  cout << ans << endl;
}

Error: -11

Fixed submission:

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

const int MAX = 1000005; // 適当に変更する
const long long 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();
  long long Mod = MOD;
  long long k;
  string str_in;
  cin >> k;
  cin >> str_in;
  long long n = str_in.size();

  long long p_25[1000005], p_26[1000005];
  p_25[0] = 1;
  p_26[0] = 1;
  for (int i = 0; i < 1000003; i++) {
    p_25[i + 1] = (p_25[i] * 25) % Mod;
    p_26[i + 1] = (p_26[i] * 26) % Mod;
  }
  long long ans = 0;
  for (int i = 0; i <= k; i++) {
    long long x;
    x = p_26[i] * p_25[k - i];
    x %= Mod;
    // cout <<  COM(k+n-1-i, n-1) << endl;
    x *= COM(k + n - 1 - i, n - 1);
    x %= Mod;
    ans += x;
    ans %= Mod;
    // cout << x << endl;
  }
  cout << ans << endl;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const long long MOD = 1000000007;

const int MAX = int(1e6) * 2 + 5;

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

template <typename T> T mod_pow(T x, T n, const T &p) {
  T ret = 1;
  while (n > 0) {
    if (n & 1)
      (ret *= x) %= p;
    (x *= x) %= p;
    n >>= 1;
  }
  return ret;
}

void solve(long long K, std::string S) {
  ll N = S.size();
  ll ans = mod_pow(26ll, K + N, MOD);

  COMinit();
  for (ll i = 0; i < N; i++) {
    ll minus = COM(K + N, i) * mod_pow(25ll, K + N - i, MOD);
    minus %= MOD;
    ans = ans + MOD - minus;
    ans %= MOD;
  }
  cout << ans << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips:
// You use the default template now. You can remove this line by using your
// custom template)
int main() {
  long long K;
  scanf("%lld", &K);
  std::string S;
  std::cin >> S;
  solve(K, S);
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const long long MOD = 1000000007;

const int MAX = int(1e6) + 5;

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

template <typename T> T mod_pow(T x, T n, const T &p) {
  T ret = 1;
  while (n > 0) {
    if (n & 1)
      (ret *= x) %= p;
    (x *= x) %= p;
    n >>= 1;
  }
  return ret;
}

void solve(long long K, std::string S) {
  ll N = S.size();
  ll ans = mod_pow(26ll, K + N, MOD);

  COMinit();
  for (ll i = 0; i < N; i++) {
    ll minus = COM(K + N, i) * mod_pow(25ll, K + N - i, MOD);
    minus %= MOD;
    ans = ans + MOD - minus;
    ans %= MOD;
  }
  cout << ans << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips:
// You use the default template now. You can remove this line by using your
// custom template)
int main() {
  long long K;
  scanf("%lld", &K);
  std::string S;
  std::cin >> S;
  solve(K, S);
  return 0;
}