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

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll extend_gcd(ll a, ll b, ll &x, ll &y) {
  if (b == 0) {
    x = 1, y = 0;
    return a;
  } else {
    ll r = extend_gcd(b, a % b, y, x);
    y -= x * (a / b);
    return r;
  }
}
ll inv(ll a, ll mod) {
  ll x, y;
  extend_gcd(a, mod, x, y);
  x = (x % mod + mod) % mod;
  return x;
}

ll K, NS, N;
string S;

ll fs[MX], ifs[MX];

ll mpow(ll a, ll n) {
  if (n == 0)
    return 1;
  ll r = mpow(a, n / 2);
  r *= r;
  r %= MOD;
  if (n % 2 == 1)
    r *= a;
  return r % MOD;
}

ll Cnm(ll n, ll m) {
  return (((((fs[n] * ifs[m]) % MOD + MOD) % MOD) * ifs[n - m]) % MOD + MOD) %
         MOD;
}

void init() {
  for (ll a = 0; a < MX; a++) {
    if (a == 0)
      fs[a] = 1;
    else
      fs[a] = (fs[a - 1] * a) % MOD;
    ifs[a] = (inv(fs[a], MOD) % MOD + MOD) % MOD;
  }
}

int main() {
  init();
  cin >> K >> S;
  NS = S.size();
  N = NS + K;
  ll res = 0;
  for (ll j = 0; j <= K; j++) {
    res += (Cnm(N, j + NS) * mpow(25, N - NS - j)) % MOD;
    res %= MOD;
  }
  cout << res << endl;

  return 0;
}


Error: 0

Fixed submission:

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll MOD = 1e9 + 7;
const ll MX = 1e6 + 6;

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll extend_gcd(ll a, ll b, ll &x, ll &y) {
  if (b == 0) {
    x = 1, y = 0;
    return a;
  } else {
    ll r = extend_gcd(b, a % b, y, x);
    y -= x * (a / b);
    return r;
  }
}
ll inv(ll a, ll mod) {
  ll x, y;
  extend_gcd(a, mod, x, y);
  x = (x % mod + mod) % mod;
  return x;
}

ll K, NS, N;
string S;

ll fs[MX], ifs[MX];

ll mpow(ll a, ll n) {
  if (n == 0)
    return 1;
  ll r = mpow(a, n / 2);
  r *= r;
  r %= MOD;
  if (n % 2 == 1)
    r *= a;
  return r % MOD;
}

ll Cnm(ll n, ll m) {
  return (((((fs[n] * ifs[m]) % MOD + MOD) % MOD) * ifs[n - m]) % MOD + MOD) %
         MOD;
}

void init() {
  for (ll a = 0; a < MX; a++) {
    if (a == 0)
      fs[a] = 1;
    else
      fs[a] = (fs[a - 1] * a) % MOD;
    ifs[a] = (inv(fs[a], MOD) % MOD + MOD) % MOD;
  }
}

int main() {
  init();
  cin >> K >> S;
  NS = S.size();
  N = NS + K;
  ll res = 0;
  for (ll j = 0; j <= K; j++) {
    res += (Cnm(N, j + NS) * mpow(25, N - NS - j)) % MOD;
    res %= MOD;
  }
  cout << res << endl;

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define M 1000000007
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
const int N = 2e6 + 5;
int k, bars, ans, fact[N], inv[N];
string s;
ll mult(ll a, ll b) { return (a * b) % M; }
int fp(int a, int b) {
  int res = 1;
  while (b > 0) {
    if (b & 1)
      res = mult(res, a);
    b /= 2;
    a = mult(a, a);
  }
  return res;
}
int nck(int a, int b) {
  if (b > a)
    return 0;
  return mult(mult(fact[a], inv[b]), inv[a - b]);
}
int main() {
  fact[0] = inv[0] = 1;
  for (int i = 1; i < N; ++i) {
    ;
    fact[i] = mult(fact[i - 1], i);
    inv[i] = fp(fact[i], M - 2);
  }
  cin >> k >> s;
  bars = (int)s.size() - 1;
  // cout << fp(2 , 0) <<endl;;
  // ans = fp(26 , k); /
  for (int i = 0; i <= k; ++i) {
    int stars = k - i;
    int ways = nck(stars + bars, bars);
    ans = (ans + mult(mult(fp(25, stars), ways), fp(26, i))) % M;
    // cout << ways <<endl;
    // cout << i <<" " << stars <<endl;
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define M 1000000007
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
const int N = 1e6 + 5;
int k, bars, ans, fact[N], inv[N];
string s;
ll mult(ll a, ll b) { return (a * b) % M; }
int fp(int a, int b) {
  int res = 1;
  while (b > 0) {
    if (b & 1)
      res = mult(res, a);
    b /= 2;
    a = mult(a, a);
  }
  return res;
}
int nck(int a, int b) {
  if (b > a)
    return 0;
  return mult(mult(fact[a], inv[b]), inv[a - b]);
}
int main() {
  fact[0] = inv[0] = 1;
  for (int i = 1; i < N; ++i) {
    ;
    fact[i] = mult(fact[i - 1], i);
    inv[i] = fp(fact[i], M - 2);
  }
  cin >> k >> s;
  bars = (int)s.size() - 1;
  // cout << fp(2 , 0) <<endl;;
  // ans = fp(26 , k);
  for (int i = 0; i <= k; ++i) {
    int stars = k - i;
    int choose = nck(stars + bars, bars);
    ans = (ans + mult(mult(fp(25, stars), choose), fp(26, i))) % M;
    // cout << choose <<endl;
    // cout << i <<" " << stars <<endl;
  }
  cout << ans << endl;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <map>
#include <vector>

using namespace std;
typedef long long ll;
typedef vector<int> vi;
const ll MOD = 1e9 + 7;
const int M = 2e6 + 5;

ll fac[M], ifac[M];

ll inv(ll x) {
  ll ans = 1;
  ll p = MOD - 2;
  while (p > 0) {
    if (p & 1)
      ans = (ans * x) % MOD;
    p >>= 1;
    x = (x * x) % MOD;
  }
  return ans;
}

ll ifa(int i) {
  if (!ifac[i])
    ifac[i] = inv(fac[i]);
  return ifac[i];
}

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

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

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

  int K;
  cin >> K;
  string S;
  cin >> S;
  int n = S.size();
  ll ans = 0;
  ll p25 = 1, p26 = 1, i26 = inv(26);
  for (int k = 0; k < K; ++k)
    p26 = (p26 * 26) % MOD;
  for (int k = 0; k <= K; ++k) {
    ll a = (p25 * C(k + n - 1, n - 1)) % MOD;
    a = (a * p26) % MOD;
    ans = (ans + a) % MOD;
    p25 = (p25 * 25) % MOD;
    p26 = (p26 * i26) % MOD;
  }
  cout << ans << "\\n";

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <map>
#include <vector>

using namespace std;
typedef long long ll;
typedef vector<int> vi;
const ll MOD = 1e9 + 7;
const int M = 1e6 + 5;

ll fac[M], ifac[M];

ll inv(ll x) {
  ll ans = 1;
  ll p = MOD - 2;
  while (p > 0) {
    if (p & 1)
      ans = (ans * x) % MOD;
    p >>= 1;
    x = (x * x) % MOD;
  }
  return ans;
}

ll ifa(int i) {
  if (!ifac[i])
    ifac[i] = inv(fac[i]);
  return ifac[i];
}

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

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

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

  int K;
  cin >> K;
  string S;
  cin >> S;
  int n = S.size();
  ll ans = 0;
  ll p25 = 1, p26 = 1, i26 = inv(26);
  for (int k = 0; k < K; ++k)
    p26 = (p26 * 26) % MOD;
  for (int k = 0; k <= K; ++k) {
    ll a = (p25 * C(k + n - 1, n - 1)) % MOD;
    a = (a * p26) % MOD;
    ans = (ans + a) % MOD;
    p25 = (p25 * 25) % MOD;
    p26 = (p26 * i26) % MOD;
  }
  cout << ans << "\\n";

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

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
const int N = 1e6 + 4;
const ll MOD = 1e9 + 7;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = x * 10 + c - '0', c = getchar();
  return x * f;
}
ll fac[N << 1] = {1, 1};
ll inv[N] = {1, 1};
int n, m;
char s[N];
inline ll fpow(ll a, int b) {
  ll ret = 1;
  while (b) {
    if (b & 1)
      ret = ret * a % MOD;
    b >>= 1, a = a * a % MOD;
  }
  return ret;
}
inline ll C(int x, int y) {
  ll ans = fac[x];
  ans = ans * inv[y] % MOD;
  ans = ans * inv[x - y] % MOD;
  return ans;
}
int main() {
  //	freopen("in.txt","r",stdin);
  for (register int i = 1; i < (N << 1); ++i)
    fac[i] = fac[i - 1] * i % MOD;
  inv[N - 1] = fpow(fac[N - 1], MOD - 2);
  for (int i = N - 2; ~i; --i)
    inv[i] = inv[i + 1] * (i + 1) % MOD;
  n = read();
  scanf("%s", s);
  m = strlen(s);
  ll ans = 0;
  for (register int i = 0; i <= n; ++i) {
    ll c = fpow(26, i) * fpow(25, n - i) % MOD;
    (ans += c * C(n + m - i - 1, m - 1) % MOD) %= MOD;
  }
  printf("%lld\\n", ans);
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
const int N = 1e6;
const ll MOD = 1e9 + 7;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = x * 10 + c - '0', c = getchar();
  return x * f;
}
ll fac[N + 4] = {1, 1};
ll inv[N + 4] = {1, 1};
int n, m;
char s[N + 4];
inline ll fpow(ll a, int b) {
  ll ret = 1;
  while (b) {
    if (b & 1)
      ret = ret * a % MOD;
    b >>= 1, a = a * a % MOD;
  }
  return ret;
}
inline ll C(int x, int y) {
  ll ans = fac[x];
  ans = ans * inv[y] % MOD;
  ans = ans * inv[x - y] % MOD;
  return ans;
}
int main() {
  //	freopen("in.txt","r",stdin);
  for (register int i = 1; i <= N; ++i)
    fac[i] = fac[i - 1] * i % MOD;
  inv[N] = fpow(fac[N], MOD - 2);
  for (int i = N - 1; ~i; --i)
    inv[i] = inv[i + 1] * (i + 1) % MOD;
  n = read();
  scanf("%s", s);
  m = strlen(s);
  ll ans = 0;
  for (register int i = 0; i <= n; ++i) {
    ll c = fpow(26, i) * fpow(25, n - i) % MOD;
    (ans += c * C(n + m - i - 1, m - 1) % MOD) %= MOD;
  }
  printf("%lld\\n", ans);
  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

/*================================================================
*
*   创 建 者： badcw
*   创建日期： 2020/6/21 20:51
*
================================================================*/
#include <bits/stdc++.h>

#define ll long long
using namespace std;

const int maxn = 2e6 + 50;
const int mod = 1e9 + 7;
ll qp(ll a, ll n, ll mod = ::mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

ll jie[maxn] = {1};
char s[maxn];

ll inv(ll x) { return qp(x, mod - 2); }

ll C(int x, int y) {
  if (x < y)
    return 0;
  if (x == 0)
    return 0;
  return jie[x] * inv(jie[y]) % mod * inv(jie[x - y]) % mod;
}

int main(int argc, char *argv[]) {
  int k;
  cin >> k >> s;
  int len = strlen(s);
  k += len;
  for (int i = 1; i <= k; ++i)
    jie[i] = jie[i - 1] * i % mod;
  ll res = qp(26, k);
  ll TC = 0;
  ll TQ = qp(25, k);
  ll tt = inv(25);
  for (int i = 0; i < len; ++i) {
    if (i == 0) {
      TC = 1;
    } else
      TC = TC * (k - i + 1) % mod * inv(i) % mod;
    res -= TC * TQ;
    res %= mod;
    TQ = TQ * tt % mod;
    //        res -= C(k, i) * qp(25, k - i) % mod;
    //        res %= mod;
  }
  if (res < 0)
    res += mod;
  cout << res << endl;
  //    printf("%lld\\n", res);
  return 0;
}

Error: 0

Fixed submission:

/*================================================================
*
*   创 建 者： badcw
*   创建日期： 2020/6/21 20:51
*
================================================================*/
#include <bits/stdc++.h>

#define ll long long
using namespace std;

const int maxn = 1e6 + 50;
const int mod = 1e9 + 7;
ll qp(ll a, ll n, ll mod = ::mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

ll jie[maxn] = {1};
char s[maxn];

ll inv(ll x) { return qp(x, mod - 2); }

ll C(int x, int y) {
  if (x < y)
    return 0;
  if (x == 0)
    return 0;
  return jie[x] * inv(jie[y]) % mod * inv(jie[x - y]) % mod;
}

int main(int argc, char *argv[]) {
  int k;
  cin >> k >> s;
  int len = strlen(s);
  k += len;
  for (int i = 1; i <= k; ++i)
    jie[i] = jie[i - 1] * i % mod;
  ll res = qp(26, k);
  ll TC = 0;
  ll TQ = qp(25, k);
  ll tt = inv(25);
  for (int i = 0; i < len; ++i) {
    if (i == 0) {
      TC = 1;
    } else
      TC = TC * (k - i + 1) % mod * inv(i) % mod;
    res -= TC * TQ;
    res %= mod;
    TQ = TQ * tt % mod;
    //        res -= C(k, i) * qp(25, k - i) % mod;
    //        res %= mod;
  }
  if (res < 0)
    res += mod;
  cout << res << endl;
  //    printf("%lld\\n", res);
  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Time Limit Exceeded

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

constexpr long long MOD = 1e9 + 7;

ll binExp(ll a, ll e) {
  if (e == 0) {
    return 1;
  }

  if (e % 2 == 1) {
    return (binExp(a, e - 1) * a) % MOD;
  }

  ll b = binExp(a, e / 2);
  return (b * b) % MOD;
}

int main() {
  ll k;
  cin >> k;

  string s;
  cin >> s;

  ll n = s.length();
  ll ans = 0;

  ll fact[n + k + 1];
  ll inv[n + k + 1];

  fact[0] = inv[0] = 1;
  for (int i = 1; i <= n + k; ++i) {
    fact[i] = (fact[i - 1] * i) % MOD;
    inv[i] = binExp(fact[i], MOD - 2);
  }

  for (int i = n; i <= n + k; ++i) {
    ll a = (((fact[n + k] * inv[n + k - i]) % MOD) * inv[i]) % MOD;
    a = (a * binExp(25, n + k - i)) % MOD;
    ans = (ans + a) % MOD;
  }

  cout << ans;

  return 0;
}


Error: TLE

Fixed submission:

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

constexpr long long MOD = 1e9 + 7;

constexpr int N = 1e6;

ll factorials[N];
ll inversed[N];

long long binExp(long long a, long long e) {
  if (e == 0) {
    return 1;
  }

  if (e % 2 == 1) {
    return (binExp(a, e - 1) * a) % MOD;
  }

  long long b = binExp(a, e / 2);
  return (b * b) % MOD;
}

long long f(long long a) {
  long long r = 1;
  for (long long i = 2; i <= a; ++i) {
    r = (r * i) % MOD;
  }

  return r;
}

long long c(long long n, long long k) {
  long long a = factorials[n];
  long long b = inversed[k];
  long long d = inversed[n - k];

  return ((a * b) % MOD * d) % MOD;
}

int main() {
  ll k;
  cin >> k;

  string s;
  cin >> s;

  ll n = s.length();

  for (int i = 0; i <= (n + k); ++i) {
    ll fact = f(i);
    factorials[i] = fact;
    inversed[i] = binExp(fact, MOD - 2);
  }

  ll ans = 0;
  for (int i = n; i <= (n + k); ++i) {
    ll a = (c(n + k, i) * binExp(25, n + k - i)) % MOD;
    ans = (ans + a) % MOD;
  }

  cout << ans;

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

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD 1000000007
vector<ll> fact(2000001);
void init_fact(int n) {
  fact[0] = 1;
  for (int i = 1; i < n + 1; i++) {
    fact[i] = fact[i - 1] * i;
    fact[i] %= MOD;
  }
}
ll mod_pow(ll x, ll p) {
  ll res = 1;
  ll n = x;
  while (p > 0) {
    if (p & 1 == 1)
      res = (res * n) % MOD;
    n = (n * n) % MOD;
    p = (p >> 1);
  }
  return res;
}

ll nCr(int n, int r) {
  ll res = 1;
  res *= fact[n];
  res *= mod_pow(fact[r], MOD - 2);
  res %= MOD;
  res *= mod_pow(fact[n - r], MOD - 2);
  res %= MOD;
  return res;
}
int main() {
  ll K;
  cin >> K;
  string s;
  cin >> s;
  ll S = s.size();
  init_fact(K + S);
  ll ans = 0;
  for (int i = 0; i < K + 1; i++) {
    ll tmp = nCr(S + K - i - 1, S - 1);
    tmp *= mod_pow(25, K - i);
    tmp %= MOD;
    tmp *= mod_pow(26, i);
    tmp %= MOD;
    ans += tmp;
    ans %= MOD;
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD 1000000007
vector<ll> fact(2000000);
void init_fact(int n) {
  fact[0] = 1;
  for (int i = 1; i < n + 1; i++) {
    fact[i] = fact[i - 1] * i;
    fact[i] %= MOD;
  }
}
ll mod_pow(ll x, ll p) {
  ll res = 1;
  ll n = x;
  while (p > 0) {
    if (p & 1 == 1)
      res = (res * n) % MOD;
    n = (n * n) % MOD;
    p = (p >> 1);
  }
  return res;
}

ll nCr(int n, int r) {
  ll res = 1;
  res *= fact[n];
  res *= mod_pow(fact[r], MOD - 2);
  res %= MOD;
  res *= mod_pow(fact[n - r], MOD - 2);
  res %= MOD;
  return res;
}
int main() {
  ll K;
  cin >> K;
  string s;
  cin >> s;
  ll S = s.size();
  init_fact(K + S);
  ll ans = 0;
  for (int i = 0; i < K + 1; i++) {
    ll tmp = nCr(S + K - i - 1, S - 1);
    tmp *= mod_pow(25, K - i);
    tmp %= MOD;
    tmp *= mod_pow(26, i);
    tmp %= MOD;
    ans += tmp;
    ans %= MOD;
  }
  cout << ans << endl;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

//
// Created by 10034 on 2020/7/29.
//

#include <cstring>
#include <iostream>
using namespace std;
const int mod = 1e9 + 7, N = 1000100;
char s[N];
#define int long long
typedef long long LL;
int qmi(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1)
      res = (LL)res * a % mod;
    b >>= 1;
    a = (LL)a * a % mod;
  }
  return res;
}
int fac[N * 2];
int C(int a, int b) {
  //    cout<<fac[a]<<" "<<qmi(fac[a-b],mod-2)<<" "<<qmi(fac[b],mod-2)<<endl;
  return (LL)fac[a] * qmi(fac[a - b], mod - 2) % mod * qmi(fac[b], mod - 2) %
         mod;
}
signed main() {
  fac[0] = 1;
  for (int i = 1; i < N * 2; ++i) {
    fac[i] = (LL)fac[i - 1] * i % mod;
  }
  int n, m;
  cin >> m;
  cin >> s;
  int res = 0;
  n = strlen(s);
  for (int i = 0; i <= m; ++i) {
    res = (LL)(res + (LL)qmi(26, i) * C(n + m - i - 1, n - 1) % mod *
                         qmi(25, m - i) % mod) %
          mod;
  }
  cout << res << endl;
  return 0;
}

Error: 0

Fixed submission:

//
// Created by 10034 on 2020/7/29.
//

#include <cstring>
#include <iostream>
using namespace std;
const int mod = 1e9 + 7, N = 1000100;
char s[N];
typedef long long LL;
int qmi(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1)
      res = (LL)res * a % mod;
    b >>= 1;
    a = (LL)a * a % mod;
  }
  return res;
}
int fac[N];
int C(int a, int b) {
  //    cout<<fac[a]<<" "<<qmi(fac[a-b],mod-2)<<" "<<qmi(fac[b],mod-2)<<endl;
  return (LL)fac[a] * qmi(fac[a - b], mod - 2) % mod * qmi(fac[b], mod - 2) %
         mod;
}
int main() {
  fac[0] = 1;
  for (int i = 1; i < N; ++i) {
    fac[i] = (LL)fac[i - 1] * i % mod;
  }
  int n, m;
  cin >> m;
  cin >> s;
  int res = 0;
  n = strlen(s);
  for (int i = 0; i <= m; ++i) {
    res = (LL)(res + (LL)qmi(26, i) * C(n + m - i - 1, n - 1) % mod *
                         qmi(25, m - i) % mod) %
          mod;
  }
  cout << res << endl;
  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1 << 30) - 1)
#define LINF (1LL << 60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

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

// 二項係数計算
ll 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 x, ll n) {
  ll res = 1;
  ll mul = x;
  while (n) {
    if (n % 2)
      res = res * mul % MOD;
    mul = mul * mul % MOD;
    n /= 2;
  }
  return res;
}

ll modinv(ll x, ll n) { return modpow(x, n - 2); }

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

  ll ans = 0;
  COMinit();

  for (int i = 0; i <= k; i++) {
    ll tmp = modpow(25, k - i);
    tmp %= MOD;
    tmp *= modpow(26, i);
    tmp %= MOD;
    tmp *= COM(n + k - i - 1, n - 1);
    tmp %= MOD;
    ans += tmp;
    ans %= MOD;
  }

  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1 << 30) - 1)
#define LINF (1LL << 60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

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

// 二項係数計算
ll 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 x, ll n) {
  ll res = 1;
  ll mul = x;
  while (n) {
    if (n % 2)
      res = res * mul % MOD;
    mul = mul * mul % MOD;
    n /= 2;
  }
  return res;
}

ll modinv(ll x, ll n) { return modpow(x, n - 2); }

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

  ll ans = 0;
  COMinit();

  for (int i = 0; i <= k; i++) {
    ll tmp = modpow(25, k - i);
    tmp %= MOD;
    tmp *= modpow(26, i);
    tmp %= MOD;
    tmp *= COM(n + k - i - 1, n - 1);
    tmp %= MOD;
    ans += tmp;
    ans %= MOD;
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>
#define ll long long
#define pii pair<ll, ll>
#define debug(a) cout << a << '\\n'
#define maxn 2000009 /// I wanna be the wind
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for (ll i = a; i < (b); ++i)
#define per(i, b, a) for (ll i = b - 1; i >= a; i--)
#define trav(a, x) for (auto &a : x)
#define allin(a, x) for (auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e14 + 9;
ll mult(ll a, ll b) { return a * b % MOD; }
ll fastpow(ll a, ll b) {
  ll calc = 1;
  for (; b >= 1LL; b /= 2LL) {
    if ((b & 1LL))
      calc = mult(calc, a);
    a = mult(a, a);
  }
  return calc;
}
ll soma(ll a, ll b) {
  if (a + b > MOD)
    return a + b - MOD;
  else
    return a + b;
}
ll subt(ll a, ll b) {
  if (a - b < 0)
    return a - b + MOD;
  else
    return a - b;
}
ll fact[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  fact[0] = 1;
  rep(i, 1, maxn) fact[i] = mult(i, fact[i - 1]);
  ll k;
  string s;
  cin >> k >> s;
  ll n = sz(s) + k;
  ll tir = 0;
  rep(i, 0, sz(s)) {
    tir = soma(
        tir, mult(fastpow(25, n - i),
                  mult(fact[n], fastpow(mult(fact[i], fact[n - i]), MOD - 2))));
  }
  cout << subt(fastpow(26, n), tir) << "\\n";
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define pii pair<ll, ll>
#define debug(a) cout << a << '\\n'
#define maxn 1000009 /// I wanna be the wind
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for (ll i = a; i < (b); ++i)
#define per(i, b, a) for (ll i = b - 1; i >= a; i--)
#define trav(a, x) for (auto &a : x)
#define allin(a, x) for (auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e14 + 9;
ll mult(ll a, ll b) { return a * b % MOD; }
ll fastpow(ll a, ll b) {
  ll calc = 1;
  for (; b >= 1LL; b /= 2LL) {
    if ((b & 1LL))
      calc = mult(calc, a);
    a = mult(a, a);
  }
  return calc;
}
ll soma(ll a, ll b) {
  if (a + b > MOD)
    return a + b - MOD;
  else
    return a + b;
}
ll subt(ll a, ll b) {
  if (a - b < 0)
    return a - b + MOD;
  else
    return a - b;
}
ll fact[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  fact[0] = 1;
  rep(i, 1, maxn) fact[i] = mult(i, fact[i - 1]);
  ll k;
  string s;
  cin >> k >> s;
  ll n = sz(s) + k;
  ll tir = 0;
  rep(i, 0, sz(s)) {
    tir = soma(
        tir, mult(fastpow(25, n - i),
                  mult(fact[n], fastpow(mult(fact[i], fact[n - i]), MOD - 2))));
  }
  cout << subt(fastpow(26, n), tir) << "\\n";
  return 0;
}