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

Buggy submission (status: Runtime Error):
// 問題URL
//

// 解き方メモ
//

#include <algorithm>
#include <iostream>
using namespace std;

#define MAX_N 100

int main() {
  int n;
  int t[MAX_N];
  int v[MAX_N];

  // 0.5s単位の速度。ve[1]で0.5秒時点の速度
  double ve[MAX_N * 200 + 1];

  double result;

  // 入力
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> t[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }

  // 計算
  // veを制限速度vで埋める。ただし、0sと終了時点は速度0
  ve[0] = 0;
  int total_half_s = 1;
  for (int i = 0; i < n; i++) { // i:ti,vi
    if (i > 0)
      ve[total_half_s - 1] = min(v[i], v[i - 1]);
    for (int j = 0; j < t[i];
         j++) { // tの秒数だけ埋める。0.5s単位なので、veは要素数が倍。
      ve[total_half_s] = v[i];
      ve[total_half_s + 1] = v[i];
      total_half_s += 2;
    }
  }
  int ve_n = total_half_s - 1;
  ve[ve_n] = 0;

  // veを開始から0.5s単位で加速した速度で埋める。ただし、制限速度vを上回るなら制限速度vとする。
  int i;
  for (i = 1; i < ve_n; i++) {
    ve[i] = min(ve[i], ve[i - 1] + 0.5);
  }
  // veを終着に向けて0.5s単位で減速した速度（0.5s未来から見て0.5速い速度：ve[i+1]+0.5）で埋める。
  // ただし、先のfor文の速度（ありえる速度の上限：ve[i]）を上回る速度は設定しない。
  for (i = ve_n - 1; i > 0; i--) {
    ve[i] = min(ve[i], ve[i + 1] + 0.5);
  }

  // 0.5s単位で移動距離を足し合わせる
  result = 0;
  for (int i = 0; i < ve_n; i++) {
    // 台形の公式：（上辺（現在速度）＋底辺（0.5s後の速度））×高さ（0.5s）／２
    result += (ve[i] + ve[i + 1]) * 0.5 / 2;
  }

  printf("%lf", result);
  cout << endl;

  return 0;
}

Fixed submission:
// 問題URL
//

// 解き方メモ
//

#include <algorithm>
#include <iostream>
using namespace std;

#define MAX_N 100

int main() {
  int n;
  int t[MAX_N];
  int v[MAX_N];

  // 0.5s単位の速度。ve[1]で0.5秒時点の速度
  double ve[MAX_N * 200 * 2 + 1];

  double result;

  // 入力
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> t[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }

  // 計算
  // veを制限速度vで埋める。ただし、0sと終了時点は速度0
  ve[0] = 0;
  int total_half_s = 1;
  for (int i = 0; i < n; i++) { // i:ti,vi
    if (i > 0)
      ve[total_half_s - 1] = min(v[i], v[i - 1]);
    for (int j = 0; j < t[i];
         j++) { // tの秒数だけ埋める。0.5s単位なので、veは要素数が倍。
      ve[total_half_s] = v[i];
      ve[total_half_s + 1] = v[i];
      total_half_s += 2;
    }
  }
  int ve_n = total_half_s - 1;
  ve[ve_n] = 0;

  // veを開始から0.5s単位で加速した速度で埋める。ただし、制限速度vを上回るなら制限速度vとする。
  int i;
  for (i = 1; i < ve_n; i++) {
    ve[i] = min(ve[i], ve[i - 1] + 0.5);
  }
  // veを終着に向けて0.5s単位で減速した速度（0.5s未来から見て0.5速い速度：ve[i+1]+0.5）で埋める。
  // ただし、先のfor文の速度（ありえる速度の上限：ve[i]）を上回る速度は設定しない。
  for (i = ve_n - 1; i > 0; i--) {
    ve[i] = min(ve[i], ve[i + 1] + 0.5);
  }

  // 0.5s単位で移動距離を足し合わせる
  result = 0;
  for (int i = 0; i < ve_n; i++) {
    // 台形の公式：（上辺（現在速度）＋底辺（0.5s後の速度））×高さ（0.5s）／２
    result += (ve[i] + ve[i + 1]) * 0.5 / 2;
  }

  printf("%lf", result);
  cout << endl;

  return 0;
}
Problem p03566 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
#define MAX_N 100 + 2
#define MAX_T 20000 + 1

int t[MAX_N];
double v[MAX_N], f[MAX_T];

double min(double a, double b) { return a < b ? a : b; }

int main(void) {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", &t[i]);
  for (int i = 0; i < n; i++)
    scanf("%lf", &v[i]);
  for (int i = 0; i < MAX_T; i++)
    f[i] = 1.E8;
  int tot = 0;
  for (int i = 0; i < n; i++) {
    t[i] *= 2;
    for (int j = tot; j <= tot + t[i]; j++)
      f[j] = min(f[j], v[i]);
    tot += t[i];
  }
  f[0] = f[tot] = 0.;
  for (int i = 1; i <= tot; i++)
    f[i] = min(f[i], f[i - 1] + .5);
  for (int i = tot - 1; i >= 0; i--)
    f[i] = min(f[i], f[i + 1] + .5);
  double ans = 0.;
  for (int i = 0; i < tot; i++)
    ans += .25 * (f[i] + f[i + 1]);
  printf("%f\n", ans);
  return 0;
}


Fixed submission:
#include <stdio.h>
#define MAX_N 100 + 2
#define MAX_T 40000

int t[MAX_N];
double v[MAX_N], f[MAX_T];

double min(double a, double b) { return a < b ? a : b; }

int main(void) {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", &t[i]);
  for (int i = 0; i < n; i++)
    scanf("%lf", &v[i]);
  for (int i = 0; i < MAX_T; i++)
    f[i] = 1.E8;
  int tot = 0;
  for (int i = 0; i < n; i++) {
    t[i] *= 2;
    for (int j = tot; j <= tot + t[i]; j++)
      f[j] = min(f[j], v[i]);
    tot += t[i];
  }
  f[0] = f[tot] = 0.;
  for (int i = 1; i <= tot; i++)
    f[i] = min(f[i], f[i - 1] + .5);
  for (int i = tot - 1; i >= 0; i--)
    f[i] = min(f[i], f[i + 1] + .5);
  double ans = 0.;
  for (int i = 0; i < tot; i++)
    ans += .25 * (f[i] + f[i + 1]);
  printf("%f\n", ans);
  return 0;
}
Problem p03567 (C++)

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

int main() {
  string s;
  cin >> s;
  if (s.substr(0, 2) == "AC" || s.substr(1, 2) == "AC" ||
      s.substr(2, 2) == "AC" || s.substr(3, 2) == "AC")
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

int main() {
  string s;
  cin >> s;
  bool is_ac = false;
  for (int i = 0; i < s.size() - 1; i++)
    if (s.substr(i, 2) == "AC") {
      is_ac = true;
      break;
    }
  if (is_ac)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p03567 (C++)

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

using namespace std;

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

  if (s.substr(0, 2) == "AC" || s.substr(1, 2) == "AC" ||
      s.substr(2, 2) == "AC" || s.substr(3, 2) == "AC")
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


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

using namespace std;

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

  for (int i = 0; i < s.length() - 1; i++) {
    if (s.substr(i, 2) == "AC") {
      cout << "Yes" << endl;
      return 0;
    }
  }

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
// char型から数値型に変換する関数（z.at(i)などに使用）
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
int main() {
  string s;
  bool t = false;
  for (int i = 0; i < s.size() - 1; i++) {
    if (s.at(i) == 'A' && s.at(i + 1) == 'C') {
      t = true;
    }
  }
  if (t) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
// char型から数値型に変換する関数（z.at(i)などに使用）
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
int main() {
  string s;
  cin >> s;
  bool t = false;
  for (int i = 0; i < s.size() - 1; i++) {
    if (s.at(i) == 'A' && s.at(i + 1) == 'C') {
      t = true;
    }
  }
  if (t) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p03567 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define ZERO (1e-10)
#define INF int(1e9 + 1)
#define CL(A, I) (memset(A, I, sizeof(A)))
#define DEB printf("DEB!\n");
#define D(X) cout << "  " << #X ": " << X << endl;
#define EQ(A, B) (A + ZERO > B && A - ZERO < B)
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
#define IN(n)                                                                  \
  int n;                                                                       \
  scanf("%d", &n);
#define FOR(i, m, n) for (int i(m); i < n; i++)
#define F(n) FOR(i, 0, n)
#define FF(n) FOR(j, 0, n)
#define FT(m, n) FOR(k, m, n)
#define aa first
#define bb second
void ga(int N, int *A) { F(N) scanf("%d", A + i); }
char s[666];
int L;
int main(void) {
  scanf("%s", s), L = strlen(s);
  F(L - 1) if (s[i] == 65 && s[i + 1] == 67) return puts("Yes");
  puts("No");
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define ZERO (1e-10)
#define INF int(1e9 + 1)
#define CL(A, I) (memset(A, I, sizeof(A)))
#define DEB printf("DEB!\n");
#define D(X) cout << "  " << #X ": " << X << endl;
#define EQ(A, B) (A + ZERO > B && A - ZERO < B)
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
#define IN(n)                                                                  \
  int n;                                                                       \
  scanf("%d", &n);
#define FOR(i, m, n) for (int i(m); i < n; i++)
#define F(n) FOR(i, 0, n)
#define FF(n) FOR(j, 0, n)
#define FT(m, n) FOR(k, m, n)
#define aa first
#define bb second
void ga(int N, int *A) { F(N) scanf("%d", A + i); }
char s[666];
int L;
int main(void) {
  scanf("%s", s), L = strlen(s);
  F(L - 1) if (s[i] == 65 && s[i + 1] == 67) return puts("Yes"), 0;
  puts("No");
  return 0;
}
Problem p03567 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>
#include <string.h>

int main() {
  int i;
  bool flag;
  char a[10];
  while (scanf("%s", a) != 0) {
    flag = 0;
    for (i = 0; i < strlen(a); i++) {
      if (a[i] == 'A' && a[i + 1] == 'C') {
        flag = 1;
        break;
      }
    }
    if (flag)
      printf("Yes\n");
    else
      printf("No\n");
  }
}

Fixed submission:
#include <stdio.h>
#include <string.h>

int main() {
  int i;
  bool flag;
  char a[10];
  while (scanf("%s", a) != EOF) {
    flag = 0;
    for (i = 0; i < strlen(a); i++) {
      if (a[i] == 'A' && a[i + 1] == 'C') {
        flag = 1;
        break;
      }
    }
    if (flag)
      printf("Yes\n");
    else
      printf("No\n");
  }
}
Problem p03567 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<ll, int> pli;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
  string s;
  cin >> s;
  rep(i, 4) {
    if (s.substr(i, i + 2) == "AC") {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<ll, int> pli;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
  string s;
  cin >> s;
  int n = s.size();
  rep(i, n - 1) {
    if (s[i] == 'A' && s[i + 1] == 'C') {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}
Problem p03567 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  string s;
  cin >> s;
  bool isreturn = false;
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) == 'A' && s.at(i + 1) == 'C') {
      isreturn = true;
    }
  }
  if (isreturn == true)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  string s;
  cin >> s;
  bool isreturn = false;
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) == 'A' && s.at(i + 1) == 'C') {
      isreturn = true;
      break;
    }
  }
  if (isreturn == true)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p03567 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string a;
  cin >> a;
  for (int i = 1; i < 5; i++) {
    if ("AC" == a.substr(i, 2)) {
      cout << "Yes";
      return 0;
    }
  }
  cout << "No";
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string a;
  cin >> a;
  for (int i = 0; i < a.size() - 1; i++) {
    if ("AC" == a.substr(i, 2)) {
      cout << "Yes";
      return 0;
    }
  }
  cout << "No";
}
Problem p03567 (C++)

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

int main() {
  char s[10];
  scanf("%s", s);
  int i = 0;
  while (1) {
    if (s[i] == 'A' && s[i + 1] == 'C') {
      printf("Yes");
      break;
    } else if (s[i + 1] = '\0') {
      printf("No");
      break;
    }
    ++i;
  }
  return 0;
}


Fixed submission:
#include <cstdio>

int main() {
  char s[10];
  scanf("%s", s);
  int i = 0;
  while (1) {
    if (s[i] == 'A' && s[i + 1] == 'C') {
      printf("Yes");
      break;
    } else if (s[i + 1] == '\0') {
      printf("No");
      break;
    }
    ++i;
  }
  return 0;
}
Problem p03567 (Python)

Buggy submission (status: Runtime Error):
S = input()
for _ in range(S - 1):
    if S[_ : _ + 2] == "AC":
        print("Yes")
        break
else:
    print("No")


Fixed submission:
S = input()
for _ in range(len(S) - 1):
    if S[_ : _ + 2] == "AC":
        print("Yes")
        break
else:
    print("No")
Problem p03567 (Python)

Buggy submission (status: Runtime Error):
S = input()
for i in range(len(S) - 1):
    if S[i, i + 1] == "AC":
        print("Yes")
        exit()
print("No")


Fixed submission:
S = input()
for i in range(len(S) - 1):
    if S[i : i + 2] == "AC":
        print("Yes")
        exit()
print("No")
Problem p03567 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod = 1000000007;
const int MAX_N = 1000; // n の最大値

// nCk を取得
double nCk(int n, int k) {
  double res = 1.0;
  for (int i = 0; i < n; i++) {
    res *= 0.5;
  }
  for (int i = 0; i < k; i++) {
    res *= (double)(n - i);
    res /= (double)(k - i);
  }
  return res;
}

int main() {
  string s;
  cin >> s;
  s += '00000';
  if (s.at(0) == 'A' && s.at(1) == 'C' || s.at(1) == 'A' && s.at(2) == 'C' ||
      s.at(2) == 'A' && s.at(3) == 'C' || s.at(3) == 'A' && s.at(4) == 'C') {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod = 1000000007;
const int MAX_N = 1000; // n の最大値

// nCk を取得
double nCk(int n, int k) {
  double res = 1.0;
  for (int i = 0; i < n; i++) {
    res *= 0.5;
  }
  for (int i = 0; i < k; i++) {
    res *= (double)(n - i);
    res /= (double)(k - i);
  }
  return res;
}

int main() {
  string s;
  cin >> s;
  s += '00000';
  s += 'aaaaa';
  s += 'adoooo';
  if (s.at(0) == 'A' && s.at(1) == 'C' || s.at(1) == 'A' && s.at(2) == 'C' ||
      s.at(2) == 'A' && s.at(3) == 'C' || s.at(3) == 'A' && s.at(4) == 'C') {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p03568 (Python)

Buggy submission (status: Runtime Error):
N = int(input().strip())
A = list(map(int, input().strip().split(" ")))

c_even = len(1 for a in A if a % 2 == 0)
ans = 3 ** len(A) - 2**c_even
print(ans)


Fixed submission:
N = int(input().strip())
A = list(map(int, input().strip().split(" ")))

c_even = len([1 for a in A if a % 2 == 0])
ans = 3 ** len(A) - 2**c_even
print(ans)
Problem p03568 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(n);
  }
  int all = 1, bad = 1;
  for (int i = 0; i < n; i++) {
    all *= 3;
    if (a.at(i) % 2 == 0)
      bad *= 2;
  }
  cout << all - bad << endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  int all = 1, bad = 1;
  for (int i = 0; i < n; i++) {
    all *= 3;
    if (a.at(i) % 2 == 0)
      bad *= 2;
  }
  cout << all - bad << endl;
}
Problem p03568 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define inf 0x7fffffff
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 10;
const int MAX = 1e5 + 10;
const double eps = 1e-6;

int n, cnt = 0;
int s[100];

void dfs(int node, int flag) {
  if (node == n) {
    if (flag % 2 == 0)
      cnt++;
    // cout<<flag<<endl;
    return;
  }
  dfs(node + 1, flag * s[node + 1]);
  dfs(node + 1, flag * (s[node + 1] - 1));
  dfs(node + 1, flag * (s[node + 1] + 1));
  return;
}

int main() {
#ifdef ONLINE_JUDGE
#else
  freopen("in.txt", "r", stdin);
// freopen("out.txt","w",stdout);
#endif

  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
  }
  dfs(1, s[1]);
  dfs(1, s[1] - 1);
  dfs(1, s[1] + 1);
  cout << cnt << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define inf 0x7fffffff
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 10;
const int MAX = 1e5 + 10;
const double eps = 1e-6;

int n, cnt = 0;
int s[100];

void dfs(int node, int flag) {
  if (node == n) {
    if (flag % 2 == 0)
      cnt++;
    // cout<<flag<<endl;
    return;
  }
  dfs(node + 1, flag * s[node + 1]);
  dfs(node + 1, flag * (s[node + 1] - 1));
  dfs(node + 1, flag * (s[node + 1] + 1));
  return;
}

int main() {
#ifdef ONLINE_JUDGE
#else
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
#endif

  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
  }
  dfs(1, s[1]);
  dfs(1, s[1] - 1);
  dfs(1, s[1] + 1);
  cout << cnt << endl;

  return 0;
}
Problem p03568 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <queue>
#include <vector>
using namespace std;
#define f(i, n) for (int i = 0; i < (int)n; i++)
#define MOD 1000000009

int main(void) {
  int a[100];
  f(i, 100000) a[i] = 0;
  int k, s;
  int n, m;
  int x, y, z;
  int ans = 1;
  scanf("%d", &n);
  x = 1;
  f(i, n) {
    ans = ans * 3;
    scanf("%d", &a[i]);
    if (a[i] % 2 == 0)
      x = x * 2;
  }

  ans -= x;

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

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <queue>
#include <vector>
using namespace std;
#define f(i, n) for (int i = 0; i < (int)n; i++)
#define MOD 1000000009

int main(void) {
  int a[100];
  f(i, 100) a[i] = 0;
  int k, s;
  int n, m;
  int x, y, z;
  int ans = 1;
  scanf("%d", &n);
  x = 1;
  f(i, n) {
    ans = ans * 3;
    scanf("%d", &a[i]);
    if (a[i] % 2 == 0)
      x = x * 2;
  }

  ans -= x;

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

  return 0;
}
Problem p03569 (C++)

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define LL long long

string s;
vector<char> vs;
vector<char> vc;
vector<int> vx;

int main() {
  cin >> s;
  int n = s.size();
  REP(i, n) {
    vs.push_back(s[i]);
    if (s[i] != 'x')
      vc.push_back(s[i]);
  }
  int m = vc.size();
  REP(i, vc.size()) {
    if (vc[i] != vc[vc.size() - 1 - i]) {
      cout << -1 << endl;
      return 0;
    }
  }
  int cnt = 0;
  REP(i, n) {
    if (s[i] == 'x')
      vx.push_back(cnt);
    else
      cnt++;
  }
  cnt = 0;
  while (vx.size()) {
    vector<int>::iterator it = lower_bound(vx.begin(), vx.end(), m - vx[0]);
    if (vx[0] == m - vx[distance(vx.begin(), it)]) {
      if (m % 2 == 1 || vx[0] != m / 2) {
        vx.erase(vx.begin());
        if (vx.size())
          vx.erase(vx.begin() + distance(vx.begin(), it) - 1);
      } else {
        vx.erase(vx.begin());
      }
    } else {
      vx.erase(vx.begin());
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define LL long long

string s;
vector<char> vs;
vector<char> vc;
vector<int> vx;

int main() {
  cin >> s;
  int n = s.size();
  REP(i, n) {
    vs.push_back(s[i]);
    if (s[i] != 'x')
      vc.push_back(s[i]);
  }
  int m = vc.size();
  REP(i, vc.size()) {
    if (vc[i] != vc[vc.size() - 1 - i]) {
      cout << -1 << endl;
      return 0;
    }
  }
  int cnt = 0;
  REP(i, n) {
    if (s[i] == 'x')
      vx.push_back(cnt);
    else
      cnt++;
  }
  cnt = 0;
  while (vx.size()) {
    vector<int>::iterator it = lower_bound(vx.begin(), vx.end(), m - vx[0]);
    if (distance(vx.begin(), it) != vx.size() &&
        vx[0] == m - vx[distance(vx.begin(), it)]) {
      if (m % 2 == 1 || vx[0] != m / 2) {
        vx.erase(vx.begin());
        if (vx.size())
          vx.erase(vx.begin() + distance(vx.begin(), it) - 1);
      } else {
        vx.erase(vx.begin());
      }
    } else {
      vx.erase(vx.begin());
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}
Problem p03569 (C++)

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

using namespace std;

bool is_palindrome(const string &s) {
  bool res = true;
  for (int i = 0; i < s.size() / 2; i++) {
    if (s[i] != s[s.size() - i - 1]) {
      res = false;
      break;
    }
  }

  return res;
}

int solve(string &s, int l, int r) {
  if (l == r) {
    return 0;
  }

  char l_ch = s[l], r_ch = s[r];
  if (l_ch == r_ch) {
    return solve(s, l + 1, r - 1);
  } else if (l_ch != 'x') {
    return solve(s, l, r - 1) + 1;
  } else {
    return solve(s, l + 1, r) + 1;
  }
}

int main(int argc, const char *argv[]) {
  string s;
  cin >> s;

  string s2;
  copy_if(s.begin(), s.end(), back_inserter(s2),
          [](char ch) { return ch != 'x'; });
  if (!is_palindrome(s2)) {
    cout << -1 << '\n';
    return 0;
  }

  cout << solve(s, 0, s.size() - 1) << '\n';
  return 0;
}

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

using namespace std;

bool is_palindrome(const string &s) {
  bool res = true;
  for (int i = 0; i < s.size() / 2; i++) {
    if (s[i] != s[s.size() - i - 1]) {
      res = false;
      break;
    }
  }

  return res;
}

int solve(string &s, int l, int r) {
  if (l >= r) {
    return 0;
  }

  char l_ch = s[l], r_ch = s[r];
  if (l_ch == r_ch) {
    return solve(s, l + 1, r - 1);
  } else if (l_ch != 'x') {
    return solve(s, l, r - 1) + 1;
  } else {
    return solve(s, l + 1, r) + 1;
  }
}

int main(int argc, const char *argv[]) {
  string s;
  cin >> s;

  string s2;
  copy_if(s.begin(), s.end(), back_inserter(s2),
          [](char ch) { return ch != 'x'; });
  if (!is_palindrome(s2)) {
    cout << -1 << '\n';
    return 0;
  }

  cout << solve(s, 0, s.size() - 1) << '\n';
  return 0;
}
Problem p03569 (C++)

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

int main() {
  int i, N, K, a = 0, b, cnt = 0;
  char ss[10000];
  scanf("%s", ss);
  N = strlen(ss);
  b = N - 1;
  while (a < b) {
    if (ss[a] == ss[b]) {
      a++;
      b--;
      continue;
    } else if (ss[a] == 'x') {
      a++;
      cnt++;
      continue;
    } else if (ss[b] == 'x') {
      b--;
      cnt++;
      continue;
    } else {
      printf("-1");
      return 0;
    }
  }
  printf("%d", cnt);
  return 0;
}

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

int main() {
  int i, N, K, a = 0, b, cnt = 0;
  char ss[100001];
  scanf("%s", ss);
  N = strlen(ss);
  b = N - 1;
  while (a < b) {
    if (ss[a] == ss[b]) {
      a++;
      b--;
      continue;
    } else if (ss[a] == 'x') {
      a++;
      cnt++;
      continue;
    } else if (ss[b] == 'x') {
      b--;
      cnt++;
      continue;
    } else {
      printf("-1");
      return 0;
    }
  }
  printf("%d", cnt);
  return 0;
}
Problem p03569 (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 = b; i-- > (a);)
#define all(v) v.begin(), v.end()
#define trav(x, v) for (auto &x : v)
#define sz(v) (int)(v).size()
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

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

  string s;
  cin >> s;
  int n = sz(s);
  string t;
  vi pos;
  rep(i, 0, n) {
    if (s[i] != 'x') {
      t.push_back(s[i]);
      pos.push_back(i);
    }
  }
  string t2 = t;
  reverse(all(t2));
  if (t2 != t) {
    cout << -1 << endl;
    return 0;
  }
  int mi1 = (sz(t) - 1) / 2;
  int ans = 0;
  rep(i, 0, mi1) {
    int j = sz(t) - 1 - i;
    int c1 = pos[i + 1] - pos[i];
    int c2 = pos[j] - pos[j - 1];
    ans += abs(c1 - c2);
  }
  ans += abs(pos[0] - (n - 1 - pos.back()));
  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 = b; i-- > (a);)
#define all(v) v.begin(), v.end()
#define trav(x, v) for (auto &x : v)
#define sz(v) (int)(v).size()
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

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

  string s;
  cin >> s;
  int n = sz(s);
  string t;
  vi pos;
  rep(i, 0, n) {
    if (s[i] != 'x') {
      t.push_back(s[i]);
      pos.push_back(i);
    }
  }
  if (sz(t) == 0) {
    cout << 0 << endl;
    return 0;
  }
  string t2 = t;
  reverse(all(t2));
  if (t2 != t) {
    cout << -1 << endl;
    return 0;
  }
  int mi1 = (sz(t) - 1) / 2;
  int ans = 0;
  rep(i, 0, mi1) {
    int j = sz(t) - 1 - i;
    int c1 = pos[i + 1] - pos[i];
    int c2 = pos[j] - pos[j - 1];
    ans += abs(c1 - c2);
  }
  ans += abs(pos[0] - (n - 1 - pos.back()));
  cout << ans << endl;
}
Problem p03569 (C++)

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

string s;
string t;

int main() {

  cin >> s;

  for (int i = 0; i < s.size(); i++)
    if (s[i] != 'x')
      t += s[i];

  for (int i = 0; i < t.size() / 2; i++)
    if (t[i] != t[t.size() - (i + 1)]) {
      cout << -1 << endl;
      return 0;
    }

  int l = 0, r = s.size() - 1;

  int ans = 0;

  while (l < r) {

    int lcnt = 0, rcnt = 0;

    while (s[l] == 'x')
      lcnt++, l++;
    while (s[r] == 'x')
      rcnt++, r--;

    ans += abs(lcnt - rcnt);
  }

  cout << ans << endl;

  return 0;
}


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

string s;
string t;

int main() {

  cin >> s;

  for (int i = 0; i < s.size(); i++)
    if (s[i] != 'x')
      t += s[i];

  for (int i = 0; i < t.size() / 2; i++)
    if (t[i] != t[t.size() - (i + 1)]) {
      cout << -1 << endl;
      return 0;
    }

  int l = 0, r = s.size() - 1;

  int ans = 0;

  while (l < r) {

    int lcnt = 0, rcnt = 0;

    while (s[l] == 'x')
      lcnt++, l++;
    while (s[r] == 'x')
      rcnt++, r--;
    l++, r--;
    ans += abs(lcnt - rcnt);
  }

  cout << ans << endl;

  return 0;
}
Problem p03569 (C++)

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

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (ll i = j; i < (n); i++)
#define CLR(mat, f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a <= x && x < b)
#define out(ans) cout << ans << endl
typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;
const int INF = 1000000;
const double PI = 3.14159265359;

int main() {

  string s;
  cin >> s;
  ll n = s.size();
  string k = "";
  rep(i, 0, n) if (s[i] != 'x') k += s[i];
  bool e = true;
  rep(i, 0, (k.size() + 1) / 2) {
    if (k[i] != k[k.size() - 1 - i])
      e = false;
  }

  if (!e) {
    out(-1);
    return 0;
  }

  ll ans = 0;
  while (s.size() <= 1) {
    out(s);
    if (s[0] == s[s.size() - 1]) {
      s.pop_back();
      s.erase(s.begin());
    } else {
      ans++;
      if (s[0] == 'x') {
        s += 'x';
      } else if (s[s.size() - 1] == 'x') {
        s.insert(s.begin(), 'x');
      } else {
        out(-1);
        return 0;
      }
    }
  }
  out(ans);

  return 0;
}


Fixed submission:
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (ll i = j; i < (n); i++)
#define CLR(mat, f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a <= x && x < b)
#define out(ans) cout << ans << endl
typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;
const int INF = 1000000;
const double PI = 3.14159265359;

int main() {

  string s;
  cin >> s;
  ll n = s.size();
  string k = "";
  rep(i, 0, n) if (s[i] != 'x') k += s[i];
  bool e = true;
  rep(i, 0, (k.size() + 1) / 2) {
    if (k[i] != k[k.size() - 1 - i])
      e = false;
  }

  if (!e) {
    out(-1);
    return 0;
  }

  ll ans = 0;
  while (s.size() > 1) {
    if (s[0] == s[s.size() - 1]) {
      s.pop_back();
      s.erase(s.begin());
    } else {
      ans++;
      if (s[0] == 'x') {
        s += 'x';
      } else if (s[s.size() - 1] == 'x') {
        s.insert(s.begin(), 'x');
      } else {
        out(-1);
        return 0;
      }
    }
  }
  out(ans);

  return 0;
}
Problem p03569 (Python)

Buggy submission (status: Runtime Error):
S = input()
N = len(S)
non_x = []
s_notx = []
for i, s in enumerate(S):
    if s != "x":
        non_x.append(i)
        s_notx.append(s)
s_notx = "".join(s_notx)
if s_notx != s_notx[::-1]:
    print(-1)
    quit()

ans = 0
L = len(non_x)
if L % 2 == 0:
    left, right = L // 2 - 1, L // 2
else:
    left = right = L // 2
left, right = left - 1, right + 1
for i in range(left + 1):
    l, r = left - i, right + i
    ans += abs((non_x[l + 1] - non_x[l]) - (non_x[r] - non_x[r - 1]))
ans += abs(non_x[0] - (N - non_x[-1] - 1))
print(ans)


Fixed submission:
S = input()
N = len(S)
non_x = []
s_notx = []
for i, s in enumerate(S):
    if s != "x":
        non_x.append(i)
        s_notx.append(s)
s_notx = "".join(s_notx)
if s_notx != s_notx[::-1]:
    print(-1)
    quit()
if not non_x:
    print(0)
    quit()
ans = 0
L = len(non_x)
if L % 2 == 0:
    left, right = L // 2 - 1, L // 2
else:
    left = right = L // 2
left, right = left - 1, right + 1
for i in range(left + 1):
    l, r = left - i, right + i
    ans += abs((non_x[l + 1] - non_x[l]) - (non_x[r] - non_x[r - 1]))
ans += abs(non_x[0] - (N - non_x[-1] - 1))
print(ans)
Problem p03569 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
#define int long long
  int answer = 0;
  string S, FS = "";
  cin >> S;
  for (int i = 0; i < (int)S.size(); i++) {
    if (S.at(i) != 'x') {
      FS += S.at(i);
    }
  }
  for (int i = 0; i < (int)FS.size(); i++) {
    if (FS.at(i) != FS.at((int)FS.size() - i - 1)) {
      cout << -1 << endl;
      return 0;
    }
  }
  int s = (int)S.size();
  for (int i = 0; i < (int)S.size(); i++) {
    if (S.at(i) != S.at((int)S.size() - i - 1)) {
      answer++;
      if (S.at(i) == 'x') {
        S += 'x';
      } else {
        S.insert(i, "x");
      }
    }
  }
  cout << answer << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
#define int long long
  int answer = 0;
  string S, FS = "";
  cin >> S;
  for (int i = 0; i < (int)S.size(); i++) {
    if (S.at(i) != 'x') {
      FS += S.at(i);
    }
  }
  for (int i = 0; i < (int)FS.size(); i++) {
    if (FS.at(i) != FS.at((int)FS.size() - i - 1)) {
      cout << -1 << endl;
      return 0;
    }
  }
  int s = (int)S.size();
  for (int i = 0; i < (int)S.size(); i++) {
    if (S.at(i) != S.at((int)S.size() - i - 1)) {
      answer++;
      if (S.at(i) == 'x') {
        S.insert((int)S.size() - i, "x");
      } else {
        S.insert(i, "x");
      }
    }
  }
  cout << answer << endl;
}
Problem p03569 (C++)

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

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

  int ans = 0;
  while (true) {
    // cout << S << endl;
    if (S.length() == 1)
      break;

    if (S.front() == S.back()) {
      S = S.substr(1, S.length() - 2);
    } else if (S.front() == 'x') {
      S = S + "x";
      ans++;
    } else if (S.back() == 'x') {
      S = "x" + S;
      ans++;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
}


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

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

  int ans = 0;
  while (true) {
    // cout << S << endl;
    if (S.length() == 1)
      break;

    if (S.front() == S.back()) {
      if (S.length() == 2)
        break;
      else
        S = S.substr(1, S.length() - 2);
    } else if (S.front() == 'x') {
      S = S + "x";
      ans++;
    } else if (S.back() == 'x') {
      S = "x" + S;
      ans++;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
}
Problem p03569 (C++)

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(x) (x).begin(), (x).end()
#define foreach(u, v) for (auto(u) : (v))
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;

const int inf = 1e9;
const ll linf = 1LL << 60;
const ll mod = 1e9 + 7;
const double eps = 1e-9;

/*{

}*/

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

  vector<pair<char, int>> t;
  rep(i, n) {
    if (s[i] != 'x')
      t.pb(mp(s[i], i));
  }
  int m = t.size();

  bool flag = true;
  rep(i, m / 2) {
    if (t[i].first != t[m - 1 - i].first)
      flag = false;
  }

  if (!flag) {
    cout << -1 << endl;
    return 0;
  }

  map<int, int> left, right;
  int cnt = 0;
  rep(i, t[(m - 1) / 2].second) {
    if (s[i] == 'x') {
      left[cnt]++;
    } else {
      cnt++;
    }
  }

  cnt = 0;
  for (int i = n - 1; i >= t[m / 2].second; i--) {
    if (s[i] == 'x') {
      right[cnt]++;
    } else {
      cnt++;
    }
  }

  int ans = 0;
  rep(i, m / 2 + 1) {
    if (left.count(i) == 0)
      left[i] = 0;
    if (right.count(i) == 0)
      right[i] = 0;
    ans += abs(left[i] - right[i]);
    //    cout << i << " : " << left[i] << " : " << right[i] << endl;
  }

  cout << ans << endl;

  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(x) (x).begin(), (x).end()
#define foreach(u, v) for (auto(u) : (v))
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;

const int inf = 1e9;
const ll linf = 1LL << 60;
const ll mod = 1e9 + 7;
const double eps = 1e-9;

/*{

}*/

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

  vector<pair<char, int>> t;
  rep(i, n) {
    if (s[i] != 'x')
      t.pb(mp(s[i], i));
  }
  int m = t.size();

  if (m == 0) {
    cout << 0 << endl;
    return 0;
  }

  bool flag = true;
  rep(i, m / 2) {
    if (t[i].first != t[m - 1 - i].first)
      flag = false;
  }

  if (!flag) {
    cout << -1 << endl;
    return 0;
  }

  map<int, int> left, right;
  int cnt = 0;
  rep(i, t[(m - 1) / 2].second) {
    if (s[i] == 'x') {
      left[cnt]++;
    } else {
      cnt++;
    }
  }

  cnt = 0;
  for (int i = n - 1; i >= t[m / 2].second; i--) {
    if (s[i] == 'x') {
      right[cnt]++;
    } else {
      cnt++;
    }
  }

  int ans = 0;
  rep(i, m / 2 + 1) {
    if (left.count(i) == 0)
      left[i] = 0;
    if (right.count(i) == 0)
      right[i] = 0;
    ans += abs(left[i] - right[i]);
    //    cout << i << " : " << left[i] << " : " << right[i] << endl;
  }

  cout << ans << endl;

  return 0;
}
Problem p03569 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
bool isPalindrome(string s) {
  int l = s.length();
  for (int i = 0; 2 * i <= l; i++) {
    if (s[i] != s[l - 1 - i])
      return false;
  }
  return true;
}
string Replace(string String1, string String2, string String3) {
  string::size_type Pos(String1.find(String2));

  while (Pos != string::npos) {
    String1.replace(Pos, String2.length(), String3);
    Pos = String1.find(String2, Pos + String3.length());
  }

  return String1;
}
int main() {
  string S;
  cin >> S;
  string s = Replace(S, string("x"), string(""));
  if (!isPalindrome(s)) {
    cout << -1 << endl;
    return 0;
  }
  int l = 0, r = S.length() - 1;
  int lx = 0, rx = 0, ans = 0;
  while (true) {
    if (S[l] == 'x') {
      lx++;
      l++;
    }
    if (S[r] == 'x') {
      rx++;
      r--;
    }
    if (S[r] != 'x' && S[r] == S[l]) {
      ans += abs(lx - rx);
      lx = rx = 0;
      if (l == r)
        break;
      l++;
      r--;
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
bool isPalindrome(string s) {
  int l = s.length();
  for (int i = 0; 2 * i <= l; i++) {
    if (s[i] != s[l - 1 - i])
      return false;
  }
  return true;
}
string Replace(string String1, string String2, string String3) {
  string::size_type Pos(String1.find(String2));

  while (Pos != string::npos) {
    String1.replace(Pos, String2.length(), String3);
    Pos = String1.find(String2, Pos + String3.length());
  }

  return String1;
}
int main() {
  string S;
  cin >> S;
  string s = Replace(S, string("x"), string(""));
  if (!isPalindrome(s)) {
    cout << -1 << endl;
    return 0;
  }
  int l = 0, r = S.length() - 1;
  int lx = 0, rx = 0, ans = 0;
  while (true) {
    if (S[l] == 'x') {
      lx++;
      l++;
    }
    if (S[r] == 'x') {
      rx++;
      r--;
    }
    if (S[r] != 'x' && S[r] == S[l]) {
      ans += abs(lx - rx);
      lx = rx = 0;
      if (l >= r)
        break;
      l++;
      r--;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03569 (C++)

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

int main() {
  string s;
  cin >> s;
  ll l = 0, r = s.size() - 1, lx = 0, rx = 0, ans = 0;
  while (l <= r) {
    lx = 0;
    rx = 0;
    while (s.at(l) == 'x') {
      l++;
      lx++;
    }
    while (s.at(r) == 'x') {
      r--;
      rx++;
    }
    if (s.at(l) != s.at(r)) {
      cout << -1 << endl;
      return 0;
    }
    ans += abs(lx - rx);
    l++;
    r--;
  }
  cout << ans << endl;
}


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

int main() {
  string s;
  cin >> s;
  ll l = 0, r = s.size() - 1, lx = 0, rx = 0, ans = 0;
  while (l <= r) {
    lx = 0;
    rx = 0;
    while (s.at(l) == 'x') {
      l++;
      lx++;
      if (l == s.size()) {
        cout << 0 << endl;
        return 0;
      }
    }
    while (s.at(r) == 'x') {
      r--;
      rx++;
    }
    if (s.at(l) != s.at(r)) {
      cout << -1 << endl;
      return 0;
    }
    ans += abs(lx - rx);
    l++;
    r--;
  }
  cout << ans << endl;
}
Problem p03569 (C++)

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

using namespace std;

#define REP(i, N) for (int(i) = 0; (i) < (N); ++(i))
#define READALL(c)                                                             \
  for (auto &e : c) {                                                          \
    cin >> e;                                                                  \
  }
#define PRINTALL(c)                                                            \
  for (const auto &e : c) {                                                    \
    cout << e << "\t";                                                         \
  }                                                                            \
  cout << "\n";

template <typename T> using V = vector<T>;

typedef long double ld;

int main() {

  string S, XS;
  cin >> S;

  V<int> XSi;

  REP(i, S.size()) if (S[i] != 'x') {
    XS.push_back(S[i]);
    XSi.push_back(i);
  }

  string rev = XS;
  reverse(rev.begin(), rev.end());
  if (rev != XS) {
    cout << -1 << endl;
    return 0;
  }

  int l, r;

  if (XS.size() % 2) {
    l = r = XSi[XS.size() / 2];
  } else {
    l = XSi[XS.size() / 2 - 1];
    r = XSi[XS.size() / 2];
  }

  int ans = 0;

  while (l >= 0 || r < S.size()) {
    char lc = l < 0 ? '@' : S[l];
    char rc = r >= S.size() ? '@' : S[r];
    if (lc == rc) {
      --l;
      ++r;
    } else {
      ++ans;
      if (lc == 'x') {
        --l;
      } else {
        ++r;
      }
    }
  }

  cout << ans << endl;
}

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

using namespace std;

#define REP(i, N) for (int(i) = 0; (i) < (N); ++(i))
#define READALL(c)                                                             \
  for (auto &e : c) {                                                          \
    cin >> e;                                                                  \
  }
#define PRINTALL(c)                                                            \
  for (const auto &e : c) {                                                    \
    cout << e << "\t";                                                         \
  }                                                                            \
  cout << "\n";

template <typename T> using V = vector<T>;

typedef long double ld;

int main() {

  string S, XS;
  cin >> S;

  V<int> XSi;

  REP(i, S.size()) if (S[i] != 'x') {
    XS.push_back(S[i]);
    XSi.push_back(i);
  }

  string rev = XS;
  reverse(rev.begin(), rev.end());
  if (rev != XS) {
    cout << -1 << endl;
    return 0;
  }

  int l, r;

  if (XS.size() == 0) {
    cout << 0 << endl;
    return 0;
  } else if (XS.size() % 2) {
    l = r = XSi[XS.size() / 2];
  } else {
    l = XSi[XS.size() / 2 - 1];
    r = XSi[XS.size() / 2];
  }

  int ans = 0;

  while (l >= 0 || r < S.size()) {
    char lc = l < 0 ? '@' : S[l];
    char rc = r >= S.size() ? '@' : S[r];
    if (lc == rc) {
      --l;
      ++r;
    } else {
      ++ans;
      if (lc == 'x') {
        --l;
      } else {
        ++r;
      }
    }
  }

  cout << ans << endl;
}
Problem p03569 (C++)

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

using namespace std;

int main() {
  string S;
  cin >> S;
  string S_without_x;
  for (int i = 0; i < S.length(); i++)
    if (!(S[i] == 'x'))
      S_without_x += S[i];

  string S_without_x_copy = S_without_x;
  int ret = 0;
  reverse(S_without_x.begin(), S_without_x.end());
  if (!(S_without_x_copy == S_without_x)) {
    ret = -1;
  } else {
    int begin = 0, end = S.length() - 1;
    while (!(begin == end)) {
      if (S[begin] != 'x' && S[end] != 'x') {
        begin++;
        end--;
      } else if (S[begin] == 'x' && S[end] != 'x') {
        begin++;
        ret++;
      } else if (S[begin] != 'x' && S[end] == 'x') {
        end--;
        ret++;
      } else if (S[begin] == 'x' && S[end] == 'x') {
        begin++;
        end--;
      }
    }
  }

  cout << ret << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

int main() {
  string S;
  cin >> S;
  string S_without_x;
  for (int i = 0; i < S.length(); i++)
    if (!(S[i] == 'x'))
      S_without_x += S[i];

  string S_without_x_copy = S_without_x;
  int ret = 0;
  reverse(S_without_x.begin(), S_without_x.end());
  if (!(S_without_x_copy == S_without_x)) {
    ret = -1;
  } else {
    int begin = 0, end = S.length() - 1;
    while (!(begin >= end)) {
      if (S[begin] != 'x' && S[end] != 'x') {
        begin++;
        end--;
      } else if (S[begin] == 'x' && S[end] != 'x') {
        begin++;
        ret++;
      } else if (S[begin] != 'x' && S[end] == 'x') {
        end--;
        ret++;
      } else if (S[begin] == 'x' && S[end] == 'x') {
        begin++;
        end--;
      }
    }
  }

  cout << ret << endl;

  return 0;
}
Problem p03569 (C++)

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

using namespace std;

int main() {
  string str = "";
  cin >> str;
  string cp = "";
  for (char c : str) {
    if (c != 'x') {
      cp.push_back(c);
    }
  }
  string cp_rev = cp;
  reverse(cp_rev.begin(), cp_rev.end());
  if (cp != cp_rev) {
    cout << -1 << endl;
  } else {
    auto iter = str.begin(), iter_rev = str.end() - 1;
    int cnt = 0;
    while (true) {
      if (iter == iter_rev) {
        break;
      }
      if (*iter == *iter_rev) {
        iter++;
        iter_rev--;
      } else {
        cnt++;
        if (*iter == 'x') {
          iter++;
        } else {
          iter_rev--;
        }
      }
    }
    cout << cnt << endl;
  }
  return 0;
}


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

using namespace std;

int main() {
  string str = "";
  cin >> str;
  string cp = "";
  for (char c : str) {
    if (c != 'x') {
      cp.push_back(c);
    }
  }
  string cp_rev = cp;
  reverse(cp_rev.begin(), cp_rev.end());
  if (cp != cp_rev) {
    cout << -1 << endl;
  } else {
    auto iter = str.begin(), iter_rev = str.end() - 1;
    int cnt = 0;
    while (true) {
      if (iter >= iter_rev) {
        break;
      }
      if (*iter == *iter_rev) {
        iter++;
        iter_rev--;
      } else {
        cnt++;
        if (*iter == 'x') {
          iter++;
        } else {
          iter_rev--;
        }
      }
    }
    cout << cnt << endl;
  }
  return 0;
}
Problem p03569 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int i, j, bo, ans;
string st;
int main() {
  getline(cin, st);
  i = 0;
  j = st.size() - 1;
  while (i <= j) {
    if (st[i] == st[j]) {
      i++;
      j--;
      continue;
    }
    if (st[i] == 'x') {
      i++;
      ans++;
      continue;
    }
    if (st[j] == 'x') {
      j--;
      ans++;
      continue;
    }
    bo = 1;
  }
  if (bo != 1)
    cout << ans << "\n";
  else
    cout << -1 << "\n";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int i, j, bo, ans;
string st;
int main() {
  getline(cin, st);
  i = 0;
  j = st.size() - 1;
  while (i <= j) {
    if (st[i] == st[j]) {
      i++;
      j--;
      continue;
    }
    if (st[i] == 'x') {
      i++;
      ans++;
      continue;
    }
    if (st[j] == 'x') {
      j--;
      ans++;
      continue;
    }
    bo = 1;
    break;
  }
  if (bo != 1)
    cout << ans << "\n";
  else
    cout << -1 << "\n";
  return 0;
}