prithivMLmods/Coder-Stat huggingface dataset:
Problem p02631 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p;
vector<ll> v;
ll arr[100001] = {0};
int main() {
  ll n, k, a, b, c, ans = 0;
  cin >> n;
  for (ll i = 0; i < n; i++) {
    cin >> arr[i];
    ans ^= arr[i];
  }
  //   cout<<arr[1]<<endl;
  for (ll i = 0; i < n; i++) {
    b = ans ^ arr[i];
    cout << b << " ";
  }
  cout << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p;
vector<ll> v;
ll arr[200001];
int main() {
  ll n, k, a, b, c, ans = 0;
  cin >> n;
  for (ll i = 0; i < n; i++) {
    cin >> arr[i];
    ans ^= arr[i];
  }
  //   cout<<arr[1]<<endl;
  for (ll i = 0; i < n; i++) {
    b = ans ^ arr[i];
    cout << b << " ";
  }
  cout << endl;
  return 0;
}
Problem p02631 (C++)

Buggy submission (status: Time Limit Exceeded):
/* https://codeforces.com/contest/1360/problem/H */
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vs = vector<string>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vpi = vector<pair<int, int>>;
using vpl = vector<pair<ll, ll>>;
using ld = double;

#define f first
#define s second
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define ins insert

const int MAX = 1e5;

int main() {
  int N;
  cin >> N;
  vl a(N);
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
  }

  vl ans(N);
  for (int i = 0; i < N; ++i) {
    ll temp = 0;
    for (int j = 0; j < N; ++j) {
      if (i == j)
        continue;
      temp ^= a[j];
    }

    ans[i] = temp;
  }

  for (auto const &x : ans) {
    cout << x << " ";
  }

  cout << endl;
  return 0;
}


Fixed submission:
/* https://codeforces.com/contest/1360/problem/H */
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vs = vector<string>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vpi = vector<pair<int, int>>;
using vpl = vector<pair<ll, ll>>;
using ld = double;

#define f first
#define s second
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define ins insert

const int MAX = 1e5;

int main() {
  int N;
  cin >> N;
  vl a(N);
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
  }

  vl ans(N);
  for (int i = 0; i < N; ++i) {
    ll temp = 0;
    for (int j = 0; j < N; ++j) {
      if (i == j)
        continue;
      temp ^= a[j];
    }

    ans[i] = temp;
    break;
  }

  for (int i = 1; i < N; ++i) {
    ans[i] = ans[0] ^ a[i] ^ a[0];
  }

  for (auto const &x : ans) {
    cout << x << " ";
  }

  cout << endl;
  return 0;
}
Problem p02631 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> x(20, 0);
  ll maxNum = 0;
  rep(i, n) {
    cin >> a[i];
    ll now = a[i];
    ll s = 0;
    while (now) {
      if (now & 1) {
        x[s]++;
        x[s] %= 2;
      }
      now >>= 1;
      s++;
      maxNum = max(maxNum, s);
    }
  }

  rep(i, n) {
    ll ans = 0;
    rep(s, maxNum) {
      if (((x[s] + (a[i] & 1)) % 2 == 1))
        ans += (1LL << s);
      a[i] >>= 1;
    }
    if (i == n - 1)
      cout << ans << endl;
    else
      cout << ans << ' ';
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> x(60, 0);
  ll maxNum = 0;
  rep(i, n) {
    cin >> a[i];
    ll now = a[i];
    ll s = 0;
    while (now) {
      if (now & 1) {
        x[s]++;
        x[s] %= 2;
      }
      now >>= 1;
      s++;
      maxNum = max(maxNum, s);
    }
  }

  rep(i, n) {
    ll ans = 0;
    rep(s, maxNum) {
      if (((x[s] + (a[i] & 1)) % 2 == 1))
        ans += (1LL << s);
      a[i] >>= 1;
    }
    if (i == n - 1)
      cout << ans << endl;
    else
      cout << ans << ' ';
  }

  return 0;
}
Problem p02631 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define MEM 100006
#define sanic ios_base::sync_with_stdio(0)
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
const ll MOD = 1e9 + 7;
ll n, m, sum;
ll c[MEM];
string s;
int main() {
  sanic;
  cin.tie(0);
  cin >> n;
  ll sxm = 0;
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    sxm ^= c[i];
  }
  for (int i = 0; i < n; i++)
    cout << (sxm ^ c[i]) << ' ';
}


Fixed submission:
#include <bits/stdc++.h>
#define MEM 200006
#define sanic ios_base::sync_with_stdio(0)
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
const ll MOD = 1e9 + 7;
ll n, m, sum;
ll c[MEM];
string s;
int main() {
  sanic;
  cin.tie(0);
  cin >> n;
  ll sxm = 0;
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    sxm ^= c[i];
  }
  for (int i = 0; i < n; i++)
    cout << (sxm ^ c[i]) << ' ';
}
Problem p02631 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, ar[100000];
  cin >> n;
  long x = 0;
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
    x ^= ar[i];
  }
  for (int i = 0; i < n; i++) {
    ar[i] ^= x;
  }
  for (int i = 0; i < n; i++)
    cout << ar[i] << " ";
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, ar[200000];
  cin >> n;
  long x = 0;
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
    x ^= ar[i];
  }
  for (int i = 0; i < n; i++) {
    ar[i] ^= x;
  }
  for (int i = 0; i < n; i++)
    cout << ar[i] << " ";
  return 0;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

const int64_t MAX = 1e+6 + 10;
const int64_t MOD = 1000000007;

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

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int64_t 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;
  }
}

// 二項係数計算
int64_t COM(int64_t n, int64_t 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() {
  int64_t K;
  string S;
  cin >> K;
  cin >> S;
  int64_t N = S.size();

  // 前処理
  COMinit();

  vector<int64_t> POW26(K + 10), POW25(K + 10);
  POW26[0] = 1;
  POW25[0] = 1;
  for (int64_t i = 1; i < K + 10; ++i) {
    POW25[i] = POW25[i - 1] * 25 % MOD;
    POW26[i] = POW26[i - 1] * 26 % MOD;
  }

  int64_t sum = 0;
  for (int64_t k = 0; k <= K; ++k) {
    sum = (sum +
           (COM(N + K - k - 1, N - 1) * POW26[k]) % MOD * POW25[K - k] % MOD) %
          MOD;
  }

  if (sum < 0)
    sum += MOD;

  cout << sum << endl;

  return 0;
}


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

const int64_t MAX = 2e+6 + 10;
const int64_t MOD = 1000000007;

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

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int64_t 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;
  }
}

// 二項係数計算
int64_t COM(int64_t n, int64_t 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() {
  int64_t K;
  string S;
  cin >> K;
  cin >> S;
  int64_t N = S.size();

  // 前処理
  COMinit();

  vector<int64_t> POW26(K + 10), POW25(K + 10);
  POW26[0] = 1;
  POW25[0] = 1;
  for (int64_t i = 1; i < K + 10; ++i) {
    POW25[i] = POW25[i - 1] * 25 % MOD;
    POW26[i] = POW26[i - 1] * 26 % MOD;
  }

  int64_t sum = 0;
  for (int64_t k = 0; k <= K; ++k) {
    sum = (sum +
           (COM(N + K - k - 1, N - 1) * POW26[k]) % MOD * POW25[K - k] % MOD) %
          MOD;
  }

  if (sum < 0)
    sum += MOD;

  cout << sum << endl;

  return 0;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define SZ(a) (int)((a).size())
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> Pii;
typedef pair<ll, int> Pli;
typedef unsigned long long ull;
const double eps = 1e-8;
const ll infll = 0x7fffffffffffffff;
const int mod = (int)(1e9) + 7;
const int inf = 0x7fffffff;
const int maxn = (int)(2e5) + 7;
const int maxm = 300;

char s[maxn];
ll n, k, a[maxn], b[maxn];
ll C(ll n, ll m) {
  if (m > n)
    return 0;
  return a[n] * b[m] % mod * b[n - m] % mod;
}
ll power(ll a, ll b) {
  ll ans = 1;
  for (; b; a = a * a % mod, b >>= 1)
    if (b & 1)
      ans = ans * a % mod;
  return ans;
}

int main() {

  // freopen("in.in", "r", stdin);
  scanf("%lld%s", &k, s + 1);
  n = strlen(s + 1);
  a[0] = a[1] = b[0] = b[1] = 1;
  for (ll i = 2; i <= n + k; i++) {
    b[i] = (mod - mod / i) * b[mod % i] % mod;
  }
  for (ll i = 2; i <= n + k; i++) {
    a[i] = a[i - 1] * i % mod;
    b[i] = b[i - 1] * b[i] % mod;
  }
  ll res = 0;
  for (ll i = 0; i <= k;
       i++) { // 先选出i个字符放在最左边, 和原串第一个字符在一起
    res = (res + C(n + k - i - 1, k - i) * power(26, i) % mod *
                     power(25, k - i) % mod) %
          mod;
  }
  printf("%lld", res);

  return 0;
}
//           f             o
// 26 * 26 * 1 * 25 * 25 * 1 * 25 * 25
// [a, z]    [a, f)∪(f, z)  [a, o)∪(o, z]
// |<----------- n + k ------------->|


Fixed submission:
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define SZ(a) (int)((a).size())
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> Pii;
typedef pair<ll, int> Pli;
typedef unsigned long long ull;
const double eps = 1e-8;
const ll infll = 0x7fffffffffffffff;
const int mod = (int)(1e9) + 7;
const int inf = 0x7fffffff;
const int maxn = (int)(2e6) + 7;
const int maxm = 300;

char s[maxn];
ll n, k, a[maxn], b[maxn];
ll C(ll n, ll m) {
  if (m > n)
    return 0;
  return a[n] * b[m] % mod * b[n - m] % mod;
}
ll power(ll a, ll b) {
  ll ans = 1;
  for (; b; a = a * a % mod, b >>= 1)
    if (b & 1)
      ans = ans * a % mod;
  return ans;
}

int main() {

  // freopen("in.in", "r", stdin);
  scanf("%lld%s", &k, s + 1);
  n = strlen(s + 1);
  a[0] = a[1] = b[0] = b[1] = 1;
  for (ll i = 2; i <= n + k; i++) {
    b[i] = (mod - mod / i) * b[mod % i] % mod;
  }
  for (ll i = 2; i <= n + k; i++) {
    a[i] = a[i - 1] * i % mod;
    b[i] = b[i - 1] * b[i] % mod;
  }
  ll res = 0;
  for (ll i = 0; i <= k;
       i++) { // 先选出i个字符放在最左边, 和原串第一个字符在一起
    res = (res + C(n + k - i - 1, k - i) * power(26, i) % mod *
                     power(25, k - i) % mod) %
          mod;
  }
  printf("%lld", res);

  return 0;
}
//           f             o
// 26 * 26 * 1 * 25 * 25 * 1 * 25 * 25
// [a, z]    [a, f)∪(f, z)  [a, o)∪(o, z]
// |<----------- n + k ------------->|
Problem p02632 (C++)

Buggy submission (status: 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 = 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;
}

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 = 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;
}
Problem p02632 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
long long fac[2000005], inv[2000005];
long long modpow(long long x, long long e) {
  if (x == 1 || e == 0)
    return 1;
  long long c = modpow(x, e / 2);
  long long c1 = (c * c) % MOD;
  if (e % 2 == 0)
    return c1;
  else
    return (c1 * x) % MOD;
}
long long C(long long n, long long k) {
  if (k > n || k < 0)
    return 0;
  return ((fac[n] * inv[k]) % MOD * inv[n - k]) % MOD;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  fac[0] = inv[0] = 1;
  for (int i = 1; i < 2000005; i++) {
    fac[i] = (fac[i - 1] * i) % MOD;
    inv[i] = (inv[i - 1] * modpow(i, MOD - 2)) % MOD;
  }
  int k, n;
  string s;
  cin >> k >> s;
  n = s.size();
  long long ans = 0;
  for (int i = n; i <= n + k; i++) {
    long long add = (C(i - 1, n - 1) * modpow(25, i - n)) % MOD;
    add = (add * modpow(26, n + k - i)) % MOD;
    ans = (add + ans) % MOD;
  }
  cout << ans;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
long long fac[2000005], inv[2000005];
long long modpow(long long x, long long e) {
  if (x == 1 || e == 0)
    return 1;
  long long c = modpow(x, e / 2);
  long long c1 = (c * c) % MOD;
  if (e % 2 == 0)
    return c1;
  else
    return (c1 * x) % MOD;
}
long long C(long long n, long long k) {
  if (k > n || k < 0)
    return 0;
  return ((fac[n] * inv[k]) % MOD * inv[n - k]) % MOD;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  fac[0] = inv[0] = 1;
  for (int i = 1; i < 2000005; i++) {
    fac[i] = (fac[i - 1] * i) % MOD;
    if (i < 1000005)
      inv[i] = (inv[i - 1] * modpow(i, MOD - 2)) % MOD;
  }
  int k, n;
  string s;
  cin >> k >> s;
  n = s.size();
  long long ans = 0;
  for (int i = n; i <= n + k; i++) {
    long long add = (C(i - 1, n - 1) * modpow(25, i - n)) % MOD;
    add = (add * modpow(26, n + k - i)) % MOD;
    ans = (add + ans) % MOD;
  }
  cout << ans;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;

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

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

int main() {
  COMinit();
  ll k;
  std::cin >> k;
  string s;
  std::cin >> s;

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

  std::cout << ans << std::endl;
}


Fixed submission:
typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;

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

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

int main() {
  COMinit();
  ll k;
  std::cin >> k;
  string s;
  std::cin >> s;

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

  std::cout << ans << std::endl;
}
Problem p02632 (C++)

Buggy submission (status: 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) + 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;
}


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) * 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;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define RREP(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define rrep(i, n) RREP(i, n - 1, 0)
#define all(v) v.begin(), v.end()
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

#define MAX_N 200005
ll inv[MAX_N], fac[MAX_N], finv[MAX_N];
void make() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX_N; i++) {
    inv[i] = mod - inv[mod % i] * (mod / i) % mod;
    fac[i] = fac[i - 1] * (ll)i % mod;
    finv[i] = finv[i - 1] * inv[i] % mod;
  }
}
ll perm(ll n, ll r) {
  if (n < 0)
    return 0;
  else if (n < r)
    return 0;
  else
    return (fac[n] * finv[n - r]) % mod;
}
ll comb(ll n, ll r) {
  ll ans = 1;
  ans = perm(n, r);            // n * (n-1) * ... * (n-r+1)
  ans = (ans * finv[r]) % mod; // フェルマーの小定理
  return ans;
}
ll modpow(ll a, ll N) {
  ll ans = 1;
  ll tmp = a;
  while (N > 0) {
    if (N % 2 == 1)
      (ans *= tmp) %= mod;
    (tmp *= tmp) %= mod;
    N /= 2;
  }
  return ans;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll K;
  string S;
  cin >> K >> S;
  ll N = S.size();
  make();
  ll ans = 0;
  rep(i, K + 1) {
    ll k = K - i;
    (ans +=
     comb(k + N - 1, N - 1) * modpow(25, k) % mod * modpow(26, i) % mod) %= mod;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define RREP(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define rrep(i, n) RREP(i, n - 1, 0)
#define all(v) v.begin(), v.end()
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

#define MAX_N 2000005
ll inv[MAX_N], fac[MAX_N], finv[MAX_N];
void make() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX_N; i++) {
    inv[i] = mod - inv[mod % i] * (mod / i) % mod;
    fac[i] = fac[i - 1] * (ll)i % mod;
    finv[i] = finv[i - 1] * inv[i] % mod;
  }
}
ll perm(ll n, ll r) {
  if (n < 0)
    return 0;
  else if (n < r)
    return 0;
  else
    return (fac[n] * finv[n - r]) % mod;
}
ll comb(ll n, ll r) {
  ll ans = 1;
  ans = perm(n, r);            // n * (n-1) * ... * (n-r+1)
  ans = (ans * finv[r]) % mod; // フェルマーの小定理
  return ans;
}
ll modpow(ll a, ll N) {
  ll ans = 1;
  ll tmp = a;
  while (N > 0) {
    if (N % 2 == 1)
      (ans *= tmp) %= mod;
    (tmp *= tmp) %= mod;
    N /= 2;
  }
  return ans;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll K;
  string S;
  cin >> K >> S;
  ll N = S.size();
  make();
  ll ans = 0;
  rep(i, K + 1) {
    ll k = K - i;
    (ans +=
     comb(k + N - 1, N - 1) * modpow(25, k) % mod * modpow(26, i) % mod) %= mod;
  }
  cout << ans << endl;
  return 0;
}
Problem p02632 (C++)

Buggy submission (status: 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 = 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;
}


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 = 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;
}
Problem p02632 (C++)

Buggy submission (status: 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 = 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;
}


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 = 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;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

#define pb push_back
#define fi first
#define se second
#define eb emplace_back

using namespace std;

typedef pair<int, int> ii;
typedef long long ll;
const int N = 1000007, inf = 0x3f3f3f3f;

const int M = 1e9 + 7;

ll fat[N];
ll fast_pow(ll a, ll b) {
  ll ans = 1;

  while (b) {
    if (b & 1)
      ans = a * ans % M;
    b >>= 1;
    a = a * a % M;
  }
  return ans;
}

ll nchoosek(ll n, ll k) {
  ll den = fat[n - k] * fat[k] % M;
  return fat[n] * fast_pow(den, M - 2) % M;
}

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

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

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

  ll sum = 0;
  for (int x = 0; x <= k; ++x) {
    sum += (fast_pow(25, k - x) * fast_pow(26, x) % M) *
           nchoosek(n + k - x - 1, n - 1) % M;
    if (sum >= M)
      sum -= M;
  }
  cout << sum << endl;
}

Fixed submission:
#include <bits/stdc++.h>

#define pb push_back
#define fi first
#define se second
#define eb emplace_back

using namespace std;

typedef pair<int, int> ii;
typedef long long ll;
const int N = 2000007, inf = 0x3f3f3f3f;

const int M = 1e9 + 7;

ll fat[N];
ll fast_pow(ll a, ll b) {
  ll ans = 1;

  while (b) {
    if (b & 1)
      ans = a * ans % M;
    b >>= 1;
    a = a * a % M;
  }
  return ans;
}

ll nchoosek(ll n, ll k) {
  ll den = fat[n - k] * fat[k] % M;
  return fat[n] * fast_pow(den, M - 2) % M;
}

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

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

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

  ll sum = 0;
  for (int x = 0; x <= k; ++x) {
    sum += (fast_pow(25, k - x) * fast_pow(26, x) % M) *
           nchoosek(n + k - x - 1, n - 1) % M;
    if (sum >= M)
      sum -= M;
  }
  cout << sum << endl;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int MAX = 510000;
const ll MOD = 1000000007;

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

// 二項係数計算
long long COM(ll n, ll k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

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

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

const int MAX = 2000000;
const ll MOD = 1000000007;

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

// 二項係数計算
long long COM(ll n, ll k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 1000000007;
const int INF = 1e15;
using Graph = vector<vector<int>>;

// AのN乗(mod M)を高速に計算する(O(logN))
// Aの逆元を取る場合、modpow(A, MOD-2, 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;
}

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

signed main() {
  COMinit();

  int K;
  cin >> K;
  string S;
  cin >> S;

  int N = (int)S.size();

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


Fixed submission:
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 1000000007;
const int INF = 1e15;
using Graph = vector<vector<int>>;

// AのN乗(mod M)を高速に計算する(O(logN))
// Aの逆元を取る場合、modpow(A, MOD-2, 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;
}

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

signed main() {
  COMinit();

  int K;
  cin >> K;
  string S;
  cin >> S;

  int N = (int)S.size();

  int ans = 0;
  for (int i = 0; i <= K; i++) {
    int now = 1;
    now = modpow(25, i, MOD);
    now %= MOD;
    now *= COM(i + N - 1, N - 1);
    now %= MOD;
    now *= modpow(26, K - i, MOD);
    now %= MOD;
    ans += now;
    ans %= MOD;
  }
  cout << ans << endl;
}
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;

const Int MOD = 1000000007;
const Int MAX = 1000010;

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

Int 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 modpow(Int a, Int n) {
  Int res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return res;
}

int main() {

  COMinit(); // これをやっておくこと

  Int K;
  cin >> K;
  string S;
  cin >> S;
  Int N = S.size();

  Int sum = 0;

  for (Int i = N; i <= N + K; i++) {
    sum = (sum + (((COM(i - 1, N - 1) * modpow(25, i - N)) % MOD) *
                  modpow(26, N + K - i)) %
                     MOD) %
          MOD;
  }

  cout << sum << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;

const Int MOD = 1000000007;
const Int MAX = 2000010;

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

Int 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 modpow(Int a, Int n) {
  Int res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return res;
}

int main() {

  COMinit(); // これをやっておくこと

  Int K;
  cin >> K;
  string S;
  cin >> S;
  Int N = S.size();

  Int sum = 0;

  for (Int i = N; i <= N + K; i++) {
    sum = (sum + (((COM(i - 1, N - 1) * modpow(25, i - N)) % MOD) *
                  modpow(26, N + K - i)) %
                     MOD) %
          MOD;
  }

  cout << sum << endl;
}
Problem p02632 (Python)

Buggy submission (status: Runtime Error):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007


def main():
    K = int(readline())
    S = readline().strip()

    COM_MAX = 10**6

    fac, finv, inv = [0] * (COM_MAX + 1), [0] * (COM_MAX + 1), [0] * (COM_MAX + 1)
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1

    for i in range(2, COM_MAX + 1):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    def mod_com(n, r):
        if n < r:
            return 0
        if n < 0 or r < 0:
            return 0
        return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD

    M = len(S)
    L = K + M

    ans = 0
    p = pow(25, K + 1, MOD)
    for i in range(M - 1, -1, -1):
        ans += mod_com(L, i) * p
        p = p * 25 % MOD

    ans = (pow(26, L, MOD) - ans) % MOD
    print(ans)
    return


if __name__ == "__main__":
    main()


Fixed submission:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007


def main():
    K = int(readline())
    S = readline().strip()

    COM_MAX = 2 * 10**6

    fac, finv, inv = [0] * (COM_MAX + 1), [0] * (COM_MAX + 1), [0] * (COM_MAX + 1)
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1

    for i in range(2, COM_MAX + 1):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    def mod_com(n, r):
        if n < r:
            return 0
        if n < 0 or r < 0:
            return 0
        return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD

    M = len(S)
    L = K + M

    ans = 0
    p = pow(25, K + 1, MOD)
    for i in range(M - 1, -1, -1):
        ans += mod_com(L, i) * p
        p = p * 25 % MOD

    ans = (pow(26, L, MOD) - ans) % MOD
    print(ans)
    return


if __name__ == "__main__":
    main()
Problem p02632 (Python)

Buggy submission (status: Runtime Error):
import sys

K = int(sys.stdin.readline())
S = sys.stdin.readline().rstrip("\n")

# ## COMBINATION (MOD) ###
N_MAX = 10**6  # 問題サイズに合わせて変えておく
MOD = 10**9 + 7

inv = [0, 1]  # 逆元テーブル計算用テーブル

for i in range(2, N_MAX + 1):
    inv.append((-inv[MOD % i] * (MOD // i)) % MOD)

# K 文字追加
ans = 0

ln = len(S)

p1 = 1
p2 = 1
s2 = pow(26, K, MOD)

for i in range(1, K + 2):
    ans += (p1 * p2 * s2) % MOD
    ans %= MOD

    # print(p1, p2, s2)

    # pre
    p1 = (p1 * (ln + i - 1) * inv[i]) % MOD
    p2 = (p2 * 25) % MOD

    # suf
    s2 = (s2 * inv[26]) % MOD

print(ans)


Fixed submission:
import sys

K = int(sys.stdin.readline())
S = sys.stdin.readline().rstrip("\n")

# ## COMBINATION (MOD) ###
N_MAX = 10**6  # 問題サイズに合わせて変えておく
MOD = 10**9 + 7

inv = [0, 1]  # 逆元テーブル計算用テーブル

for i in range(2, N_MAX + 2):
    inv.append((-inv[MOD % i] * (MOD // i)) % MOD)

# K 文字追加
ans = 0

ln = len(S)

p1 = 1
p2 = 1
s2 = pow(26, K, MOD)

for i in range(1, K + 2):
    ans += (p1 * p2 * s2) % MOD
    ans %= MOD

    # print(p1, p2, s2)

    # pre
    p1 = (p1 * (ln + i - 1) * inv[i]) % MOD
    p2 = (p2 * 25) % MOD

    # suf
    s2 = (s2 * inv[26]) % MOD

print(ans)
Problem p02632 (Python)

Buggy submission (status: Runtime Error):
MOD = 10**9 + 7
K = int(input())
S = input()
N = len(S)


class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """

    def __init__(self, n_max, mod=10**9 + 7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n + 1):
            fac.append(fac[i - 1] * i % self.mod)
            facinv.append(facinv[i - 1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n + 1)
        modinv[1] = 1
        for i in range(2, n + 1):
            modinv[i] = self.mod - self.mod // i * modinv[self.mod % i] % self.mod
        return modinv


comb = Combination(1000000)
ans = 0
for i in range(K + 1):
    temp = comb(N + K - i - 1, N - 1)
    temp %= MOD
    temp *= pow(26, i, MOD)
    temp %= MOD
    temp *= pow(25, K - i, MOD)
    temp %= MOD
    ans += temp
    ans %= MOD
print(ans)


Fixed submission:
MOD = 10**9 + 7
K = int(input())
S = input()
N = len(S)


class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """

    def __init__(self, n_max, mod=10**9 + 7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n + 1):
            fac.append(fac[i - 1] * i % self.mod)
            facinv.append(facinv[i - 1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n + 1)
        modinv[1] = 1
        for i in range(2, n + 1):
            modinv[i] = self.mod - self.mod // i * modinv[self.mod % i] % self.mod
        return modinv


comb = Combination(2100000)
ans = 0
for i in range(K + 1):
    temp = comb(N + K - i - 1, N - 1)
    temp %= MOD
    temp *= pow(26, i, MOD)
    temp %= MOD
    temp *= pow(25, K - i, MOD)
    temp %= MOD
    ans += temp
    ans %= MOD
print(ans)
Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
// #include<bits/stdc++.h>
#define int long long
#define for0(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i <= (n); i++)
#define mp make_pair
#define all(x) x.begin(), x.end()
#define puts(x) cout << x << "\n"
#define endwith return
constexpr int mod = 1000000007;
using namespace std;
int input() {
  int t;
  cin >> t;
  return t;
}
int n, a25[234567], ans, c[234567];
string s;
//(a^p)%mod
int f1(int a, int p) {
  if (p == 1)
    return a;
  if (p % 2)
    return f1(a, p - 1) * a % mod;
  else
    return f1(a * a % mod, p / 2) % mod;
}
// pでわる→ *= f1(p, mod - 2);
signed main() {
  a25[0] = 1;
  c[0] = 1;
  cin >> n >> s;
  for1(i, n + s.size()) {
    a25[i] = a25[i - 1] * 25 % mod;
    c[i] = c[i - 1] * (n + s.size() - i + 1) % mod;
    c[i] = c[i] * f1(i, mod - 2) % mod;
  }
  ans = 1;
  for0(v, n + s.size()) ans = ans * 26 % mod;
  for0(i, s.size()) {
    int k = c[i] * a25[n + s.size() - i] % mod;
    ans -= k;
    if (ans < 0)
      ans += mod;
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
// #include<bits/stdc++.h>
#define int long long
#define for0(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i <= (n); i++)
#define mp make_pair
#define all(x) x.begin(), x.end()
#define puts(x) cout << x << "\n"
#define endwith return
constexpr int mod = 1000000007;
using namespace std;
int input() {
  int t;
  cin >> t;
  return t;
}
int n, a25[2345678], ans, c[2345678];
string s;
//(a^p)%mod
int f1(int a, int p) {
  if (p == 1)
    return a;
  if (p % 2)
    return f1(a, p - 1) * a % mod;
  else
    return f1(a * a % mod, p / 2) % mod;
}
// pでわる→ *= f1(p, mod - 2);
signed main() {
  a25[0] = 1;
  c[0] = 1;
  cin >> n >> s;
  for1(i, n + s.size()) {
    a25[i] = a25[i - 1] * 25 % mod;
    c[i] = c[i - 1] * (n + s.size() - i + 1) % mod;
    c[i] = c[i] * f1(i, mod - 2) % mod;
  }
  ans = 1;
  for0(v, n + s.size()) ans = ans * 26 % mod;
  for0(i, s.size()) {
    int k = c[i] * a25[n + s.size() - i] % mod;
    ans -= k;
    if (ans < 0)
      ans += mod;
  }
  cout << ans << endl;
}