prithivMLmods/Coder-Stat huggingface dataset:
Problem p03291 (Python)

Buggy submission (status: Time Limit Exceeded):
mod = 1000000007

pow3 = [1] * 100001
for i in range(1, 100001):
    pow3[i] = pow3[i - 1] * 3

s = input()

all_a = 0
all_c = 0
all_q = 0
for c in s:
    if c == "A":
        all_a += 1
    elif c == "C":
        all_c += 1
    elif c == "?":
        all_q += 1
sum_a = 0
sum_c = 0
sum_q = 0
ans = 0

for c in s:
    n = 0
    if c == "B":
        n += sum_a * (all_c - sum_c) * pow3[all_q] % mod
        n += sum_a * (all_q - sum_q) * pow3[all_q - 1] % mod
        n += sum_q * (all_c - sum_c) * pow3[all_q - 1] % mod
        n += sum_q * (all_q - sum_q) * pow3[all_q - 2] % mod
    elif c == "?":
        n += sum_a * (all_c - sum_c) * pow3[all_q - 1] % mod
        n += sum_a * (all_q - sum_q - 1) * pow3[all_q - 2] % mod
        n += sum_q * (all_c - sum_c) * pow3[all_q - 2] % mod
        n += sum_q * (all_q - sum_q - 1) * pow3[all_q - 3] % mod
    ans += n % mod
    if c == "A":
        sum_a += 1
    elif c == "C":
        sum_c += 1
    elif c == "?":
        sum_q += 1
print(int(ans % mod))


Fixed submission:
mod = 1000000007

pow3 = [1] * 100001
for i in range(1, 100001):
    pow3[i] = pow3[i - 1] * 3 % mod

s = input()

all_a = 0
all_c = 0
all_q = 0
for c in s:
    if c == "A":
        all_a += 1
    elif c == "C":
        all_c += 1
    elif c == "?":
        all_q += 1
sum_a = 0
sum_c = 0
sum_q = 0
ans = 0

for c in s:
    n = 0
    if c == "B":
        n += sum_a * (all_c - sum_c) * pow3[all_q] % mod
        n += sum_a * (all_q - sum_q) * pow3[all_q - 1] % mod
        n += sum_q * (all_c - sum_c) * pow3[all_q - 1] % mod
        n += sum_q * (all_q - sum_q) * pow3[all_q - 2] % mod
    elif c == "?":
        n += sum_a * (all_c - sum_c) * pow3[all_q - 1] % mod
        n += sum_a * (all_q - sum_q - 1) * pow3[all_q - 2] % mod
        n += sum_q * (all_c - sum_c) * pow3[all_q - 2] % mod
        n += sum_q * (all_q - sum_q - 1) * pow3[all_q - 3] % mod
    ans += n % mod
    if c == "A":
        sum_a += 1
    elif c == "C":
        sum_c += 1
    elif c == "?":
        sum_q += 1
print(int(ans % mod))
Problem p03291 (Python)

Buggy submission (status: Time Limit Exceeded):
MOD = (10**9) + 7

S = input()
N = len(S)

nums = [1, 0, 0, 0]

for i in range(0, N):
    s = S[i]
    m = 3 if s == "?" else 1
    a = 1 if s == "A" or s == "?" else 0
    b = 1 if s == "B" or s == "?" else 0
    c = 1 if s == "C" or s == "?" else 0

    n0 = nums[0] * m
    n1 = nums[1] * m + nums[0] * a
    n2 = nums[2] * m + nums[1] * b
    n3 = nums[3] * m + nums[2] * c
    nums = [n0, n1, n2, n3]

print(nums[3] % MOD)


Fixed submission:
MOD = (10**9) + 7

S = input()
N = len(S)

nums = [1, 0, 0, 0]

for i in range(0, N):
    s = S[i]
    m = 3 if s == "?" else 1
    a = 1 if s == "A" or s == "?" else 0
    b = 1 if s == "B" or s == "?" else 0
    c = 1 if s == "C" or s == "?" else 0

    n0 = (nums[0] * m) % MOD
    n1 = (nums[1] * m + nums[0] * a) % MOD
    n2 = (nums[2] * m + nums[1] * b) % MOD
    n3 = (nums[3] * m + nums[2] * c) % MOD
    nums = [n0, n1, n2, n3]

print(nums[3] % MOD)
Problem p03291 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <string>
using namespace std;
const int P = 1000000007;

long long pow3(int n) {
  long long p = 1;
  for (int i = 0; i < n; i++)
    (p *= 3) %= P;
  return p;
}

int main(void) {
  string s;
  cin >> s;
  int len = s.size();
  long long dp[100002][3] = {{0}}; // 欲しいのは dp[0][0]
  long long cntHatena[100001] = {0}, po[100001] = {0};

  for (int i = len; i >= 0; i--) {
    cntHatena[i] = ((s[i] == '?') ? 1 : 0) + cntHatena[i + 1];
    po[i] = pow3(cntHatena[i]);
  }
  char al[3] = {'A', 'B', 'C'};

  for (int i = len - 1; i >= 0; i--) {
    if (s[i] == 'C') {
      dp[i][2] = dp[i + 1][2] + po[i + 1];
    } else if (s[i] == '?') {
      dp[i][2] = 3 * dp[i + 1][2] + po[i + 1];
    } else {
      dp[i][2] = dp[i + 1][2];
    }
    dp[i][2] %= P;
  }

  for (int j = 1; j >= 0; j--) {
    for (int i = len - 1; i >= 0; i--) {
      if (s[i] == al[j]) {
        dp[i][j] = (dp[i + 1][j + 1] + dp[i + 1][j]) % P;
      } else if (s[i] == '?') {
        dp[i][j] = (dp[i + 1][j + 1] + 3 * dp[i + 1][j]) % P;
      } else {
        dp[i][j] = dp[i + 1][j];
      }
    }
  }
  printf("%lld\n", dp[0][0]);
}


Fixed submission:
#include <iostream>
#include <string>
using namespace std;
const int P = 1000000007;

long long pow3(int n) {
  long long p = 1;
  for (int i = 0; i < n; i++)
    (p *= 3) %= P;
  return p;
}

int main(void) {
  string s;
  cin >> s;
  int len = s.size();
  long long dp[100002][3] = {{0}}; // 欲しいのは dp[0][0]
  long long cntHatena[100001] = {0}, po[100001] = {0};

  po[len] = 1;
  for (int i = len - 1; i >= 0; i--) {
    po[i] = (((s[i] == '?') ? 3 : 1) * po[i + 1]) % P;
  }
  char al[3] = {'A', 'B', 'C'};

  for (int i = len - 1; i >= 0; i--) {
    if (s[i] == 'C') {
      dp[i][2] = dp[i + 1][2] + po[i + 1];
    } else if (s[i] == '?') {
      dp[i][2] = 3 * dp[i + 1][2] + po[i + 1];
    } else {
      dp[i][2] = dp[i + 1][2];
    }
    dp[i][2] %= P;
  }

  for (int j = 1; j >= 0; j--) {
    for (int i = len - 1; i >= 0; i--) {
      if (s[i] == al[j]) {
        dp[i][j] = (dp[i + 1][j + 1] + dp[i + 1][j]) % P;
      } else if (s[i] == '?') {
        dp[i][j] = (dp[i + 1][j + 1] + 3 * dp[i + 1][j]) % P;
      } else {
        dp[i][j] = dp[i + 1][j];
      }
    }
  }
  printf("%lld\n", dp[0][0]);
}
Problem p03291 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
ll kai(ll n, ll k) {
  ll ret = 1;
  for (ll i = 0; i < k; i++) {
    ret *= n;
    ret %= mod;
  }
  return ret;
}
int main() {
  string s;
  cin >> s;
  ll a[s.size() + 1], c[s.size() + 1], h[s.size() + 1];
  a[0] = 0;
  c[0] = 0;
  h[0] = 0;
  for (ll i = 0; i < s.size(); i++) {
    a[i + 1] = a[i];
    c[i + 1] = c[i];
    h[i + 1] = h[i];
    if (s[i] == 'A')
      a[i + 1]++;
    if (s[i] == 'C')
      c[i + 1]++;
    if (s[i] == '?')
      h[i + 1]++;
  }
  // cout<<a[1]<<c[4]<<h[3];return 0;
  ll ans = 0;
  for (ll i = 0; i < s.size(); i++) {
    if (s[i] == 'B' || s[i] == '?') {
      ll p = (a[i] * kai(3, h[i]) + h[i] * kai(3, h[i] - 1)) % mod;
      ll q = ((c[s.size()] - c[i + 1]) * kai(3, h[s.size()] - h[i + 1]) +
              (h[s.size()] - h[i + 1]) * kai(3, h[s.size()] - h[i + 1] - 1)) %
             mod;
      ans += p * q % mod;
      ans %= mod;
      // cout<<p<<" "<<q<<endl;
    }
  }
  cout << ans % mod << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
ll kai(ll n, ll k) {
  ll ret = 1;
  ll jou = n;
  for (;;) {
    if (k % 2 == 1)
      ret = ret * jou % mod;
    k /= 2;
    if (k == 0)
      break;
    jou = jou * jou % mod;
  }
  return ret;
}
int main() {
  string s;
  cin >> s;
  ll a[s.size() + 1], c[s.size() + 1], h[s.size() + 1];
  a[0] = 0;
  c[0] = 0;
  h[0] = 0;
  for (ll i = 0; i < s.size(); i++) {
    a[i + 1] = a[i];
    c[i + 1] = c[i];
    h[i + 1] = h[i];
    if (s[i] == 'A')
      a[i + 1]++;
    if (s[i] == 'C')
      c[i + 1]++;
    if (s[i] == '?')
      h[i + 1]++;
  }
  // cout<<a[1]<<c[4]<<h[3];return 0;
  ll ans = 0;
  for (ll i = 0; i < s.size(); i++) {
    if (s[i] == 'B' || s[i] == '?') {
      ll p = (a[i] * kai(3, h[i]) + h[i] * kai(3, h[i] - 1)) % mod;
      ll q = ((c[s.size()] - c[i + 1]) * kai(3, h[s.size()] - h[i + 1]) +
              (h[s.size()] - h[i + 1]) * kai(3, h[s.size()] - h[i + 1] - 1)) %
             mod;
      ans += p * q % mod;
      ans %= mod;
      // cout<<p<<" "<<q<<endl;
    }
  }
  cout << ans % mod << endl;
}
Problem p03291 (C++)

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

long long a[4] = {1};
char s[100005];
int main() {
  scanf("%s", s);
  for (int i = 0; s[i] != '\n'; i++)
    for (int j = 3; j >= 0; j--)
      a[j] = (a[j] * (s[i] == '?' ? 3 : 1) +
              (j && (s[i] == '?' || s[i] - 'A' == j - 1) ? a[j - 1] : 0)) %
             md;
  printf("%lld\n", a[3]);
}

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

long long a[4] = {1};
char s[100005];
int main() {
  scanf("%s", s);
  for (int i = 0; s[i] != '\0'; i++)
    for (int j = 3; j >= 0; j--)
      a[j] = (a[j] * (s[i] == '?' ? 3 : 1) +
              (j && (s[i] == '?' || s[i] - 'A' == j - 1) ? a[j - 1] : 0)) %
             md;
  printf("%lld\n", a[3]);
}
Problem p03291 (C++)

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

int main() {
  string S;
  cin >> S;
  int n = S.size();
  vector<LL> dpa(n, 0), dpb(n, 0), dpc(n, 0), dpsum(n, 0);
  dpsum[0] = 1;
  for (int i = 0; i < n; i++) {
    dpa[i + 1] = dpa[i];
    dpb[i + 1] = dpb[i];
    dpc[i + 1] = dpc[i];
    dpsum[i + 1] = dpsum[i];
    if (S[i] == 'A') {
      dpa[i + 1] += dpsum[i];
      dpa[i + 1] %= mod;
    } else if (S[i] == 'B') {
      dpb[i + 1] += dpa[i];
      dpb[i + 1] %= mod;
    } else if (S[i] == 'C') {
      dpc[i + 1] += dpb[i];
      dpc[i + 1] %= mod;
    } else {
      dpa[i + 1] += dpsum[i] + dpa[i] * 2;
      dpa[i + 1] %= mod;
      dpb[i + 1] += dpa[i] + dpb[i] * 2;
      dpb[i + 1] %= mod;
      dpc[i + 1] += dpb[i] + dpc[i] * 2;
      dpc[i + 1] %= mod;
      dpsum[i + 1] += dpsum[i] * 2;
      dpsum[i + 1] %= mod;
    }
  }
  cout << dpc[n] << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
LL mod = 1e9 + 7;

int main() {
  string S;
  cin >> S;
  int n = S.size();
  vector<LL> dpa(n + 1, 0), dpb(n + 1, 0), dpc(n + 1, 0), dpsum(n + 1, 0);
  dpsum[0] = 1;
  for (int i = 0; i < n; i++) {
    dpa[i + 1] = dpa[i];
    dpb[i + 1] = dpb[i];
    dpc[i + 1] = dpc[i];
    dpsum[i + 1] = dpsum[i];
    if (S[i] == 'A') {
      dpa[i + 1] += dpsum[i];
      dpa[i + 1] %= mod;
    } else if (S[i] == 'B') {
      dpb[i + 1] += dpa[i];
      dpb[i + 1] %= mod;
    } else if (S[i] == 'C') {
      dpc[i + 1] += dpb[i];
      dpc[i + 1] %= mod;
    } else {
      dpa[i + 1] += dpsum[i] + dpa[i] * 2;
      dpa[i + 1] %= mod;
      dpb[i + 1] += dpa[i] + dpb[i] * 2;
      dpb[i + 1] %= mod;
      dpc[i + 1] += dpb[i] + dpc[i] * 2;
      dpc[i + 1] %= mod;
      dpsum[i + 1] += dpsum[i] * 2;
      dpsum[i + 1] %= mod;
    }
  }
  cout << dpc[n] << endl;
}
Problem p03291 (C++)

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

int main() {

  string s;
  cin >> s;

  long long dp[1010][3];
  memset(dp, 0, sizeof dp);
  long long now_num = 1LL;

  for (int i = 1; i <= (int)s.size(); i++) {
    char alpha = s[i - 1];

    //(dp[i][0] += dp[i - 1][0]) % MOD;
    //(dp[i][1] += dp[i - 1][1]) % MOD;
    //(dp[i][2] += dp[i - 1][2]) % MOD;

    if (alpha == 'A' || alpha == '?') {
      dp[i][0] += ((dp[i - 1][0] + now_num) % MOD);
      dp[i][0] %= MOD;
      dp[i][1] += (dp[i - 1][1] % MOD);
      dp[i][1] %= MOD;
      dp[i][2] += (dp[i - 1][2] % MOD);
      dp[i][2] %= MOD;
    }

    if (alpha == 'B' || alpha == '?') {
      dp[i][0] += (dp[i - 1][0] % MOD);
      dp[i][0] %= MOD;
      dp[i][1] += ((dp[i - 1][0] + dp[i - 1][1]) % MOD);
      dp[i][1] %= MOD;
      dp[i][2] += (dp[i - 1][2] % MOD);
      dp[i][2] %= MOD;
    }

    if (alpha == 'C' || alpha == '?') {
      dp[i][0] += (dp[i - 1][0] % MOD);
      dp[i][0] %= MOD;
      dp[i][1] += (dp[i - 1][1] % MOD);
      dp[i][1] %= MOD;
      dp[i][2] += ((dp[i - 1][1] + dp[i - 1][2]) % MOD);
      dp[i][2] %= MOD;
    }

    if (alpha == '?')
      now_num = ((now_num % MOD) * 3) % MOD;
  }

  /*for(int i = 0; i <= (int)s.size(); i++){
      for(int j = 0; j < 3; j++){
          cout << dp[i][j] << " ";
      }
      cout << endl;
  }*/

  cout << dp[(int)s.size()][2] % MOD << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007LL;

int main() {

  string s;
  cin >> s;

  long long dp[100010][3];
  memset(dp, 0, sizeof dp);
  long long now_num = 1LL;

  for (int i = 1; i <= (int)s.size(); i++) {
    char alpha = s[i - 1];

    //(dp[i][0] += dp[i - 1][0]) % MOD;
    //(dp[i][1] += dp[i - 1][1]) % MOD;
    //(dp[i][2] += dp[i - 1][2]) % MOD;

    if (alpha == 'A' || alpha == '?') {
      dp[i][0] += ((dp[i - 1][0] + now_num) % MOD);
      dp[i][0] %= MOD;
      dp[i][1] += (dp[i - 1][1] % MOD);
      dp[i][1] %= MOD;
      dp[i][2] += (dp[i - 1][2] % MOD);
      dp[i][2] %= MOD;
    }

    if (alpha == 'B' || alpha == '?') {
      dp[i][0] += (dp[i - 1][0] % MOD);
      dp[i][0] %= MOD;
      dp[i][1] += ((dp[i - 1][0] + dp[i - 1][1]) % MOD);
      dp[i][1] %= MOD;
      dp[i][2] += (dp[i - 1][2] % MOD);
      dp[i][2] %= MOD;
    }

    if (alpha == 'C' || alpha == '?') {
      dp[i][0] += (dp[i - 1][0] % MOD);
      dp[i][0] %= MOD;
      dp[i][1] += (dp[i - 1][1] % MOD);
      dp[i][1] %= MOD;
      dp[i][2] += ((dp[i - 1][1] + dp[i - 1][2]) % MOD);
      dp[i][2] %= MOD;
    }

    if (alpha == '?')
      now_num = ((now_num % MOD) * 3) % MOD;
  }

  /*for(int i = 0; i <= (int)s.size(); i++){
      for(int j = 0; j < 3; j++){
          cout << dp[i][j] << " ";
      }
      cout << endl;
  }*/

  cout << dp[(int)s.size()][2] % MOD << endl;

  return 0;
}
Problem p03291 (C++)

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

constexpr long mod = 1000000007;

long powpow(long x, long y) {
  long r = 1;
  while (y) {
    if (y & 1)
      r *= x, r %= mod;
    x *= x, x %= mod;
    y >>= 1;
  }
  return r;
}

int main(void) {
  string s;
  cin >> s;
  int l = s.size();

  vector<vector<long>> dp(3, vector<long>(4));

  long q = 0;
  for (size_t i = 0; i < l; i++)
    q += s[i] == '?';

  for (size_t i = 0; i < l; i++) {
    for (int j : {2, 1, 0})
      for (int k : {2, 1, 0}) {
        dp[j][k] += (j > 0 ? dp[j - 1][k] : k == 0) * (s[i] == 'A' + j),
            dp[j][k] %= mod;
        dp[j][k + 1] += (j > 0 ? dp[j - 1][k] : k == 0) * (s[i] == '?'),
            dp[j][k + 1] %= mod;
      }
  }

  long r = 0;
  for (int i : {0, 1, 2, 3})
    r += dp[2][i] * powpow(3, q - i), r %= mod;

  cout << r << endl;
}


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

constexpr long mod = 1000000007;

long powpow(long x, long y) {
  long r = 1;
  while (y) {
    if (y & 1)
      r *= x, r %= mod;
    x *= x, x %= mod;
    y >>= 1;
  }
  return r;
}

int main(void) {
  string s;
  cin >> s;
  int l = s.size();

  vector<vector<long>> dp(3, vector<long>(4));

  long q = 0;
  for (size_t i = 0; i < l; i++)
    q += s[i] == '?';

  for (size_t i = 0; i < l; i++) {
    for (int j : {2, 1, 0})
      for (int k : {2, 1, 0}) {
        dp[j][k] += (j > 0 ? dp[j - 1][k] : k == 0) * (s[i] == 'A' + j),
            dp[j][k] %= mod;
        dp[j][k + 1] += (j > 0 ? dp[j - 1][k] : k == 0) * (s[i] == '?'),
            dp[j][k + 1] %= mod;
      }
  }

  long r = 0;
  for (int i : {0, 1, 2, 3})
    if (q - i >= 0)
      r += dp[2][i] * powpow(3, q - i), r %= mod;

  cout << r << endl;
}
Problem p03291 (C++)

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

string S;
ll dp[MAX + 1][4] = {0};

void abc104d() {
  int n = S.size();
  dp[0][0] = 1;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j < 4; j++) {
      if (S[i] == '?') {
        dp[i + 1][j] += 3 * dp[i][j];
      } else {
        dp[i + 1][j] += dp[i][j];
      }
      dp[i + 1][j] %= MOD;
    }

    if (S[i] == 'A' || S[i] == '?') {
      dp[i + 1][1] += dp[i][0];
      dp[i + 1][1] %= MOD;
    }
    if (S[i] == 'B' || S[i] == '?') {
      dp[i + 1][2] += dp[i][1];
      dp[i + 1][2] %= MOD;
    }
    if (S[i] == 'C' || S[i] == '?') {
      dp[i + 1][3] += dp[i][2];
      dp[i + 1][3] %= MOD;
    }
  }

  cout << dp[n][3] << "\n";
  return;
}

int main() {
  cin >> S;
  abc104d();
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAX = 500000;
const int MOD = 1000000007;

string S;
ll dp[MAX + 1][4] = {0};

void abc104d() {
  int n = S.size();
  dp[0][0] = 1;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j < 4; j++) {
      if (S[i] == '?') {
        dp[i + 1][j] += 3 * dp[i][j];
      } else {
        dp[i + 1][j] += dp[i][j];
      }
      dp[i + 1][j] %= MOD;
    }

    if (S[i] == 'A' || S[i] == '?') {
      dp[i + 1][1] += dp[i][0];
      dp[i + 1][1] %= MOD;
    }
    if (S[i] == 'B' || S[i] == '?') {
      dp[i + 1][2] += dp[i][1];
      dp[i + 1][2] %= MOD;
    }
    if (S[i] == 'C' || S[i] == '?') {
      dp[i + 1][3] += dp[i][2];
      dp[i + 1][3] %= MOD;
    }
  }

  cout << dp[n][3] << "\n";
  return;
}

int main() {
  cin >> S;
  abc104d();
  return 0;
}
Problem p03292 (Python)

Buggy submission (status: Runtime Error):
*a = map(int, input().split())
print(max(a) - min(a))


Fixed submission:
(*a,) = map(int, input().split())
print(max(a) - min(a))
Problem p03292 (Python)

Buggy submission (status: Runtime Error):
A = [map(int, input().split())]

print(max(A) - min(A))


Fixed submission:
A = [int(x) for x in input().split()]

print(max(A) - min(A))
Problem p03292 (Python)

Buggy submission (status: Runtime Error):
A = map(int, input())
A = sorted(A)
ans = 0
for i in range(1, 3):
    ans += abs(A[i - 1] - A[i])
print(ans)


Fixed submission:
A = map(int, input().split())
A = sorted(A)
ans = 0
for i in range(1, 3):
    ans += abs(A[i - 1] - A[i])
print(ans)
Problem p03292 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
#define INF 2000000000
#define DESPACITO2 1000000000000000
#define DESPACITO 1000000000000000000
#define MOD 1000000007
#define ll long long
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define ii pair<int, int>
#define vii vector<ii>
#define si set<int>
#define msi map<string, int>
#define REP(i, a, b) for (int i = int(a); i <= int(b); i++)
#define TRvi(c, it) for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) for (msi::iterator it = (c).begin(); it != (c).end(); it++)

using namespace std;

int main() {
  IOS;
#ifndef ONLINE_JUDGE
  // for getting input from input.txt
  freopen("input.txt", "r", stdin);
  // for writing output to output.txt
  freopen("output.txt", "w", stdout);
#endif
  int arr[3];
  cin >> arr[0] >> arr[1] >> arr[2];
  sort(arr, arr + 3);
  bool a = true;
  int minim = 10000;
  while (a) {
    int val = abs(arr[1] - arr[0]) + abs(arr[2] - arr[1]);
    minim = min(minim, val);
    a = next_permutation(arr, arr + 3);
  }
  cout << minim;
}

Fixed submission:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
#define INF 2000000000
#define DESPACITO2 1000000000000000
#define DESPACITO 1000000000000000000
#define MOD 1000000007
#define ll long long
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define ii pair<int, int>
#define vii vector<ii>
#define si set<int>
#define msi map<string, int>
#define REP(i, a, b) for (int i = int(a); i <= int(b); i++)
#define TRvi(c, it) for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) for (msi::iterator it = (c).begin(); it != (c).end(); it++)

using namespace std;

int main() {
  IOS;
  /*#ifndef ONLINE_JUDGE
      // for getting input from input.txt
      freopen("input.txt", "r", stdin);
      // for writing output to output.txt
      freopen("output.txt", "w", stdout);
  #endif*/
  int arr[3];
  cin >> arr[0] >> arr[1] >> arr[2];
  sort(arr, arr + 3);
  bool a = true;
  int minim = 10000;
  while (a) {
    int val = abs(arr[1] - arr[0]) + abs(arr[2] - arr[1]);
    minim = min(minim, val);
    a = next_permutation(arr, arr + 3);
  }
  cout << minim;
}
Problem p03292 (Python)

Buggy submission (status: Runtime Error):
s1 = input()
print("Yes" if input() in tuple(s1[i:] + s1[:i] for i in range(len(s1))) else "No")


Fixed submission:
import numpy as np

A = np.array(sorted(map(int, input().split())))
print((A[1:] - A[:-1]).sum())
Problem p03292 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
// cout <<  << endl;
typedef long long int ll;
typedef long double ld;

int main() {
  vector<ll> a;
  cin >> a[0] >> a[1] >> a[2];
  sort(a.begin(), a.end());
  cout << a[2] - a[0] << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
// cout <<  << endl;
typedef long long int ll;
typedef long double ld;

int main() {
  vector<ll> a(3);
  cin >> a[0] >> a[1] >> a[2];
  sort(a.begin(), a.end());
  cout << a[2] - a[0] << endl;
  return 0;
}
Problem p03292 (C++)

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

// 与2数の絶対値の差を返す
int absolute_diff(int a, int b) {
  if (a - b >= 0)
    return a - b;
  else
    return b - a;
}

// 与パターンのコストの和を返す
int p_sum(int a, int b, int c) {
  return absolute_diff(a, b) + absolute_diff(b, c);
}

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  int m;
  m = min(p_sum(A, B, C), p_sum(A, C, B));
  m = min(m, p_sum(B, A, C));
  m = min(m, p_sum(B, C, A));
  m = min(m, p_sum(C, A, B));
  m = min(m, p_sum(C, B, A));
  return m;
}


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

// 与2数の絶対値の差を返す
int absolute_diff(int a, int b) {
  if (a - b >= 0)
    return a - b;
  else
    return b - a;
}

// 与パターンのコストの和を返す
int p_sum(int a, int b, int c) {
  return absolute_diff(a, b) + absolute_diff(b, c);
}

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  int m;
  m = min(p_sum(A, B, C), p_sum(A, C, B));
  m = min(m, p_sum(B, A, C));
  m = min(m, p_sum(B, C, A));
  m = min(m, p_sum(C, A, B));
  m = min(m, p_sum(C, B, A));
  cout << m << endl;
}
Problem p03292 (C++)

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

int main() {
  vector<int> a;
  rep(i, 3) cin >> a.at(i);
  sort(a.begin(), a.end());
  cout << a.at(2) - a.at(0) << endl;
}


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

int main() {
  int a1, a2, a3;
  cin >> a1 >> a2 >> a3;
  cout << max(a1, max(a2, a3)) - min(a1, min(a2, a3)) << endl;
}
Problem p03292 (C++)

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

int main() {
  vector<int> a;
  for (int i = 0; i < 3; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  cout << (a[1] - a[0]) + (a[2] - a[1]) << endl;
  return 0;
}


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

int main() {
  vector<int> a;
  for (int i = 0; i < 3; i++) {
    int x;
    cin >> x;
    a.push_back(x);
  }
  sort(a.begin(), a.end());
  cout << (a[1] - a[0]) + (a[2] - a[1]) << endl;
  return 0;
}
Problem p03292 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <math.h>
#include <stdio.h>
int main() {
  int a, b, c;
  while (scanf("%d %d %d", &a, &b, &c)) {
    printf("%d\n", (int)fabs(a - b));
  }
}

Fixed submission:
#include <math.h>
#include <stdio.h>
int main() {
  int a[3];
  int i, j, t, sum = 0;
  while (scanf("%d %d %d", &a[0], &a[1], &a[2]) == 3) {
    sum = 0;
    for (i = 0; i < 3; i++) {
      for (j = 0; j < 2 - i; j++) {
        if (a[j] > a[j + 1]) {
          t = a[j];
          a[j] = a[j + 1];
          a[j + 1] = t;
        }
      }
    }
    for (i = 0; i < 2; i++) {
      sum = sum + fabs(a[i + 1] - a[i]);
    }
    printf("%d\n", sum);
  }
}
Problem p03292 (C++)

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

int main() {
  vector<int> a;
  cin >> a.at(0) >> a.at(1) >> a.at(2);

  sort(a.begin(), a.end());

  cout << a.at(2) - a.at(0);
}

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

int main() {
  vector<int> a(3);
  cin >> a.at(0) >> a.at(1) >> a.at(2);

  sort(a.begin(), a.end());

  cout << a.at(2) - a.at(0);
}
Problem p03292 (C++)

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

#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define loop(i, a, b) for (int i = a; i < b; i++)
#define inf (long long int)1e18
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define mod 1000000007

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

int palindrome(string s) {
  int l = 0;
  int h = s.length() - 1;
  while (h > l) {
    if (s[l++] != s[h--]) {
      return 0;
    }
  }
  return 1;
}

long long modexp(long long a, long long b, long long m) {
  if (b == 0)
    return 1;
  long long temp = modexp(a, b / 2, m);
  temp = (temp * temp) % m;
  if (b & 1)
    return (temp * (a % m)) % m; // if b is odd a^b = a^(b/2)*a^(b/2)*a
  return temp;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  int a[3];
  loop(i, 0, 3) { cin >> a[i]; }
  sort(a, a + 3);
  cout << abs(a[1] - a[0]) + abs(a[2] - a[1]);
}


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

#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define loop(i, a, b) for (int i = a; i < b; i++)
#define inf (long long int)1e18
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define mod 1000000007

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

int palindrome(string s) {
  int l = 0;
  int h = s.length() - 1;
  while (h > l) {
    if (s[l++] != s[h--]) {
      return 0;
    }
  }
  return 1;
}

long long modexp(long long a, long long b, long long m) {
  if (b == 0)
    return 1;
  long long temp = modexp(a, b / 2, m);
  temp = (temp * temp) % m;
  if (b & 1)
    return (temp * (a % m)) % m; // if b is odd a^b = a^(b/2)*a^(b/2)*a
  return temp;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  /*#ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
  #endif*/

  int a[3];
  loop(i, 0, 3) { cin >> a[i]; }
  sort(a, a + 3);
  cout << abs(a[1] - a[0]) + abs(a[2] - a[1]);
}
Problem p03292 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>

int main() {
  int A[3] = {}, cost, total, tmp;
  scanf("%d %d %d ", A[0], A[1], A[2]);
  for (int i = 0; i < 3; i++) {
    for (int j = i + 1; j < 3; j++) {
      if (A[i] > A[j]) {
        tmp = A[i];
        A[i] = A[j];
        A[j] = tmp;
      }
    }
  }
  cost = (A[1] - A[0]) + (A[2] - A[1]);
  printf("%d\n", cost);
  return 0;
}

Fixed submission:
#include <stdio.h>

int main() {
  int A[3] = {}, cost, total, tmp;
  scanf("%d %d %d ", &A[0], &A[1], &A[2]);
  for (int i = 0; i < 3; i++) {
    for (int j = i + 1; j < 3; j++) {
      if (A[i] > A[j]) {
        tmp = A[i];
        A[i] = A[j];
        A[j] = tmp;
      }
    }
  }
  cost = (A[1] - A[0]) + (A[2] - A[1]);
  printf("%d\n", cost);
  return 0;
}
Problem p03292 (Python)

Buggy submission (status: Runtime Error):
a = map(int, input().split())
print(max(a) - min(a))


Fixed submission:
a = list(map(int, input().split()))
print(max(a) - min(a))
Problem p03293 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n - 1);
  return ans * n;
}
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
bool is_prime(ll n) {
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0)
    return 1;
  ll res = mod_pow(x * x % mod, n / 2, mod);
  if (n & 1)
    res = res * x % mod;
  return res;
}

int main() {
  string s, t;
  cin >> s >> t;
  bool main_flag = 0;
  rep(i, s.size()) {
    if (s.at(i) == t.at(0)) {
      bool semi_flag = 1;
      rep(j, s.size()) {
        if (s.at(i + j) != t.at(j)) {
          semi_flag = 0;
          break;
        }
      }
      if (semi_flag) {
        main_flag = 1;
        break;
      }
    }
  }
  if (main_flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n - 1);
  return ans * n;
}
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
bool is_prime(ll n) {
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0)
    return 1;
  ll res = mod_pow(x * x % mod, n / 2, mod);
  if (n & 1)
    res = res * x % mod;
  return res;
}

int main() {
  string s, t;
  cin >> s >> t;
  bool main_flag = 0;
  rep(i, s.size()) {
    if (s.at(i) == t.at(0)) {
      bool semi_flag = 1;
      rep(j, s.size()) {
        if (s.at((i + j) % s.size()) != t.at(j)) {
          semi_flag = 0;
          break;
        }
      }
      if (semi_flag) {
        main_flag = 1;
        break;
      }
    }
  }
  if (main_flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p03293 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  string s, t;
  cin >> s >> t;
  int i = 0;
  while (i <= s.size()) {
    string s = s[s.size() - 1] + s.substr(1, s.size() - 1);
    if (s == t) {
      cout << "Yes" << endl;
      return 0;
    }
    i++;
  }
  cout << "No" << endl;
}

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

int main() {
  string s, t;
  cin >> s >> t;
  int i = 0;
  while (i <= s.size()) {
    s = s[s.size() - 1] + s.substr(0, s.size() - 1);
    if (s == t) {
      cout << "Yes" << endl;
      return 0;
    }
    i++;
  }
  cout << "No" << endl;
}
Problem p03293 (C++)

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

using namespace std;

int main(int argc, const char *argv[]) {

  string S, T;

  cin >> S >> T;

  for (int i = 0; i < S.size(); i++) {
    S += S.at(S.size());
    S.erase(0, 1);

    if (S == T) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
  return 0;
}


Fixed submission:
#include <iostream>

using namespace std;

int main(int argc, const char *argv[]) {

  string S, T;

  cin >> S >> T;

  for (int i = 0; i < S.size(); i++) {
    S += S.at(0);
    S.erase(0, 1);

    if (S == T) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
  return 0;
}
Problem p03293 (C++)

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

int main() {
  string S, T;
  cin >> S, T;
  int N = S.size();
  bool flag1 = false;
  for (int k = 0; k < N; k++) {
    bool flag2 = true;
    for (int i = 0; i < N; i++) {
      if (S.at(i) != T.at((i + k) % N))
        flag2 = false;
    }
    if (flag2)
      flag1 = true;
  }
  if (flag1)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

int main() {
  string S, T;
  cin >> S >> T;
  int N = S.size();
  bool flag1 = false;
  for (int k = 0; k < N; k++) {
    bool flag2 = true;
    for (int i = 0; i < N; i++) {
      if (S.at(i) != T.at((i + k) % N))
        flag2 = false;
    }
    if (flag2)
      flag1 = true;
  }
  if (flag1)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p03293 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
int main() {
  char s[100], s1[100], t[100];
  cin >> s1 >> t;
  sprintf(s, "%s%s", s1, s1);
  int hantei = 0;
  for (int i = 0; i < strlen(s); i++) {
    for (int j = 0; j < strlen(t); j++) {
      if (s[i + j] != t[j]) {
        break;
      }
      if (j == strlen(t) - 1) {
        hantei = 1;
      }
    }
    if (hantei == 1) {
      break;
    }
  }
  if (hantei == 1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Fixed submission:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
int main() {
  char s[300], s1[150], t[150];
  cin >> s1 >> t;
  sprintf(s, "%s%s", s1, s1);
  int hantei = 0;
  for (int i = 0; i < strlen(s); i++) {
    for (int j = 0; j < strlen(t); j++) {
      if (s[i + j] != t[j]) {
        break;
      }
      if (j == strlen(t) - 1) {
        hantei = 1;
      }
    }
    if (hantei == 1) {
      break;
    }
  }
  if (hantei == 1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p03293 (C++)

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

using namespace std;

int main() {
  string S, T;
  string ans = "No";
  cin >> S >> T;

  while (1) {
    if (S == T) {
      ans = "Yes";
      break;
    } else {
      char tmp = S.back();
      for (int i = S.size() - 2; i >= 0; i--) {
        S.at(i + 1) = S.at(i);
      }
      S.at(0) = tmp;
    }
  }
  cout << ans << endl;
}

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

using namespace std;

int main() {
  string S, T;
  string ans = "No";
  cin >> S >> T;

  for (int j = 0; j < S.size(); j++) {
    if (S == T) {
      ans = "Yes";
      break;
    } else {
      char tmp = S.back();
      for (int i = S.size() - 2; i >= 0; i--) {
        S.at(i + 1) = S.at(i);
      }
      S.at(0) = tmp;
    }
  }
  cout << ans << endl;
}
Problem p03293 (Python)

Buggy submission (status: Runtime Error):
S = input()
T = input()
ansCnt = 0
for i in range(len(S)):
    for j in range(1, len(S) + 1):
        if S[-j] == T[-j]:
            continue
        elif j != len(S):
            for z in range(len(S) - j):
                if S[-j] == T[z]:
                    S = S[0:z] + S[-j] + S[z:-j] + S[-j + 1 :]
                    continue

if S == T:
    print("Yes")
else:
    print("No")


Fixed submission:
S = input()
T = input()
ansCnt = 0
for i in range(len(S)):
    if S == T:
        break
    S = S[-1] + S[0:-1]
if S == T:
    print("Yes")
else:
    print("No")
Problem p03293 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
int l;
char s[100], c[100], t[100], a;
int main() {
  cin >> s >> t;
  if (strcmp(s, t) == 0) {
    cout << "Yes";
    return 0;
  }
  l = strlen(s);
  strcpy(c, s);
  a = c[0];
  for (int i = 1; i < l; i++)
    c[i - 1] = c[i];
  c[l - 1] = a;
  while (strcmp(s, c) != 0) {
    if (strcmp(c, t) == 0) {
      cout << "Yes";
      return 0;
    }
    a = c[0];
    for (int i = 1; i < l; i++)
      c[i - 1] = c[i];
    c[l - 1] = a;
  }
  cout << "No";
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
int l;
char s[102], c[102], t[102], a;
int main() {
  cin >> s >> t;
  if (strcmp(s, t) == 0) {
    cout << "Yes";
    return 0;
  }
  l = strlen(s);
  strcpy(c, s);
  a = c[0];
  for (int i = 1; i < l; i++)
    c[i - 1] = c[i];
  c[l - 1] = a;
  while (strcmp(s, c) != 0) {
    if (strcmp(c, t) == 0) {
      cout << "Yes";
      return 0;
    }
    a = c[0];
    for (int i = 1; i < l; i++)
      c[i - 1] = c[i];
    c[l - 1] = a;
  }
  cout << "No";
  return 0;
}
Problem p03293 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed                                                                  \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
const int INF = 1e9 + 5;
int main() {
  string s, t;
  cin >> s >> t;
  int cnt = 0;
  while (cnt < s.size() && s != t) {
    char x = s[0];
    s.erase(s.begin());
    s += x;
  }
  if (s == t)
    cout << "Yes";
  else
    cout << "No";
}

Fixed submission:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed                                                                  \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
const int INF = 1e9 + 5;
int main() {
  string s, t;
  cin >> s >> t;
  int cnt = 0;
  while (cnt < s.size() && s != t) {
    char x = s[0];
    s.erase(s.begin());
    s += x;
    cnt++;
  }
  if (s == t)
    cout << "Yes";
  else
    cout << "No";
}
Problem p03293 (Python)

Buggy submission (status: Runtime Error):
s = [*input()]
t = [*input()]
flg = 0

for i in range(len(s)):
    if s != t:
        s.append(s[0])
        s.remove(s[0])
    else:
        flg = 1
        break

if flg == 0:
    print("No")
else:
    print("Yes")


Fixed submission:
s = [i for i in input()]
t = [i for i in input()]
flg = 0

for i in range(len(s)):
    if s != t:
        s.append(s[0])
        s.remove(s[0])
    else:
        flg = 1
        break

if flg == 0:
    print("No")
else:
    print("Yes")
Problem p03293 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <string>
using namespace std;
int main() {
  string a, b;
  cin >> a >> b;
  int n = a.size();
  int c = 0;
  for (int i = 0; i < n; i++) {
    int f = 0;
    for (int j = 0; i < n; j++) {
      if (a[(i + j) % n] != b[j])
        f++;
    }
    if (f == 0)
      c = 1;
  }
  if (c == 1)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Fixed submission:
#include <iostream>
#include <string>
using namespace std;
int main() {
  string a, b;
  cin >> a >> b;
  int n = a.size();
  int c = 0;
  for (int i = 0; i < n; i++) {
    int f = 0;
    for (int j = 0; j < n; j++) {
      if (a[(i + j) % n] != b[j])
        f++;
    }
    if (f == 0)
      c = 1;
  }
  if (c == 1)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
Problem p03293 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FFOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FFOR(i, 0, n)
#define SORT(V) sort((V).begin(), (V).end())
#define INF ((1LL << 62) - (1LL << 31))
#define MOD 1000000007
using namespace std;

int main() {
  string S, T;
  cin >> S, T;

  bool CAN = true;
  for (int i = 0; i < S.size(); ++i) {
    CAN = true;
    for (int j = 0; j < S.size(); ++j) {
      if (j + i < S.size()) {
        if (S.at(j + i) != T.at(j))
          CAN = false;
      } else {
        if (S.at(j + i - S.size()) != T.at(j))
          CAN = false;
      }
    }
    if (CAN)
      break;
  }

  if (CAN)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FFOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FFOR(i, 0, n)
#define SORT(V) sort((V).begin(), (V).end())
#define INF ((1LL << 62) - (1LL << 31))
#define MOD 1000000007
using namespace std;

int main() {
  string S, T;
  cin >> S >> T;

  bool CAN = true;
  for (int i = 0; i < S.size(); ++i) {
    CAN = true;
    for (int j = 0; j < S.size(); ++j) {
      if (j + i < S.size()) {
        if (S.at(j + i) != T.at(j))
          CAN = false;
      } else {
        if (S.at(j + i - S.size()) != T.at(j))
          CAN = false;
      }
    }
    if (CAN)
      break;
  }

  if (CAN)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p03293 (C++)

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

using namespace std;

int main() {
  string S, T;
  cin >> S >> T;

  for (int i = 0; i < S.size(); i++) {
    if (S == T) {
      cout << "Yes" << endl;
      return 0;
    }
    S += S.substr(1) + S[0];
  }

  cout << "No" << endl;
}

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

using namespace std;

int main() {
  string S, T;
  cin >> S >> T;

  for (int i = 0; i < S.size(); i++) {
    if (S == T) {
      cout << "Yes" << endl;
      return 0;
    }
    S = S.substr(1) + S[0];
  }

  cout << "No" << endl;
}
Problem p03293 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <vector>
using namespace std;

int main() {
  string S, T;
  cin >> S >> T;

  int count = 0;
  int size = S.size();
  while (count <= size) {
    int front = S.at(size - 1);
    for (int i = 0; i < size; i++) {
      int tmp = S.at(i);
      S.at(i) = front;
      front = tmp;
    }
    if (S == T) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Fixed submission:
#include <iostream>
#include <vector>
using namespace std;

int main() {
  string S, T;
  cin >> S >> T;

  int count = 0;
  int size = S.size();
  while (count <= size) {
    int front = S.at(size - 1);
    for (int i = 0; i < size; i++) {
      int tmp = S.at(i);
      S.at(i) = front;
      front = tmp;
    }
    if (S == T) {
      cout << "Yes" << endl;
      return 0;
    }
    count++;
  }
  cout << "No" << endl;
  return 0;
}
Problem p03293 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  string s1, s2;
  cin >> s1 >> s2;
  s1 = s1 + s1;
  int sz = s2.size();
  for (int i = 0; i < 100; i++)
    if (s1.compare(i, sz, s2) == 0) {
      cout << "Yes";
      return 0;
    }
  cout << "No";
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  string s1, s2;
  cin >> s1 >> s2;
  s1 = s1 + s1;
  int sz = s2.size();
  for (int i = 0; i < sz; i++)
    if (s1.compare(i, sz, s2) == 0) {
      cout << "Yes";
      return 0;
    }
  cout << "No";
  return 0;
}
Problem p03293 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
using namespace std;
int main() {
  string s, t;
  int count = 0;
  cin >> s >> t;
  for (int i = 0; i < s.size(); i++) {
    t = t.back() + t.substr(t[0], t.size() - 1);
    if (s == t)
      count++;
  }
  if (count == 0)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
using namespace std;
int main() {
  string s, t;
  int count = 0;
  cin >> s >> t;
  for (int i = 0; i < s.size(); i++) {
    t = t.back() + t.substr(0, t.size() - 1);
    if (s == t)
      count++;
  }
  if (count == 0)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}
Problem p03293 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  string a, b;
  cin >> a >> b;
  int count = 0;
  int han = 0;
  while (count, a.size()) {
    char c = a.at(0);
    for (int i = 0; i < a.size() - 1; i++) {
      a.at(i) = a.at(i + 1);
    }
    a.at(a.size() - 1) = c;
    count++;
    if (a == b) {
      han++;
    }
  }
  if (han != 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  string a, b;
  cin >> a >> b;
  int count = 0;
  int han = 0;
  while (count < a.size()) {
    char c = a.at(0);
    for (int i = 0; i < a.size() - 1; i++) {
      a.at(i) = a.at(i + 1);
    }
    a.at(a.size() - 1) = c;
    count++;
    if (a == b) {
      han++;
    }
  }
  if (han != 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p03293 (C++)

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

int main() {
  string s, t;
  cin >> s >> t;
  for (int i = 0; i < s.size(); i++) {
    s = s.at(s.size() - 1) + s.substr(0, s.size());
    if (s == t) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

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

int main() {
  string s, t;
  cin >> s >> t;
  for (int i = 0; i < s.size(); i++) {
    s = s.at(s.size() - 1) + s.substr(0, s.size() - 1);
    if (s == t) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}