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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> P(N);
  rep(i, N) cin >> P[i];
  set<int> st, unite;
  rep(i, K) st.insert(P[i]);
  for (int i = K; i < N; i++) {
    if (P[i - K] == *(st.begin()) && P[i] > *(st.rbegin()))
      unite.insert(i);
    st.erase(P[i]);
    st.insert(P[i + K]);
  }
  int cnt = 1;
  bool flag = 0;
  for (int i = 1; i < N; i++) {
    if (P[i] > P[i - 1]) {
      cnt++;
      if (cnt >= K) {
        flag = 1;
        unite.insert(i);
      }
    } else
      cnt = 1;
  }
  cout << N - K + 1 - unite.size() + flag << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> P(N);
  rep(i, N) cin >> P[i];
  set<int> st, unite;
  rep(i, K) st.insert(P[i]);
  for (int i = K; i < N; i++) {
    if (P[i - K] == *(st.begin()) && P[i] > *(st.rbegin()))
      unite.insert(i);
    st.erase(P[i - K]);
    st.insert(P[i]);
  }
  int cnt = 1;
  bool flag = 0;
  for (int i = 1; i < N; i++) {
    if (P[i] > P[i - 1]) {
      cnt++;
      if (cnt >= K) {
        flag = 1;
        unite.insert(i);
      }
    } else
      cnt = 1;
  }
  cout << N - K + 1 - unite.size() + flag << endl;
  return 0;
}
Problem p02905 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <vector>
using namespace std;
using ll = long long int;
const ll MOD = 998244353;

vector<vector<int>> divs(1010101, vector<int>{});
vector<vector<int>> A_div(1010101, vector<int>{});
ll sum_AiAj[1010101];
vector<int> a(202020);

ll mod_pow(ll x, ll n) {
  ll ret = 1;
  while (n != 0) {
    if (n & 1) {
      ret = ret * x % MOD;
    }
    x = x * x % MOD;
    n = n >> 1;
  }
  return ret;
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i < 1000001; i++) {
    for (int j = 1; i * j < 1000001; j++) {
      divs[i * j].push_back(i);
    }
  }

  for (auto &v : a) {
    for (auto &w : divs[v]) {
      A_div[w].push_back(v);
    }
  }

  ll inv_mod2 = mod_pow(2, MOD - 2);

  for (int i = 0; i < 1000001; i++) {
    ll square_sum = 0;
    ll sum = 0;
    for (auto &v : A_div[i]) {
      square_sum += 1LL * v * v;
      sum += v;
    }
    square_sum %= MOD;
    sum %= MOD;
    sum_AiAj[i] = (sum * sum - square_sum + MOD) % MOD;
    sum_AiAj[i] *= inv_mod2;
    sum_AiAj[i] %= MOD;
  }

  ll ans = 0;
  for (int i = 1000000; i > 0; i--) {
    ll val = sum_AiAj[i];
    for (int j = 2; i * j < 1000001; j++) {
      val = (val - sum_AiAj[i * j] + MOD) % MOD;
    }
    sum_AiAj[i] = val;
    ans += val * mod_pow(i, MOD - 2);
    ans %= MOD;
  }
  cout << (ans + MOD) % MOD << endl;
  return 0;
}

Fixed submission:
#include <iostream>
#include <vector>
using namespace std;
using ll = long long int;
const ll MOD = 998244353;

vector<vector<int>> divs(1010101, vector<int>{});
vector<vector<int>> A_div(1010101, vector<int>{});
ll sum_AiAj[1010101];
vector<int> a(202020);

ll mod_pow(ll x, ll n) {
  ll ret = 1;
  while (n != 0) {
    if (n & 1) {
      ret = ret * x % MOD;
    }
    x = x * x % MOD;
    n = n >> 1;
  }
  return ret;
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i < 1000001; i++) {
    for (int j = 1; i * j < 1000001; j++) {
      divs[i * j].push_back(i);
    }
  }

  for (auto &v : a) {
    for (auto &w : divs[v]) {
      A_div[w].push_back(v);
    }
  }

  ll inv_mod2 = mod_pow(2, MOD - 2);

  for (int i = 0; i < 1000001; i++) {
    ll square_sum = 0;
    ll sum = 0;
    for (auto &v : A_div[i]) {
      square_sum += 1LL * v * v;
      sum += v;
    }
    square_sum %= MOD;
    sum %= MOD;
    sum_AiAj[i] = (sum * sum - square_sum + MOD) % MOD;
    sum_AiAj[i] *= inv_mod2;
    sum_AiAj[i] %= MOD;
  }

  ll ans = 0;
  for (int i = 1000000; i > 0; i--) {
    ll val = sum_AiAj[i];
    for (int j = 2; i * j < 1000001; j++) {
      val = (val - sum_AiAj[i * j] + MOD) % MOD;
    }
    sum_AiAj[i] = val;
    if (val == 0) {
      continue;
    }
    ans += val * mod_pow(i, MOD - 2);
    ans %= MOD;
  }
  cout << (ans + MOD) % MOD << endl;
  return 0;
}
Problem p02905 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 2, mod = 998244353;
int n, x, a[N], inv[N], w[N];
int main() {
  inv[1] = 1;
  for (int i = 2; i < N; i++)
    inv[i] = (-1ll * inv[mod % i] * (mod / i) % mod + mod) % mod;
  scanf("%d", &n);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    (a[x] += x) %= mod;
    (ans += mod - x) %= mod;
  } // w[1]=1;
  for (int i = 1; i < N; i++) {
    int cnt = 0;
    (w[i] += inv[i]) %= mod;
    for (int j = i + i; j < N; j += i)
      (w[j] += mod - w[i]) %= mod, (cnt += a[j]) %= mod;
    (cnt += a[i]) %= mod;
    // cout<<cnt<<" "<<i<<" "<<w[i]<<endl;
    (ans += 1ll * cnt * cnt % mod * w[i] % mod) %= mod;
  }
  ans = (1ll * ans * inv[2] % mod + mod) % mod;
  cout << ans;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 2, mod = 998244353;
int n, x, a[N], inv[N], w[N];
int main() {
  inv[1] = 1;
  for (int i = 2; i < N; i++)
    inv[i] = (-1ll * inv[mod % i] * (mod / i) % mod + mod) % mod;
  scanf("%d", &n);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    (a[x] += x) %= mod;
    (ans += mod - x) %= mod;
  } // w[1]=1;
  for (int i = 1; i < N; i++) {
    int cnt = 0;
    (w[i] += inv[i]) %= mod;
    for (int j = i + i; j < N; j += i)
      (w[j] += mod - w[i]) %= mod, (cnt += a[j]) %= mod;
    (cnt += a[i]) %= mod;
    // cout<<cnt<<" "<<i<<" "<<w[i]<<endl;
    (ans += 1ll * cnt * cnt % mod * w[i] % mod) %= mod;
  }
  ans = (1ll * ans * inv[2] % mod + mod) % mod;
  cout << ans;
}
Problem p02905 (C++)

Buggy submission (status: Runtime Error):
// পূর্ণিমা সন্ধ্যায় তোমার রজনী গন্ধায়
// রূপসাগরের পাড়ের পানে উদাসী মন ধায়
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
typedef long long ll;
const long long M = 1e5 + 20, MX = 1e6 + 20, mod = 998244353;
ll ara[M], inv[MX];
vi dvs[MX];
void invrs(ll m) {
  inv[1] = 1;
  for (ll i = 2; i <= m; i++) {
    inv[i] = (mod - ((mod / i) * inv[mod % i]) % mod) % mod;
    //        if (i == 2) cout << "inv " << inv[i] << endl;
  }
}
ll mx = 0, sm = 0, ans = 0, csm[MX], cnt[MX];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> ara[i];
    cnt[ara[i]]++;
    sm = (sm + ara[i]) % mod;
    mx = max(mx, ara[i]);
  }
  invrs(mx);
  for (int i = 1; i <= mx; i++) {
    for (int j = i; j <= mx; j += i) {
      dvs[j].pb(i);
      if (cnt[j] > 0)
        csm[i] = (csm[i] + (cnt[j] * j)) % mod;
    }
  }
  for (int i = 1; i <= mx; i++) {
    csm[i] = (csm[i] * csm[i]) % mod;
    // cout << i << " " << csm[i] << endl;
  }
  for (int i = mx; i >= 1; i--) {
    ans = (ans + csm[i] * inv[i]) % mod;
    // cout << i << " " << csm[i] << " " << inv[i] << endl;
    // cout << ans << endl;
    for (int j : dvs[i]) {
      csm[j] = (csm[j] + (mod - csm[i])) % mod;
    }
  }
  ans = ((ans + mod - sm % mod) * inv[2]) % mod;
  cout << ans << endl;
  return 0;
}


Fixed submission:
// পূর্ণিমা সন্ধ্যায় তোমার রজনী গন্ধায়
// রূপসাগরের পাড়ের পানে উদাসী মন ধায়
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
typedef long long ll;
const long long M = 1e5 + 20, MX = 1e6 + 20, mod = 998244353;
ll ara[2 * M], inv[MX];
vi dvs[MX];
void invrs(ll m) {
  inv[1] = 1;
  for (ll i = 2; i <= m; i++) {
    inv[i] = (mod - ((mod / i) * inv[mod % i]) % mod) % mod;
    //        if (i == 2) cout << "inv " << inv[i] << endl;
  }
}
ll mx = 0, sm = 0, ans = 0, csm[MX], cnt[MX];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> ara[i];
    cnt[ara[i]]++;
    sm = (sm + ara[i]) % mod;
    mx = max(mx, ara[i]);
  }
  invrs(mx);
  for (int i = 1; i <= mx; i++) {
    for (int j = i; j <= mx; j += i) {
      dvs[j].pb(i);
      if (cnt[j] > 0)
        csm[i] = (csm[i] + (cnt[j] * j)) % mod;
    }
  }
  for (int i = 1; i <= mx; i++) {
    csm[i] = (csm[i] * csm[i]) % mod;
    // cout << i << " " << csm[i] << endl;
  }
  for (int i = mx; i >= 1; i--) {
    ans = (ans + csm[i] * inv[i]) % mod;
    // cout << i << " " << csm[i] << " " << inv[i] << endl;
    // cout << ans << endl;
    for (int j : dvs[i]) {
      csm[j] = (csm[j] + (mod - csm[i])) % mod;
    }
  }
  ans = ((ans + mod - sm % mod) * inv[2]) % mod;
  cout << ans << endl;
  return 0;
}
Problem p02905 (C++)

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

const int mod = 998244353;
const int M = 1000000;

int N;
int A[100000];
long C[M + 1];
void sub() {
  for (int i = 1; i <= M; ++i) {
    long sum = 0;
    for (int k = i; k <= M; k += i) {
      sum += C[k];
    }
    C[i] = sum % mod;
  }

  for (int i = 1; i <= M; ++i) {
    C[i] = C[i] * C[i] % mod;
  }

  for (int i = M; i >= 1; --i) {
    for (int k = 2 * i; k <= M; k += i) {
      C[i] += mod - C[k];
    }
    C[i] %= mod;
  }
}

long powmod(long b, long e) {
  if (e == 0)
    return 1;
  if (e % 2 == 1)
    return b * powmod(b, e - 1) % mod;
  long t = powmod(b, e / 2);
  return t * t % mod;
}

long inv(long n) { return powmod(n, mod - 2); }

int main() {
  cin >> N;
  for (int i = 0; i < N; ++i) {
    int a;
    cin >> a;
    A[i] = a;
    C[a] += a;
    if (C[a] >= mod)
      C[a] -= mod;
  }
  sub();

  long ans = 0;
  for (int i = 1; i <= M; ++i) {
    ans += inv(i) * C[i] % mod;
  }
  ans %= mod;

  long sum = accumulate(A, A + N, 0l) % mod;
  ans = (ans + mod - sum) * inv(2) % mod;
  cout << ans << endl;
}

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

const int mod = 998244353;
const int M = 1000000;

int N;
int A[200000];
long C[M + 1];
void sub() {
  for (int i = 1; i <= M; ++i) {
    long sum = 0;
    for (int k = i; k <= M; k += i) {
      sum += C[k];
    }
    C[i] = sum % mod;
  }

  for (int i = 1; i <= M; ++i) {
    C[i] = C[i] * C[i] % mod;
  }

  for (int i = M; i >= 1; --i) {
    for (int k = 2 * i; k <= M; k += i) {
      C[i] += mod - C[k];
    }
    C[i] %= mod;
  }
}

long powmod(long b, long e) {
  if (e == 0)
    return 1;
  if (e % 2 == 1)
    return b * powmod(b, e - 1) % mod;
  long t = powmod(b, e / 2);
  return t * t % mod;
}

long inv(long n) { return powmod(n, mod - 2); }

int main() {
  cin >> N;
  for (int i = 0; i < N; ++i) {
    int a;
    cin >> a;
    A[i] = a;
    C[a] += a;
    if (C[a] >= mod)
      C[a] -= mod;
  }
  sub();

  long ans = 0;
  for (int i = 1; i <= M; ++i) {
    ans += inv(i) * C[i] % mod;
  }
  ans %= mod;

  long sum = accumulate(A, A + N, 0l) % mod;
  ans = (ans + mod - sum) * inv(2) % mod;
  cout << ans << endl;
}
Problem p02905 (C++)

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

using namespace std;
#define ll long long
const int N = 1000 + 1, MOD = 998244353;
int cnt[N], S[N], _S[N];
vector<int> Div[N];

int sum(int a, int b) { return a + b - (a + b >= MOD ? MOD : 0); }
int mul(ll a, ll b) { return a * b % MOD; }

int main() {
  for (int i = N - 1; i >= 1; i--)
    for (int j = i; j < N; j += i)
      Div[j].push_back(i);
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0, x; i < n; i++)
    cin >> x, cnt[x]++;
  int ans = 0;
  for (int i = 1; i < N; i++)
    if (cnt[i]) {
      ans = sum(ans, mul(i, 1ll * cnt[i] * (cnt[i] - 1) / 2));
      int res = 0;
      for (int d : Div[i])
        _S[d] = S[d];
      for (int d : Div[i]) {
        res = sum(res, mul(S[d], i / d));
        for (int _d : Div[d])
          if (_d != d)
            S[_d] = sum(S[_d], MOD - S[d]);
      }
      ans = sum(ans, mul(res, cnt[i]));
      for (int d : Div[i])
        S[d] = sum(_S[d], mul(i, cnt[i]));
    }
  cout << ans << "\n";

  return 0;
}


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

using namespace std;
#define ll long long
const int N = 1e6 + 1, MOD = 998244353;
int cnt[N], S[N], _S[N];
vector<int> Div[N];

int sum(int a, int b) { return a + b - (a + b >= MOD ? MOD : 0); }
int mul(ll a, ll b) { return a * b % MOD; }

int main() {
  for (int i = N - 1; i >= 1; i--)
    for (int j = i; j < N; j += i)
      Div[j].push_back(i);
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0, x; i < n; i++)
    cin >> x, cnt[x]++;
  int ans = 0;
  for (int i = 1; i < N; i++)
    if (cnt[i]) {
      ans = sum(ans, mul(i, 1ll * cnt[i] * (cnt[i] - 1) / 2));
      int res = 0;
      for (int d : Div[i])
        _S[d] = S[d];
      for (int d : Div[i]) {
        res = sum(res, mul(S[d], i / d));
        for (int _d : Div[d])
          if (_d != d)
            S[_d] = sum(S[_d], MOD - S[d]);
      }
      ans = sum(ans, mul(res, cnt[i]));
      for (int d : Div[i])
        S[d] = sum(_S[d], mul(i, cnt[i]));
    }
  cout << ans << "\n";

  return 0;
}
Problem p02905 (C++)

Buggy submission (status: Runtime Error):
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()
#define pb push_back

#define error(x) cout << #x << " = " << x << endl

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;

const int N = 1e6 + 20, mod = 998244353;
int n, a[N], ans;
int sum[N], val[N];
vector<int> dv[N];

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

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

  for (int i = 1; i < N; i++)
    for (int j = i; j < N; j += i)
      dv[j].pb(i);

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> a[i];

    for (int x : dv[a[i]]) {
      val[x] = (val[x] + 1ll * sum[x] * a[i]) % mod;
      sum[x] = (sum[x] + a[i]) % mod;
    }
  }

  for (int i = N; i >= 0; i--) {
    ans = (ans + 1ll * val[i] * pw(i, mod - 2)) % mod;
    for (int j : dv[i]) {
      if (i == j)
        continue;
      val[j] = (val[j] - val[i] + mod) % mod;
    }
  }

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


Fixed submission:
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()
#define pb push_back

#define error(x) cout << #x << " = " << x << endl

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;

const int N = 1e6 + 20, mod = 998244353;
int n, a[N], ans;
int sum[N], val[N];
vector<int> dv[N];

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

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

  for (int i = 1; i < N; i++)
    for (int j = i; j < N; j += i)
      dv[j].pb(i);

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> a[i];

    for (int x : dv[a[i]]) {
      val[x] = (val[x] + 1ll * sum[x] * a[i]) % mod;
      sum[x] = (sum[x] + a[i]) % mod;
    }
  }

  for (int i = N - 1; i > 0; i--) {
    ans = (ans + 1ll * val[i] * pw(i, mod - 2)) % mod;
    for (int j : dv[i]) {
      if (i == j)
        continue;
      val[j] = (val[j] - val[i] + mod) % mod;
    }
  }

  cout << ans << '\n';
}
Problem p02905 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>

using namespace std;

using ll = long long;

int const nmax = 1000000;
int const modulo = 998244353;
int v[1 + nmax];
ll sum[1 + nmax], sol[1 + nmax];

void gcd(int a, int b, int &x, int &y) {
  if (b == 0) {
    x = 1;
    y = 0;
  } else {
    gcd(b, a % b, x, y);
    int aux = x;
    x = y;
    y = aux - a / b * y;
  }
}

int inv(int number) {
  int x, y;
  gcd(number, modulo, x, y);
  x %= modulo;
  if (x < 0)
    x += modulo;
  return x;
}

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

  int n;
  cin >> n;

  for (int i = 1; i <= n; i++) {
    cin >> v[i];
    sum[v[i]] += v[i];
  }

  for (int i = 1; i <= nmax; i++)
    for (int j = 2 * i; j <= nmax; j += i)
      sum[i] += sum[j];
  ll result = 0, result2 = 0;

  for (int i = 1; i < n; i++)
    for (int j = i + 1; j <= n; j++) {
      result2 += (1LL * v[i] * v[j] / __gcd(v[i], v[j])) % modulo;
      if (modulo <= result2)
        result2 -= modulo;
    }

  for (int i = nmax; 1 <= i; i--) {
    sol[i] = 1LL * (sum[i] / i) % modulo * (sum[i] % modulo) % modulo;
    for (int j = 2 * i; j <= nmax; j += i) {
      sol[i] -= 1LL * sol[j] * (j / i) % modulo;
      if (sol[i] < 0)
        sol[i] += modulo;
    }

    result += sol[i];
    if (modulo <= result)
      result -= modulo;
  }
  cout << 1LL * ((modulo + result - sum[1] % modulo) * inv(2)) % modulo;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>

using namespace std;

using ll = long long;

int const nmax = 1000000;
int const modulo = 998244353;
int v[1 + nmax];
ll sum[1 + nmax], sol[1 + nmax];

void gcd(int a, int b, int &x, int &y) {
  if (b == 0) {
    x = 1;
    y = 0;
  } else {
    gcd(b, a % b, x, y);
    int aux = x;
    x = y;
    y = aux - a / b * y;
  }
}

int inv(int number) {
  int x, y;
  gcd(number, modulo, x, y);
  x %= modulo;
  if (x < 0)
    x += modulo;
  return x;
}

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

  int n;
  cin >> n;

  for (int i = 1; i <= n; i++) {
    cin >> v[i];
    sum[v[i]] += v[i];
  }

  for (int i = 1; i <= nmax; i++)
    for (int j = 2 * i; j <= nmax; j += i)
      sum[i] += sum[j];
  ll result = 0;

  for (int i = nmax; 1 <= i; i--) {
    sol[i] = 1LL * (sum[i] / i) % modulo * (sum[i] % modulo) % modulo;
    for (int j = 2 * i; j <= nmax; j += i) {
      sol[i] -= 1LL * sol[j] * (j / i) % modulo;
      if (sol[i] < 0)
        sol[i] += modulo;
    }

    result += sol[i];
    if (modulo <= result)
      result -= modulo;
  }
  cout << 1LL * ((modulo + result - sum[1] % modulo) * inv(2)) % modulo;
  return 0;
}
Problem p02905 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define rrep(i, a, b) for (int i = (a); i >= (b); --i)
#define PB push_back
#define ar2 array<int, 2>
typedef long long LL;
const int P = 998244353;
const int N = 2e5, M = 1e6;
const double pi = acos(-1);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

LL n, a[N + 5], sum[M + 5], sum2[M + 5];
int cnt[M + 5];
vector<int> fac[M + 5];

LL pw(LL x, int n) {
  LL res = 1;
  for (; n; n >>= 1, x = x * x % P)
    if (n & 1)
      res = res * x % P;
  return res;
}
void add(LL &x, LL y) {
  x += y;
  if (x >= P)
    x -= P;
}
void sub(LL &x, LL y) {
  x -= y;
  if (x < 0)
    x += P;
}

int main() {
  freopen("test.in", "r", stdin);
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  rep(i, 1, n) cin >> a[i];
  rep(i, 1, M) for (int j = i + i; j <= M; j += i) fac[j].push_back(i);
  rep(i, 1, n) {
    for (auto x : fac[a[i]])
      add(sum[x], a[i]), add(sum2[x], a[i] * a[i] % P), ++cnt[x];
    add(sum[a[i]], a[i]), add(sum2[a[i]], a[i] * a[i] % P), ++cnt[a[i]];
  }
  LL ans = 0, inv2 = pw(2, P - 2);
  rrep(i, M, 1) if (cnt[i]) {
    LL x = sum[i], y = sum2[i];
    x = x * x % P, sub(x, y), x = x * inv2 % P;
    sum2[i] = x;
  }
  rrep(i, M, 1) if (cnt[i]) {
    add(ans, sum2[i] * pw(i, P - 2) % P);
    for (auto x : fac[i])
      sub(sum2[x], sum2[i]);
    // cout<<i<<" "<<sum2[i]<<" "<<cnt[i]<<endl;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define rrep(i, a, b) for (int i = (a); i >= (b); --i)
#define PB push_back
#define ar2 array<int, 2>
typedef long long LL;
const int P = 998244353;
const int N = 2e5, M = 1e6;
const double pi = acos(-1);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

LL n, a[N + 5], sum[M + 5], sum2[M + 5];
int cnt[M + 5];
vector<int> fac[M + 5];

LL pw(LL x, int n) {
  LL res = 1;
  for (; n; n >>= 1, x = x * x % P)
    if (n & 1)
      res = res * x % P;
  return res;
}
void add(LL &x, LL y) {
  x += y;
  if (x >= P)
    x -= P;
}
void sub(LL &x, LL y) {
  x -= y;
  if (x < 0)
    x += P;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  rep(i, 1, n) cin >> a[i];
  rep(i, 1, M) for (int j = i + i; j <= M; j += i) fac[j].push_back(i);
  rep(i, 1, n) {
    for (auto x : fac[a[i]])
      add(sum[x], a[i]), add(sum2[x], a[i] * a[i] % P), ++cnt[x];
    add(sum[a[i]], a[i]), add(sum2[a[i]], a[i] * a[i] % P), ++cnt[a[i]];
  }
  LL ans = 0, inv2 = pw(2, P - 2);
  rrep(i, M, 1) if (cnt[i]) {
    LL x = sum[i], y = sum2[i];
    x = x * x % P, sub(x, y), x = x * inv2 % P;
    sum2[i] = x;
  }
  rrep(i, M, 1) if (cnt[i]) {
    add(ans, sum2[i] * pw(i, P - 2) % P);
    for (auto x : fac[i])
      sub(sum2[x], sum2[i]);
    // cout<<i<<" "<<sum2[i]<<" "<<cnt[i]<<endl;
  }
  cout << ans << endl;
}
Problem p02905 (Python)

Buggy submission (status: Runtime Error):
import sys


def prepare(n, MOD):
    f = 1
    factorials = [1]
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv

    solo_invs = [0] + [f * i % MOD for f, i in zip(factorials, invs[1:])]

    return factorials, invs, solo_invs


def decompose_inverses(solo_invs, MOD):
    # 各整数 g に対して、g の約数である各 i について dcm[i] を全て足すと 1/g になるような数列を作成
    n = len(solo_invs)
    dcm = solo_invs.copy()
    for i in range(1, n):
        d = dcm[i]
        for j in range(2 * i, n, i):
            dcm[j] -= d
    for i in range(1, n):
        dcm[i] %= MOD
    return dcm


n, *aaa = map(int, sys.stdin.buffer.read().split())
MOD = 998244353
LIMIT = max(aaa)
count = [0] * (LIMIT + 1)
double = [0] * (LIMIT + 1)
for a in aaa:
    count[a] += a
    double[a] += a * a
_, _, solo_invs = prepare(LIMIT, MOD)
dcm = decompose_inverses(solo_invs, MOD)

ans = 0
inv2 = solo_invs[2]
for d in range(1, LIMIT + 1):
    ans = (ans + dcm[d] * (sum(count[d::d]) ** 2 - sum(double[d::d])) * inv2) % MOD
print(ans)


Fixed submission:
import sys


def prepare(n, MOD):
    f = 1
    factorials = [1]
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv

    solo_invs = [0] + [f * i % MOD for f, i in zip(factorials, invs[1:])]

    return factorials, invs, solo_invs


def decompose_inverses(solo_invs, MOD):
    # 各整数 g に対して、g の約数である各 i について dcm[i] を全て足すと 1/g になるような数列を作成
    n = len(solo_invs)
    dcm = solo_invs[:]
    for i in range(1, n):
        d = dcm[i]
        for j in range(2 * i, n, i):
            dcm[j] -= d
    for i in range(1, n):
        dcm[i] %= MOD
    return dcm


n, *aaa = map(int, sys.stdin.buffer.read().split())
MOD = 998244353
LIMIT = max(aaa)
count = [0] * (LIMIT + 1)
double = [0] * (LIMIT + 1)
for a in aaa:
    count[a] += a
    double[a] += a * a
_, _, solo_invs = prepare(LIMIT, MOD)
dcm = decompose_inverses(solo_invs, MOD)

ans = 0
inv2 = solo_invs[2]
for d in range(1, LIMIT + 1):
    ans = (ans + dcm[d] * (sum(count[d::d]) ** 2 - sum(double[d::d])) * inv2) % MOD
print(ans)
Problem p02906 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i, n) for (short i = 0; i < n; ++i)
typedef pair<int, int> P;
int par[100006], siz[100006];
void init(int n) {
  rep(i, n) {
    par[i] = i;
    siz[i] = 1;
  }
}
int find(int x) {
  if (par[x] == x)
    return x;
  return par[x] = find(par[x]);
}
void unite(int x, int y) {
  x = find(x), y = find(y);
  if (x == y)
    return;
  if (siz[x] < siz[y])
    swap(x, y);
  par[y] = x;
  siz[x] += siz[y];
}

vector<P> v1;
signed main() {
  int n, m, q;
  cin >> n >> m >> q;
  init(n);
  rep(i, q) {
    int a, b, c;
    cin >> a >> b >> c;
    if (c)
      v1.push_back(P(a, b));
    else
      unite(a, b);
  }

  if (v1.size()) {
    set<int> S;
    rep(i, n) S.insert(find(i));
    if (S.size() <= 2) {
      puts("No");
      return 0;
    }
    rep(i, v1.size()) {
      if (find(v1[i].first) == find(v1[i].second)) {
        puts("No");
        return 0;
      }
    }
    int M = 0;
    for (auto itr = S.begin(); itr != S.end(); itr++) {
      M += siz[find(*itr)] - 1;
    }
    int z = S.size();
    M += z * (z - 1) / 2;
    if (n - 1 < m && m <= M)
      puts("Yes");
    else
      puts("No");
  } else {
    if (m == n - 1)
      puts("Yes");
    else
      puts("No");
  }
}

Fixed submission:
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; ++i)
typedef pair<int, int> P;
int par[100006], siz[100006];
void init(int n) {
  rep(i, n) {
    par[i] = i;
    siz[i] = 1;
  }
}
int find(int x) {
  if (par[x] == x)
    return x;
  return par[x] = find(par[x]);
}
void unite(int x, int y) {
  x = find(x), y = find(y);
  if (x == y)
    return;
  if (siz[x] < siz[y])
    swap(x, y);
  par[y] = x;
  siz[x] += siz[y];
}

vector<P> v1;
signed main() {
  int n, m, q;
  cin >> n >> m >> q;
  init(n);
  rep(i, q) {
    int a, b, c;
    cin >> a >> b >> c;
    if (c)
      v1.push_back(P(a, b));
    else
      unite(a, b);
  }

  if (v1.size()) {
    set<int> S;
    rep(i, n) S.insert(find(i));
    if (S.size() <= 2) {
      puts("No");
      return 0;
    }
    rep(i, v1.size()) {
      if (find(v1[i].first) == find(v1[i].second)) {
        puts("No");
        return 0;
      }
    }
    int M = 0;
    for (auto itr = S.begin(); itr != S.end(); itr++) {
      M += siz[find(*itr)] - 1;
    }
    int z = S.size();
    M += z * (z - 1) / 2;
    if (n - 1 < m && m <= M)
      puts("Yes");
    else
      puts("No");
  } else {
    if (m == n - 1)
      puts("Yes");
    else
      puts("No");
  }
}
Problem p02906 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;
#define rep(i, n) for (UL i = 0; i < (n); i++)

struct UF {
  UL N;
  vector<UL> V;
  UL Z;
  void init(UL n) {
    N = n;
    V.resize(N);
    Z = N;
    rep(i, N) V[i] = i;
  }
  UL root(UL a) {
    if (V[a] == a)
      return a;
    return root(V[a]);
  }
  void unite(UL a, UL b) {
    a = root(a), b = root(b);
    if (a != b)
      Z--;
    V[a] = b;
  }
};

struct Problem {
public:
  LL N, M, Q;
  UF F;
  vector<pair<UL, UL>> Q1;
  vector<pair<UL, UL>> Q2;

  void Solve() {
    scanf("%lld%lld%lld", &N, &M, &Q);
    F.init(N);
    rep(i, Q) {
      UL a, b, c;
      scanf("%u%u%u", &a, &b, &c);
      if (c == 0)
        Q1.push_back({a, b});
      else
        Q2.push_back({a, b});
    }
    for (auto &p : Q1)
      F.unite(p.first, p.second);
    for (auto &e : Q2)
      if (F.root(e.first) == F.root(e.second)) {
        printf("No");
        return;
      }
    LL X = F.Z;
    if (M > (N - 1) + (X - 2) * (X - 1) / 2) {
      printf("No");
      return;
    }
    if (M < (N - 1)) {
      printf("No");
      return;
    }
    if (Q2.size()) {
      if (M < (N)) {
        printf("No");
        return;
      }
      if (F.Z <= 2) {
        printf("No");
        return;
      }
    }
    printf("Yes");
  }
};

int main() {
  unique_ptr<Problem> p(new Problem());
  p->Solve();
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;
#define rep(i, n) for (UL i = 0; i < (n); i++)

struct UF {
  UL N;
  vector<UL> V;
  UL Z;
  void init(UL n) {
    N = n;
    V.resize(N);
    Z = N;
    rep(i, N) V[i] = i;
  }
  UL root(UL a) {
    if (V[a] == a)
      return a;
    return V[a] = root(V[a]);
  }
  void unite(UL a, UL b) {
    a = root(a), b = root(b);
    if (a != b)
      Z--;
    V[a] = b;
  }
};

struct Problem {
public:
  LL N, M, Q;
  UF F;
  vector<pair<UL, UL>> Q1;
  vector<pair<UL, UL>> Q2;

  void Solve() {
    scanf("%lld%lld%lld", &N, &M, &Q);
    F.init(N);
    rep(i, Q) {
      UL a, b, c;
      scanf("%u%u%u", &a, &b, &c);
      if (c == 0)
        Q1.push_back({a, b});
      else
        Q2.push_back({a, b});
    }
    for (auto &p : Q1)
      F.unite(p.first, p.second);
    for (auto &e : Q2)
      if (F.root(e.first) == F.root(e.second)) {
        printf("No");
        return;
      }
    LL X = F.Z;
    if (M > (N - 1) + (X - 2) * (X - 1) / 2) {
      printf("No");
      return;
    }
    if (M < (N - 1)) {
      printf("No");
      return;
    }
    if (Q2.size()) {
      if (M < (N)) {
        printf("No");
        return;
      }
      if (F.Z <= 2) {
        printf("No");
        return;
      }
    }
    printf("Yes");
  }
};

int main() {
  unique_ptr<Problem> p(new Problem());
  p->Solve();
  return 0;
}
Problem p02906 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define popCnt(x) (__builtin_popcountll(x))
typedef long long Long;

const int N = 1e5 + 5;

vector<int> adj[2][N];

int comp[N];

void dfs(int node, int id) {
  if (comp[node] == id)
    return;
  comp[node] = id;
  for (int x : adj[0][node]) {
    dfs(x, id);
  }
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  int n, m, q;
  cin >> n >> m >> q;

  bool type_1_appeared = false;
  while (q--) {
    int u, v, c;
    cin >> u >> v >> c;
    ++u, ++v;
    adj[c][u].push_back(v);
    adj[c][v].push_back(u);
    type_1_appeared |= (c == 1);
  }

  int cnt_comps = 0;
  for (int i = 1; i <= n; ++i) {
    if (comp[i] == 0) {
      dfs(i, i);
      ++cnt_comps;
    }
  }

  for (int i = 1; i <= n; ++i) {
    for (int x : adj[1][i]) {
      if (comp[i] == comp[x]) {
        cout << "No" << endl;
        return 0;
      }
    }
  }

  int mn = n;
  Long mx = n - cnt_comps + 1LL * cnt_comps * (cnt_comps - 1) / 2;
  if (!type_1_appeared) {
    mn = n - 1;
  }
  if (cnt_comps == 2 && type_1_appeared) {
    cout << "No" << endl;
    return 0;
  }

  if (mn <= m && m <= mx) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define popCnt(x) (__builtin_popcountll(x))
typedef long long Long;

const int N = 1e5 + 5;

vector<int> adj[2][N];

int comp[N];

void dfs(int node, int id) {
  if (comp[node] == id)
    return;
  comp[node] = id;
  for (int x : adj[0][node]) {
    dfs(x, id);
  }
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  int n, q;
  Long m;
  cin >> n >> m >> q;

  bool type_1_appeared = false;
  while (q--) {
    int u, v, c;
    cin >> u >> v >> c;
    ++u, ++v;
    adj[c][u].push_back(v);
    adj[c][v].push_back(u);
    type_1_appeared |= (c == 1);
  }

  int cnt_comps = 0;
  for (int i = 1; i <= n; ++i) {
    if (comp[i] == 0) {
      dfs(i, i);
      ++cnt_comps;
    }
  }

  for (int i = 1; i <= n; ++i) {
    for (int x : adj[1][i]) {
      if (comp[i] == comp[x]) {
        cout << "No" << endl;
        return 0;
      }
    }
  }

  int mn = n;
  Long mx = n - cnt_comps + 1LL * cnt_comps * (cnt_comps - 1) / 2;
  if (!type_1_appeared) {
    mn = n - 1;
  }
  if (cnt_comps == 2 && type_1_appeared) {
    cout << "No" << endl;
    return 0;
  }

  if (mn <= m && m <= mx) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p02906 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>

typedef long long LL;
const int MN = 100005, MQ = 100005;

int N, Q;
LL M;
int pa[MN];
int fp(int x) { return pa[x] ? pa[x] = fp(pa[x]) : x; }
int qu[MQ], qv[MQ], K;
int E;

int main() {
  scanf("%d%lld%d", &N, &M, &Q);
  for (int i = 1; i <= Q; ++i) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    ++x, ++y;
    if (z == 0) {
      if ((x = fp(x)) != (y = fp(y)))
        pa[y] = x, ++E;
    } else
      qu[++K] = x, qv[K] = y;
  }
  if (!K)
    return puts("Yes"), 0;
  if (M == N - 1)
    return puts("No"), 1;
  for (int i = 1; i <= K; ++i)
    if ((qu[i] = fp(qu[i])) == (qv[i] = fp(qv[i])))
      return puts("No"), 0;
  int C = N - E;
  if (C == 2)
    return puts("No"), 0;
  if (M > E + (LL)C * (C - 1) / 2)
    return puts("No"), 0;
  return puts("Yes"), 0;
  return 0;
}

Fixed submission:
#include <cstdio>

typedef long long LL;
const int MN = 100005, MQ = 100005;

int N, Q;
LL M;
int pa[MN];
int fp(int x) { return pa[x] ? pa[x] = fp(pa[x]) : x; }
int qu[MQ], qv[MQ], K;
int E;

int main() {
  scanf("%d%lld%d", &N, &M, &Q);
  for (int i = 1; i <= Q; ++i) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    ++x, ++y;
    if (z == 0) {
      if ((x = fp(x)) != (y = fp(y)))
        pa[y] = x, ++E;
    } else
      qu[++K] = x, qv[K] = y;
  }
  if (K && M == N - 1)
    return puts("No"), 0;
  for (int i = 1; i <= K; ++i)
    if ((qu[i] = fp(qu[i])) == (qv[i] = fp(qv[i])))
      return puts("No"), 0;
  int C = N - E;
  if (C == 2)
    return puts("No"), 0;
  if (M > E + (LL)C * (C - 1) / 2)
    return puts("No"), 0;
  return puts("Yes"), 0;
  return 0;
}
Problem p02906 (C++)

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

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 1e5 + 7;

int p[N], sz[N];

int get(int a) { return (a == p[a] ? a : p[a] = get(p[a])); }

int cmp;

void join(int a, int b) {
  a = get(a);
  b = get(b);
  if (a != b) {
    --cmp;
    p[a] = b;
    sz[b] += sz[a];
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.setf(ios::fixed);
  cout.precision(20);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int n, m, q;
  cin >> n >> m >> q;
  for (int i = 0; i < n; ++i) {
    p[i] = i;
    sz[i] = 1;
  }
  cmp = n;
  vector<int> a(q), b(q), c(q);
  bool fl = false;
  for (int i = 0; i < q; ++i) {
    cin >> a[i] >> b[i] >> c[i];
    if (c[i] == 0) {
      join(a[i], b[i]);
    } else {
      fl = true;
    }
  }
  for (int i = 0; i < q; ++i) {
    if (c[i] == 1 && get(a[i]) == get(b[i])) {
      cout << "No\n";
      return 0;
    }
  }
  ll mn, mx;
  if (!fl) {
    mn = n - 1;
  } else {
    mn = n;
  }
  mx = 0;
  vector<int> cm;
  for (int i = 0; i < n; ++i)
    cm.push_back(get(i));
  sort(cm.begin(), cm.end());
  cm.resize(unique(cm.begin(), cm.end()) - cm.begin());
  for (auto x : cm) {
    mx += 2 * (sz[x] - 1);
    mx += cmp - 1;
  }
  mx /= 2;
  if (mn <= m && m <= mx) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 1e5 + 7;

int p[N], sz[N];

int get(int a) { return (a == p[a] ? a : p[a] = get(p[a])); }

int cmp;

void join(int a, int b) {
  a = get(a);
  b = get(b);
  if (a != b) {
    --cmp;
    p[a] = b;
    sz[b] += sz[a];
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.setf(ios::fixed);
  cout.precision(20);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int n, q;
  ll m;
  cin >> n >> m >> q;
  for (int i = 0; i < n; ++i) {
    p[i] = i;
    sz[i] = 1;
  }
  cmp = n;
  vector<int> a(q), b(q), c(q);
  bool fl = false;
  for (int i = 0; i < q; ++i) {
    cin >> a[i] >> b[i] >> c[i];
    if (c[i] == 0) {
      join(a[i], b[i]);
    } else {
      fl = true;
    }
  }
  for (int i = 0; i < q; ++i) {
    if (c[i] == 1 && get(a[i]) == get(b[i])) {
      cout << "No\n";
      return 0;
    }
  }
  ll mn, mx;
  if (!fl) {
    mn = n - 1;
  } else {
    mn = n;
  }
  mx = 0;
  vector<int> cm;
  for (int i = 0; i < n; ++i)
    cm.push_back(get(i));
  sort(cm.begin(), cm.end());
  cm.resize(unique(cm.begin(), cm.end()) - cm.begin());
  for (auto x : cm) {
    mx += 2 * (sz[x] - 1);
    mx += cmp - 1;
  }
  mx /= 2;
  if (mn <= m && m <= mx) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
}
Problem p02909 (C++)

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

int main() {
  string s;
  cin >> s;

  vector<string> w = {"Sunny", "Cloudy", "Rainy", "Sunny"};
  for (int i = 0; i < 4; i++) {
    if (w[i] == s) {
      cout << w[i + 1] << endl;
    }
  }
}

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

int main() {
  string s;
  cin >> s;

  vector<string> w = {"Sunny", "Cloudy", "Rainy", "Sunny"};
  for (int i = 0; i < 4; i++) {
    if (w[i] == s) {
      cout << w[i + 1] << endl;
      break;
    }
  }
}
Problem p02909 (C++)

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

int main() {
  string S;
  cin >> S;
  vector<string> wea;
  wea = {"Sunny", "Cloudy", "Rainy"};
  for (int i = 0; i < 3; i++) {
    if (S == wea[i])
      cout << wea[i + 1] << endl;
  }
}


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

int main() {
  string S;
  cin >> S;
  vector<string> wea;
  wea = {"Sunny", "Cloudy", "Rainy"};
  for (int i = 0; i < 3; i++) {
    if (S == wea[i])
      cout << wea[(i + 1) % 3] << endl;
  }
}
Problem p02909 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  vector<string> weather = {"Sunny", "Cloudy", "Rainy"};
  for (int i = 0; i < 3; i++) {
    if (s == weather.at(i)) {
      cout << weather.at(i + 1) << endl;
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  if (s == "Sunny") {
    cout << "Cloudy" << endl;
  }
  if (s == "Cloudy") {
    cout << "Rainy" << endl;
  }
  if (s == "Rainy") {
    cout << "Sunny" << endl;
  }
}
Problem p02909 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define fi first
#define se second
#define PI acos(-1.0)
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair<int, int>
#define lowbit(x) x & (-x)
using namespace std;
const int maxx = 1e6 + 5;
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;

int n, m, T;

char s[100];

int main() {
  int i, j, k;
  string ans;
  while (scanf(" %s", s)) {
    if (s[0] == 'S')
      ans = "Cloudy";
    else if (s[0] == 'C')
      ans = "Rainy";
    else
      ans = "Sunny";
    cout << ans << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define fi first
#define se second
#define PI acos(-1.0)
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair<int, int>
#define lowbit(x) x & (-x)
using namespace std;
const int maxx = 1e6 + 5;
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;

int n, m, T;

char s[100];

int main() {
  int i, j, k;
  string ans;
  scanf(" %s", s);
  if (s[0] == 'S')
    ans = "Cloudy";
  else if (s[0] == 'C')
    ans = "Rainy";
  else
    ans = "Sunny";
  cout << ans << endl;
  return 0;
}
Problem p02909 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  string weather[4];
  weather[0] = "Sunny";
  weather[1] = "Cloudy";
  weather[2] = "Rainy";
  weather[3] = weather[0];
  cin >> s;
  for (int i = 0; i < 4; i++) {
    if (s == weather[i]) {
      cout << weather[i + 1] << endl;
      continue;
    }
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  string weather[4];
  weather[0] = "Sunny";
  weather[1] = "Cloudy";
  weather[2] = "Rainy";
  weather[3] = weather[0];
  cin >> s;
  for (int i = 0; i < 3; i++) {
    if (s == weather[i]) {
      cout << weather[i + 1] << endl;
      continue;
    }
  }
  return 0;
}
Problem p02909 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
#define ll long long int
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

int main() {
  string *k;
  getline(cin, k[0]);
  k[0] = "Sunny";
  k[1] = "Cloudy";
  k[2] = "Rainy";
  string j;
  cin >> j;
  if (j == k[0]) {
    cout << k[1];
  } else if (j == k[1]) {
    cout << k[2];
  } else if (j == k[2]) {
    cout << k[0];
  }
}

Fixed submission:
#include <stdio.h>
#define ll long long int
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

int main() {
  string k[4] = {"Sunny", "Cloudy", "Rainy"};
  string j;
  cin >> j;
  if (j == k[0]) {
    cout << k[1];
  } else if (j == k[1]) {
    cout << k[2];
  } else if (j == k[2]) {
    cout << k[0];
  }
}
Problem p02909 (C++)

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

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
typedef pair<int, int> P;

const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9 + 7;
const int vx[4] = {0, 1, 0, -1};
const int vy[4] = {1, 0, -1, 0};

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

  int n;
  string s[3] = {"Sunny", "Cloudy", "Rainy"};
  string a;
  cin >> a;
  rep(i, 3) {
    if (a == s[i]) {
      cout << s[i + 1] << endl;
      return 0;
    }
  }

  cout << endl;
  return 0;
}


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

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
typedef pair<int, int> P;

const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9 + 7;
const int vx[4] = {0, 1, 0, -1};
const int vy[4] = {1, 0, -1, 0};

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

  int n;
  string s[3] = {"Sunny", "Cloudy", "Rainy"};
  string a;
  cin >> a;
  rep(i, 3) {
    if (a == s[i]) {
      if (i == 2) {
        cout << s[0] << endl;
        return 0;
      }
      cout << s[i + 1] << endl;
      return 0;
    }
  }

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

Buggy submission (status: Runtime Error):
#define __USE_MINGW_ANSI_STDIO
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long ll;
typedef long long ull;
typedef pair<ll, ll> ii;

#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define endl "\n"
#define fx(n) fixed << setprecision(n)
#define mk make_pair

void fast() {
  ios::sync_with_stdio(NULL);
  cout.tie(NULL);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("output.out", "w", stdout);
  freopen("input.in", "r", stdin);
#endif
  /*#ifdef ONLINE_JUDGE
  //freopen("output.txt", "w", stdout);
  freopen("path.in", "r", stdin);
  #endif*/
}
const double pi = 2 * acos(0.0);
const ll oo = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int nn = 1e3 + 15;
int dx[8] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[8] = {0, 0, -1, 1, -1, 1, 1, -1};

int main() {
  fast();
  string s;
  cin >> s;
  string arr[] = {"Sunny", "Cloudy", "Rainy"};
  int idx = find(arr, arr + 2, s) - arr;
  cout << arr[(idx + 1) % 3] << endl;
  return 0;
}

Fixed submission:
#define __USE_MINGW_ANSI_STDIO
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long ll;
typedef long long ull;
typedef pair<ll, ll> ii;

#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define endl "\n"
#define fx(n) fixed << setprecision(n)
#define mk make_pair

void fast() {
  ios::sync_with_stdio(NULL);
  cout.tie(NULL);
  cin.tie(NULL);
  /*#ifndef ONLINE_JUDGE
          freopen("output.out", "w", stdout);
          freopen("input.in", "r", stdin);
  #endif
          #ifdef ONLINE_JUDGE
          //freopen("output.txt", "w", stdout);
          freopen("path.in", "r", stdin);
          #endif*/
}
const double pi = 2 * acos(0.0);
const ll oo = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int nn = 1e3 + 15;
int dx[8] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[8] = {0, 0, -1, 1, -1, 1, 1, -1};

int main() {
  fast();
  string s;
  cin >> s;
  string arr[] = {"Sunny", "Cloudy", "Rainy"};
  int idx = find(arr, arr + 2, s) - arr;
  cout << arr[(idx + 1) % 3] << endl;
  return 0;
}
Problem p02909 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string w;
  cin >> w;
  if (w == "Sunny")
    cout << "Cloudy";
  else if (w == "Cloudy")
    cout << "Rainy";
  else if (w == "Rainy")
    cout << "Sunny";
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  // #ifndef ONLINE_JUDGE
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  // #endif
  // ios_base::sync_with_stdio(0);
  // cin.tie(0);
  string w;
  cin >> w;
  if (w == "Sunny")
    cout << "Cloudy";
  else if (w == "Cloudy")
    cout << "Rainy";
  else if (w == "Rainy")
    cout << "Sunny";
}
Problem p02909 (C++)

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

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

  string value[3] = {"Sunny", "Cloudy", "Rainy"};

  string str;
  cin >> str;

  for (int i = 0; i < str.size(); i++) {
    if (str == value[i]) {
      cout << value[(i + 1) % 3] << "\n";
    }
  }

  return 0;
}


Fixed submission:
/// AtCoder Beginner Contest 141
#include <bits/stdc++.h>
using namespace std;
#define ll long long

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

  string value[3] = {"Sunny", "Cloudy", "Rainy"};

  string str;
  cin >> str;

  for (int i = 0; i < 3; i++) {
    if (str == value[i]) {
      cout << value[(i + 1) % 3] << "\n";
    }
  }

  return 0;
}
Problem p02909 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;

int main() {
  string weather[3] = {"Sunny", "Cloudy", "Rainy"};
  string input;
  cin >> input;
  int i = 0;
  while (i < 3) {
    if (weather[i] == input) {
      if (i == 2)
        i = -1;
      cout << weather[i + 1] << endl;
    }
    i++;
  }
}


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

using namespace std;

int main() {
  string weather[3] = {"Sunny", "Cloudy", "Rainy"};
  string input;
  cin >> input;
  int i = 0;
  while (i < 3) {
    if (weather[i] == input) {
      if (i == 2)
        i = -1;
      cout << weather[i + 1] << endl;
      break;
    }
    i++;
  }
}