alexjercan/bugnet huggingface dataset:
Problem p02632 (C++) — buggy submission, verdict: 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[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;
}

Error: 0

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[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;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i < n; i++)
#define rev(i, n) for (int i = n - 1; i >= 0; i--)
#define all(v) v.begin(), v.end()
#define P pair<int, int>
#define len(s) (int)s.size()
#define pb push_back

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
constexpr int mod = 1e9 + 7;
constexpr int inf = 3e18;

int K;
string S;
int mod_pow(int x, int y, int m = mod) {
  int res = 1;
  while (y > 0) {
    if (y & 1)
      (res *= x) %= m;
    (x *= x) %= m;
    y >>= 1;
  }
  return res;
}
vector<int> perm, inv;
void init_perm() {
  int x = 2e6 + 1;
  perm.resize(x);
  inv.resize(x);
  perm[0] = 1;
  REP(i, x + 1) perm[i] = perm[i - 1] * i % mod;
  inv[x] = mod_pow(perm[x], mod - 2);
  for (int i = x - 1; i >= 0; i--) {
    inv[i] = inv[i + 1] * (i + 1) % mod;
  }
}
int nCk(int x, int y) {
  if (x < y)
    return 0;
  return perm[x] * inv[x - y] % mod * inv[y] % mod;
}
signed main() {
  init_perm();
  cin >> K >> S;
  int N = K + len(S), M = len(S);
  int ans = 0;
  for (int i = M; i <= N; i++) {
    int p = nCk(N, i);
    int q = mod_pow(25, N - i);
    ans += p * q % mod;
    ans %= mod;
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i < n; i++)
#define rev(i, n) for (int i = n - 1; i >= 0; i--)
#define all(v) v.begin(), v.end()
#define P pair<int, int>
#define len(s) (int)s.size()
#define pb push_back

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
constexpr int mod = 1e9 + 7;
constexpr int inf = 3e18;

int K;
string S;
int mod_pow(int x, int y, int m = mod) {
  int res = 1;
  while (y > 0) {
    if (y & 1)
      (res *= x) %= m;
    (x *= x) %= m;
    y >>= 1;
  }
  return res;
}
vector<int> perm, inv;
void init_perm() {
  int x = 1e6 + 1;
  perm.resize(x);
  inv.resize(x);
  perm[0] = 1;
  REP(i, x + 1) perm[i] = perm[i - 1] * i % mod;
  inv[x] = mod_pow(perm[x], mod - 2);
  for (int i = x - 1; i >= 0; i--) {
    inv[i] = inv[i + 1] * (i + 1) % mod;
  }
}
int nCk(int x, int y) {
  if (x < y)
    return 0;
  return perm[x] * inv[x - y] % mod * inv[y] % mod;
}
signed main() {
  init_perm();
  cin >> K >> S;
  int N = K + len(S), M = len(S);
  int ans = 0;
  for (int i = M; i <= N; i++) {
    int p = nCk(N, i);
    int q = mod_pow(25, N - i);
    ans += p * q % mod;
    ans %= mod;
  }
  cout << ans << endl;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define Sz(a) ((int)(a).size())
const int maxn = 2000009;
const int MOD = 1e9 + 7;
int64_t fac[maxn], invfac[maxn];
int64_t pw(int64_t a, int64_t b) {
  int64_t c = 1;
  while (b) {
    if (b & 1ll)
      c = c * a % MOD;
    b >>= 1;
    a = a * a % MOD;
  }
  return c;
}
int64_t C(int a, int b) {
  return fac[a] * invfac[b] % MOD * invfac[a - b] % MOD;
}
int main() {
#ifdef LOCAL
  freopen("a.in", "r", stdin);
#endif
  ios_base::sync_with_stdio(false), cout.tie(0), cin.tie(0);
  fac[0] = 1;
  for (int i = 1; i < maxn; ++i)
    fac[i] = fac[i - 1] * i % MOD;
  invfac[maxn - 1] = pw(fac[maxn - 1], MOD - 2);
  for (int i = maxn - 2; i >= 0; --i)
    invfac[i] = invfac[i + 1] * (i + 1) % MOD;
  int K, n;
  string s;
  cin >> K >> s;
  n = Sz(s);
  int64_t ans = 1, deg = 1;
  for (int i = 0; i < K; ++i) {
    deg = deg * 25 % MOD;
    ans = (ans * 26 + C(n + i, n - 1) * deg) % MOD;
  }
  cout << ans << "\\n";

  return 0;
}
// 2020.06.23 19:49:09


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define Sz(a) ((int)(a).size())
const int maxn = 1000009;
const int MOD = 1e9 + 7;
int64_t fac[maxn], invfac[maxn];
int64_t pw(int64_t a, int64_t b) {
  int64_t c = 1;
  while (b) {
    if (b & 1ll)
      c = c * a % MOD;
    b >>= 1;
    a = a * a % MOD;
  }
  return c;
}
int64_t C(int a, int b) {
  return fac[a] * invfac[b] % MOD * invfac[a - b] % MOD;
}
int main() {
#ifdef LOCAL
  freopen("a.in", "r", stdin);
#endif
  ios_base::sync_with_stdio(false), cout.tie(0), cin.tie(0);
  fac[0] = 1;
  for (int i = 1; i < maxn; ++i)
    fac[i] = fac[i - 1] * i % MOD;
  invfac[maxn - 1] = pw(fac[maxn - 1], MOD - 2);
  for (int i = maxn - 2; i >= 0; --i)
    invfac[i] = invfac[i + 1] * (i + 1) % MOD;
  int K, n;
  string s;
  cin >> K >> s;
  n = Sz(s);
  int64_t ans = 1, deg = 1;
  for (int i = 0; i < K; ++i) {
    deg = deg * 25 % MOD;
    ans = (ans * 26 + C(n + i, n - 1) * deg) % MOD;
  }
  cout << ans << "\\n";

  return 0;
}
// 2020.06.23 19:49:09
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define MOD 1000000007
#define N 2000123
#define ll long long

using namespace std;

char cs[N];
int k, n, m;
string s;
ll fat[N], inv_fat[N], p[N], z[N];

ll gcd(ll a, ll b, ll &x, ll &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  ll x1, y1;
  ll g = gcd(b, a % b, x1, y1);
  x = y1;
  y = x1 - ((a / b) * y1);
  return g;
}

ll inv(ll a) {
  ll x, y;
  gcd(a, MOD, x, y);
  return (x + MOD) % MOD;
}

ll C(int a, int b) {
  return (((fat[a] * inv_fat[b]) % MOD) * inv_fat[a - b]) % MOD;
}

ll partial, ans;

int main() {
  scanf("%d %s", &k, cs);

  n = strlen(cs);
  fat[0] = inv_fat[0] = p[0] = z[0] = 1;
  for (int i = 1; i <= n + k + 5; ++i) {
    fat[i] = (fat[i - 1] * i) % MOD;
    inv_fat[i] = inv(fat[i]);
    p[i] = (p[i - 1] * 25LL) % MOD;
    z[i] = (z[i - 1] * 26LL) % MOD;
  }

  m = n - 1;
  for (int i = n; i <= n + k; ++i) {
    partial = (C(i - 1, m) * p[i - m - 1]) % MOD;
    // printf("%d %d %lld\\n",i - 1, m,  C(i - 1, m));

    ans = (ans + ((partial * z[n + k - i]) % MOD)) % MOD;

    // printf("%d %lld\\n", n + k - i, z[n + k - i]);
  }

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

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define MOD 1000000007
#define N 200123
#define ll long long

using namespace std;

char cs[N];
int k, n, m;
string s;
ll fat[N], inv_fat[N], p[N], z[N];

ll gcd(ll a, ll b, ll &x, ll &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  ll x1, y1;
  ll g = gcd(b, a % b, x1, y1);
  x = y1;
  y = x1 - ((a / b) * y1);
  return g;
}

ll inv(ll a) {
  ll x, y;
  gcd(a, MOD, x, y);
  return (x + MOD) % MOD;
}

ll C(int a, int b) {
  return (((fat[a] * inv_fat[b]) % MOD) * inv_fat[a - b]) % MOD;
}

ll partial, ans;

int main() {
  scanf("%d %s", &k, cs);

  n = strlen(cs);
  fat[0] = inv_fat[0] = p[0] = z[0] = 1;
  for (int i = 1; i <= n + k + 5; ++i) {
    fat[i] = (fat[i - 1] * i) % MOD;
    inv_fat[i] = inv(fat[i]);
    p[i] = (p[i - 1] * 25LL) % MOD;
    z[i] = (z[i - 1] * 26LL) % MOD;
  }

  m = n - 1;
  for (int i = n; i <= n + k; ++i) {
    partial = (C(i - 1, m) * p[i - m - 1]) % MOD;
    // printf("%d %d %lld\\n",i - 1, m,  C(i - 1, m));

    ans = (ans + ((partial * z[n + k - i]) % MOD)) % MOD;

    // printf("%d %lld\\n", n + k - i, z[n + k - i]);
  }

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

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

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<ll, ll> pii;
#define rep(i, x, y) for (int i = x; i < y; i++)
#define rept(i, x, y) for (int i = x; i <= y; i++)
#define per(i, x, y) for (int i = x; i >= y; i--)
#define all(x) x.begin(), x.end()
#define pb push_back
#define fi first
#define se second
#define mes(a, b) memset(a, b, sizeof a)
#define mp make_pair
#define dd(x) cout << #x << "=" << x << " "
#define de(x) cout << #x << "=" << x << "\\n"
#define debug() cout << "I love Miyamizu Mitsuha forever.\\n"
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 3e6 + 5;
ll fac[maxn];
string s;

ll qpow(ll a, ll b) {
  ll ans = 1;
  for (; b; b >>= 1, a = a * a % mod)
    if (b & 1)
      ans = ans * a % mod;
  return ans;
}

void init() {
  fac[0] = 1;
  rept(i, 1, 3000000) fac[i] = fac[i - 1] * i % mod;
}
ll c(ll n, ll k) {
  return fac[n] * qpow(fac[k], mod - 2) % mod * qpow(fac[n - k], mod - 2) % mod;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  init();
  int k;
  cin >> k >> s;
  ll ans = 0;
  int n = s.size();
  rept(i, 0, k) {
    ll val = 1;
    val = val * qpow(26, i) % mod * c(n - 1 + k - i, n - 1) % mod *
          qpow(25, k - i) % mod;
    //		dd(i);dd(val);dd(n-1+k-i);dd(n-1);de(k-i);
    ans = (ans + val) % mod;
  }
  cout << ans << "\\n";
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<ll, ll> pii;
#define rep(i, x, y) for (int i = x; i < y; i++)
#define rept(i, x, y) for (int i = x; i <= y; i++)
#define per(i, x, y) for (int i = x; i >= y; i--)
#define all(x) x.begin(), x.end()
#define pb push_back
#define fi first
#define se second
#define mes(a, b) memset(a, b, sizeof a)
#define mp make_pair
#define dd(x) cout << #x << "=" << x << " "
#define de(x) cout << #x << "=" << x << "\\n"
#define debug() cout << "I love Miyamizu Mitsuha forever.\\n"
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 5;
ll fac[maxn];
string s;

ll qpow(ll a, ll b) {
  ll ans = 1;
  for (; b; b >>= 1, a = a * a % mod)
    if (b & 1)
      ans = ans * a % mod;
  return ans;
}

void init() {
  fac[0] = 1;
  rept(i, 1, 1000000) fac[i] = fac[i - 1] * i % mod;
}
ll c(ll n, ll k) {
  return fac[n] * qpow(fac[k], mod - 2) % mod * qpow(fac[n - k], mod - 2) % mod;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  init();
  int k;
  cin >> k >> s;
  ll ans = 0;
  int n = s.size();
  rept(i, 0, k) {
    ll val = 1;
    val = val * qpow(26, i) % mod * c(n - 1 + k - i, n - 1) % mod *
          qpow(25, k - i) % mod;
    //		dd(i);dd(val);dd(n-1+k-i);dd(n-1);de(k-i);
    ans = (ans + val) % mod;
  }
  cout << ans << "\\n";
  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int N = 2000000 + 5, yzh = 1e9 + 7;

int k, n, fac[N], ifac[N];
char ch[N];

int quick_pow(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1)
      ans = 1ll * a * ans % yzh;
    b >>= 1, a = 1ll * a * a % yzh;
  }
  return ans;
}
int C(int n, int m) { return 1ll * fac[n] * ifac[m] % yzh * ifac[n - m] % yzh; }
int main() {
  scanf("%d%s", &k, ch + 1);
  n = strlen(ch + 1);
  ifac[0] = ifac[1] = fac[0] = 1;
  for (int i = 2; i <= n + k; i++)
    ifac[i] = -1ll * yzh / i * ifac[yzh % i] % yzh;
  for (int i = 1; i <= n + k; i++) {
    fac[i] = 1ll * fac[i - 1] * i % yzh;
    ifac[i] = 1ll * ifac[i] * ifac[i - 1] % yzh;
  }
  int ans = 0;
  for (int i = 0; i <= k; i++)
    (ans += 1ll * quick_pow(25, k - i) * quick_pow(26, i) % yzh *
            C(n + k - i - 1, n - 1) % yzh) %= yzh;
  printf("%d\\n", (ans + yzh) % yzh);
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int N = 1000000 + 5, yzh = 1e9 + 7;

int k, n, fac[N], ifac[N];
char ch[N];

int quick_pow(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1)
      ans = 1ll * a * ans % yzh;
    b >>= 1, a = 1ll * a * a % yzh;
  }
  return ans;
}
int C(int n, int m) { return 1ll * fac[n] * ifac[m] % yzh * ifac[n - m] % yzh; }
int main() {
  scanf("%d%s", &k, ch + 1);
  n = strlen(ch + 1);
  ifac[0] = ifac[1] = fac[0] = 1;
  for (int i = 2; i <= n + k; i++)
    ifac[i] = -1ll * yzh / i * ifac[yzh % i] % yzh;
  for (int i = 1; i <= n + k; i++) {
    fac[i] = 1ll * fac[i - 1] * i % yzh;
    ifac[i] = 1ll * ifac[i] * ifac[i - 1] % yzh;
  }
  int ans = 0;
  for (int i = 0; i <= k; i++)
    (ans += 1ll * quick_pow(25, k - i) * quick_pow(26, i) % yzh *
            C(n + k - i - 1, n - 1) % yzh) %= yzh;
  printf("%d\\n", (ans + yzh) % yzh);
  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL << 62
#define inf 1000000007

const int MAX = 5100000;
const int MOD = 1000000007;

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

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

int main() {
  ll k;
  string s;
  cin >> k >> s;
  ll n = s.size();
  COMinit();
  ll ans = 0;
  // 計算例
  //    cout << COM(100000, 50000) << endl;
  for (ll i = 0; i <= k; i++) {
    ll n1 = COM(n - 1 + k - i, n - 1);
    ll n2 = modpow(25, k - i, inf);
    ll n3 = modpow(26, i, inf);
    ll cnt = n1 * n2;
    cnt %= inf;
    cnt *= n3;
    cnt %= inf;
    ans += cnt;
    ans %= inf;
  }
  cout << ans;
  // your code goes here
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL << 62
#define inf 1000000007

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

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

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

int main() {
  ll k;
  string s;
  cin >> k >> s;
  ll n = s.size();
  COMinit();
  ll ans = 0;
  // 計算例
  //    cout << COM(100000, 50000) << endl;
  for (ll i = 0; i < k; i++) {
    ll n1 = COM(n - 1 + k - i, n - 1);
    ll n2 = modpow(25, k - i, inf);
    ll n3 = modpow(26, i, inf);
    ll cnt = n1 * n2;
    cnt %= inf;
    cnt *= n3;
    cnt %= inf;
    ans += cnt;
    ans %= inf;
  }
  cout << ans;
  // your code goes here
  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
ll n, m;
char str[1000010];
ll md = 1e9 + 7;
ll inv[2000010];
ll ksm[2000010];
ll ksmi(ll x, ll y) {
  ksm[0] = x;
  for (int i = 1; i <= 60; i++)
    ksm[i] = (ksm[i - 1] * ksm[i - 1]) % md;
  ll res = 1;
  for (int i = 0; i <= 60; i++)
    if (y & (1ll << i))
      res = (res * ksm[i]) % md;
  return res;
}
int main() {
  scanf("%lld%s", &n, &str);
  string s = str;
  m = s.size(), n += m;
  for (int i = 1; i < n - (m - 1) + 1; i++)
    inv[i] = ksmi(i, md - 2);
  vector<ll> com;
  ll t = 1;
  for (ll i = m - 1; i < n; i++) {
    // cout <<t<<" ##\\n";
    if (!(m - 1))
      com.push_back(1);
    else {
      com.push_back(t);
      t = (t * inv[i - (m - 1) + 1]) % md;
      t = (t * (i + 1)) % md;
    }
  }
  // for (int i=0;i<com.size();i++) cout <<com[i]<<" ";
  // cout <<"\\n";
  t = 1;
  for (int i = 0; i < com.size(); i++)
    com[i] = (com[i] * t) % md, t = (t * 25) % md;
  ll res = 0;
  for (int i = 0; i < com.size(); i++)
    res = (((res * 26) % md) + com[i]) % md;
  printf("%lld", res);
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
ll n, m;
char str[1000010];
ll md = 1e9 + 7;
ll inv[2000010];
ll ksm[2000010];
ll ksmi(ll x, ll y) {
  ksm[0] = x;
  for (int i = 1; i <= 60; i++)
    ksm[i] = (ksm[i - 1] * ksm[i - 1]) % md;
  ll res = 1;
  for (int i = 0; i <= 60; i++)
    if (y & (1ll << i))
      res = (res * ksm[i]) % md;
  return res;
}
int main() {
  scanf("%lld%s", &n, &str);
  string s = str;
  m = s.size(), n += m;
  for (int i = 1; i <= n; i++)
    inv[i] = ksmi(i, md - 2);
  vector<ll> com;
  ll t = 1;
  for (ll i = m - 1; i < n; i++) {
    // cout <<t<<" ##\\n";
    if (!(m - 1))
      com.push_back(1);
    else {
      com.push_back(t);
      t = (t * inv[i - (m - 1) + 1]) % md;
      t = (t * (i + 1)) % md;
    }
  }
  // for (int i=0;i<com.size();i++) cout <<com[i]<<" ";
  // cout <<"\\n";
  t = 1;
  for (int i = 0; i < com.size(); i++)
    com[i] = (com[i] * t) % md, t = (t * 25) % md;
  ll res = 0;
  for (int i = 0; i < com.size(); i++)
    res = (((res * 26) % md) + com[i]) % md;
  printf("%lld", res);
  return 0;
}
Problem p02632 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
#define MAX 2000001
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(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 modpow(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;
}
int main() {
  ll k;
  cin >> k;
  string s;
  cin >> s;
  ll n = s.size();
  ll ans = 0;
  COMinit();
  for (int i = 0; i <= k; i++) {
    ans +=
        (COM(k + n - i - 1, n - 1) * modpow(25, k - i) % MOD) * modpow(26, i);
    ans %= MOD;
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
#define MAX 1000001
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(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 modpow(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;
}
int main() {
  ll k;
  cin >> k;
  string s;
  cin >> s;
  ll n = s.size();
  ll ans = 0;
  COMinit();
  for (int i = 0; i <= k; i++) {
    ans +=
        (COM(k + n - i - 1, n - 1) * modpow(25, k - i) % MOD) * modpow(26, i);
    ans %= MOD;
  }
  cout << ans << endl;
}
Problem p02633 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

int main() {
  int X;
  scanf("%d", &X);
  printf("%d\\n", 360 / __gcd(X, 360));
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

int cnt[180];

int main() {
  int now = 0;
  int X;
  scanf("%d", &X);
  int ans = 1;
  int sum = 1;
  cnt[0] = 1;
  while (sum > 0) {
    now += X;
    ans++;
    while (now >= 360)
      now -= 360;
    if (now >= 180) {
      sum -= abs(cnt[now - 180]);
      cnt[now - 180]--;
      sum += abs(cnt[now - 180]);
    } else {
      sum -= abs(cnt[now]);
      cnt[now]++;
      sum += abs(cnt[now]);
    }
  }
  printf("%d\\n", ans);
}
Problem p02633 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  int sum = 0;
  int cnt = 0;
  while (sum == 0 || sum % 360 != 0) {
    sum += n;
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n;
  int sum = 0;
  int cnt = 0;
  while (sum == 0 || sum % 360 != 0) {
    sum += n;
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}