alexjercan/bugnet huggingface dataset:
Problem p02730 (C++) — buggy submission, verdict: Runtime Error

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

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

  int N = S.size();
  bool a = true;
  for (int i = 1; i <= N; i++) {

    if (S.at(i - 1) == S.at(N - i)) {
      continue;
    } else {
      a = false;
      break;
    }
  }
  for (int i = 1; i <= (N - 1) / 2; i++) {

    if (S.at(i - 1) == S.at((N - 1) / 2 - i)) {
      continue;
    } else {
      a = false;
      break;
    }
  }

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


Error: WA

Fixed submission:

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

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

  int N = S.size();
  bool a = true;
  for (int i = 0; i < N; i++) {
    if (S.at(i) == S.at((N - 1) / 2 - i) && S.at((N + 3) / 2) == S.at(N - i)) {
      continue;
    } else {
      a = false;
      break;
    }
  }
  if (a)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p02730 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  string a;
  cin >> a;
  int c = 1;
  int b = a.size();
  for (int i = 0; i < b; i++) {
    if (a.at(i) != a.at(b - i - 1))
      c = 0;
  }
  for (int i = 0; i < (b - 1) / 2; i++) {
    if (a.at(i) != a.at((b - 1) / 2 - i - 1))
      c = 0;
  }

  for (int i = (b + 3) / 2; i < b; i++) {
    if (a.at(i) != a.at(b - i - 1))
      c = 0;
  }
  if (c == 1)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::at: __n (which is 7) >= this->size() (which is 7)


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  string a;
  cin >> a;
  int c = 1;
  int b = a.size();
  for (int i = 0; i < b; i++) {
    if (a.at(i) != a.at(b - i))
      c = 0;
  }
  for (int i = 0; i < (b - 1) / 2; i++) {
    if (a.at(i) != a.at((b - 1) / 2 - i))
      c = 0;
  }

  for (int i = (b + 3) / 2; i < b; i++) {
    if (a.at(i) != a.at(b - i))
      c = 0;
  }
  if (c == 1)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p02730 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()    // 昇順ソート
#define rall(v) (v).rbegin(), (v).rend() // 降順ソート
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

bool isPalindrome(string s) {
  string es = s;
  reverse(all(es));
  return s == es;
}

int main() {
  string S;
  cin >> S;
  int i1 = (S.size() - 1) / 2, i2 = (S.size() + 3) / 2;
  string s1 = S.substr(0, i1), s2 = S.substr(i2 - 1, S.size());
  cout << (isPalindrome(S) && isPalindrome(s1) && isPalindrome(s2) ? "Yes"
                                                                   : "No")
       << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()    // 昇順ソート
#define rall(v) (v).rbegin(), (v).rend() // 降順ソート
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

bool isPalindrome(string s) {
  int si = 0, ei = s.size() - 1;
  while (si != ei) {
    if (s.at(si) != s.at(ei))
      return false;
    si++;
    ei--;
  }
  return true;
}

int main() {
  string S;
  cin >> S;
  int i1 = (S.size() - 1) / 2, i2 = (S.size() + 3) / 2;
  string s1 = S.substr(0, i1), s2 = S.substr(i2 - 1, S.size());
  cout << (isPalindrome(S) && isPalindrome(s1) && isPalindrome(s2) ? "Yes"
                                                                   : "No")
       << endl;
}
Problem p02730 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  int N = S.size();
  string ans = "Yes";
  for (int i = 0; i <= (N - 3) / 2; i++) {
    if (S.at(i) != S.at(N - i - 1) || S.at(i) != S.at((N - 3) / 2 - i)) {
      ans = "No";
      break;
    }
  }
  cout << ans << endl;

  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::at: __n (which is 7) >= this->size() (which is 7)


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  int N = S.size();
  string ans = "Yes";
  for (int i = 0; i <= (N - 3) / 4; i++) {
    if (S.at(i) != S.at(N - i) || S.at(i) != S.at((N - 3) / 2)) {
      ans = "No";
      break;
    }
  }
  cout << ans << endl;

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

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define int long long int

signed main() {
  string s;
  cin >> s;
  int s_center = ((s.length() + 1) / 2) - 1;
  string mae = s.substr(0, s_center);
  string usiro = s.substr(s_center + 1);
  if (mae == usiro) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::substr: __pos (which is 18446744073709551615) > this->size() (which is 0)


Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define int long long int

signed main() {
  string s;
  int s_center = (s.length() + 1) / 2;
  string mae = s.substr(s_center - 1);
  string usiro = s.substr(s_center + 1, (s.length() / 2));
  if (mae == usiro) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p02730 (C++) — buggy submission, verdict: Runtime Error

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

bool judge(string &s) {
  string s2 = s;
  reverse(s2.begin(), s2.end());
  return s != s2;
}

int main() {
  cin.tie(0), ios::sync_with_stdio(false);
  string s;
  cin >> s;
  bool yes = true;
  int n = s.size(), n2;
  if (judge(s))
    yes = false;
  string s2 = s.substr(0, (n - 1) / 2);
  n2 = s2.size();
  if (yes == true && judge(s2))
    yes = false;
  s2 = s.substr((n + 3) / 2 - 1, n2);
  if (yes == true && judge(s2))
    yes = false;
  if (yes)
    cout << "Yes\\n"s;
  else
    cout << "No\\n"s;
}

Error: 0

Fixed submission:

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

bool judge(string &s) {
  for (int i = 0, j = s.size() - 1; i != j; ++i, --j) {
    if (s.at(i) != s.at(j))
      return true;
  }
  return false;
}

int main() {
  cin.tie(0), ios::sync_with_stdio(false);
  string s;
  cin >> s;
  bool yes = true;
  int n = s.size(), n2;
  if (judge(s))
    yes = false;
  string s2 = s.substr(0, (n - 1) / 2);
  n2 = s2.size();
  if (yes == true && judge(s2))
    yes = false;
  s2 = s.substr((n + 3) / 2 - 1, n2);
  if (yes == true && judge(s2))
    yes = false;
  if (yes)
    cout << "Yes\\n"s;
  else
    cout << "No\\n"s;
}
Problem p02730 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

bool isKaibun(string s) {
  int n = s.length();
  int l = n / 2;
  for (int i = 0; i < l; i++) {
    if (s[i] != s[n - 1 - i]) {
      return false;
    }
  }
  return true;
}

int main() {
  string s;
  cin >> s;
  int n = s.length();
  bool ok = isKaibun(s) && isKaibun(s.substr(0, (n - 1) / 2)) &&
            isKaibun(s.substr((n + 3) / 2 - 1, n));
  if (ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

bool isKaibun(string s) {
  int n = s.length();
  int l = n / 2;
  for (int i = 0; i < l; i++) {
    if (s[i] != s[n - 1 - i]) {
      return false;
    }
  }
  return true;
}

int main() {
  string s;
  cin >> s;
  int n = s.length();
  bool ok = isKaibun(s) && isKaibun(s.substr(0, (n - 1) / 2)) &&
            isKaibun(s.substr((n + 3) / 2 + 1, n));
  if (ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
Problem p02730 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for (int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpii = vector<pll>;

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

  ll N = S.size();
  ll left = 0, right = N - 1;
  while (left < right) {
    if (S[left] != S[right]) {
      cout << "No" << endl;
      return 0;
    }
    left++;
    right--;
  }

  left = 0;
  right = (N - 1) / 2 - 1;

  while (left < right) {
    if (S[left] != S[right]) {
      cout << "No" << endl;
      return 0;
    }
    left++;
    right--;
  }

  left = (N + 3) / 2 - 1;
  right = N - 1;

  while (left < right) {
    if (S[left] != S[right]) {
      cout << "No" << endl;
      return 0;
    }
    left++;
    right--;
  }

  cout << "Yes" << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for (int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpii = vector<pll>;

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

  ll N = S.size();
  ll left = 0, right = N - 1;
  while (left < right) {
    if (S[left] != S[right]) {
      cout << "No" << endl;
      return 0;
    }
  }

  left = 0;
  right = (N - 1) / 2 - 1;

  while (left < right) {
    if (S[left] != S[right]) {
      cout << "No" << endl;
      return 0;
    }
    left++;
    right--;
  }

  left = (N + 3) / 2 - 1;
  right = N - 1;

  while (left < right) {
    if (S[left] != S[right]) {
      cout << "No" << endl;
      return 0;
    }
    left++;
    right--;
  }

  cout << "Yes" << endl;

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

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define FORD(i, a, n) for (int i = (a); i >= (n); i--)
#define REPD(i, n) FOR(i, n, 0)

#define ALL(o) (o).begin(), (o).end()

template <class T> using V = vector<T>;
template <class T, class U> using P = pair<T, U>;
template <class T> using PQ = priority_queue<T>;
template <class T> using PQR = priority_queue<T, vector<T>, greater<T>>;

const ll MOD = 1000000007;

bool f(string s) {
  string ss = s;
  reverse(ALL(ss));
  if (s == ss) {
    return true;
  }
  return false;
}

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

  int n = s.size();
  if (f(s) && f(s.substr(0, n / 2)) &&
      f(s.substr((n + 3) / 2 - 1, n - (n + 3) / 2 + 1))) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define FORD(i, a, n) for (int i = (a); i >= (n); i--)
#define REPD(i, n) FOR(i, n, 0)

#define ALL(o) (o).begin(), (o).end()

template <class T> using V = vector<T>;
template <class T, class U> using P = pair<T, U>;
template <class T> using PQ = priority_queue<T>;
template <class T> using PQR = priority_queue<T, vector<T>, greater<T>>;

const ll MOD = 1000000007;

bool f(string s) {
  string ss = s;
  reverse(ALL(ss));
  if (s == ss) {
    return true;
  }
  return false;
}

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

  int n = s.size();
  if (f(s) && f(s.substr(0, n / 2)) &&
      f(s.substr((n + 3) / 2 + 1, (n - (n + 3) / 2 + 1)))) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

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

#include <iostream>
using namespace std;

bool is_palindrome(string s) {
  string t(s.rbegin(), s.rend());
  return s == t;
}

int main() {
  string s;
  cin >> s;
  int n = s.size();
  if (is_palindrome(s) && is_palindrome(s.substr(0, (n - 1) / 2)) &&
      is_palindrome(s.substr((n + 1) / 2))) {
    cout << "Yes" << endl;
  } else
    cout << "No" << endl;
}


Error: 0

Fixed submission:

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

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

  // 条件1判定
  int check1 = 0;
  string R = S;
  reverse(R.begin(), R.end());

  for (int i = 0; i < S.length(); i++) {
    if (S.at(i) != R.at(i)) {
      check1 = 0;
      break;
    }

    if (i == (S.length() - 1)) {
      check1 = 1;
    }
  }

  // 条件2
  int check2 = 0;
  int N = S.length();
  string T;

  for (int i = 0; i < (N - 1) / 2; i++) {
    T += S.at(i);
  }
  string U = T;
  reverse(U.begin(), U.end());

  if (U == T) {
    check2 = 1;
  }

  // 条件2
  int check3 = 0;
  string P;

  for (int i = ((N + 3) / 2) - 1; i < N; i++) {
    P += S.at(i);
  }

  string Q = P;
  reverse(Q.begin(), P.end());

  if (P == Q) {
    check3 = 1;
  }

  if ((check1 == 1) && (check2 == 1) && (check3 == 1)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p02730 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  string str;
  cin >> str;
  ll N = str.size(), count = 0;
  for (ll i = 0; i < N; i++) {
    if (str.at(i) == str.at(N - i - 1)) {
      count++;
    }
  }
  for (ll i = 0; i < (N - 1) / 2; i++) {
    if (str.at(i) == str.at((N - 1) / 2 - i - 1)) {
      count++;
    }
  }
  for (ll i = 0; i < (N - 1) / 2; i++) {
    if (str.at(N - i - 1) == str.at((N + 3) / 2 + i - 1)) {
      count++;
    }
  }
  if (count == 2 * N - 1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::at: __n (which is 7) >= this->size() (which is 7)


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  string str;
  cin >> str;
  ll N = str.size(), count = 0;
  for (ll i = 0; i < (N - 1) / 2; i++) {
    if (str.at(i) == str.at((N - 1) / 2 - i - 1)) {
      count++;
    }
  }
  for (ll i = 0; i < (N - 1) / 2; i++) {
    if (str.at(N - i) == str.at((N + 3) / 2 + i)) {
      count++;
    }
  }
  if (count == N - 1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p02730 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int main(void) {
  string str;
  // string bstr, astr;
  int j = 0;
  int flag = 1;
  cin >> str;
  int len = str.size();
  vector<string> bstr(len / 2);
  vector<string> astr(len / 2);

  for (int i = 0; i < (len / 2); i++) {

    bstr.at(i) = str.at(i);
    astr.at(i) = str.at((len + 1) / 2 + i);
  }

  for (int i = 0; i < bstr.size(); i++) {
    if (bstr.at(i) != astr.at(i)) {
      // cout << "No" << endl;
      flag = 0;
    }
    if (i < (bstr.size() / 2)) {
      if (!((bstr.at(i) == bstr.at(bstr.size() - 1 - i)) &&
            (astr.at(i) == astr.at(astr.size() - 1 - i)))) {
        // cout << "No" << endl;
        flag = 0;
      }
    }
  }

  if (flag == 1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main(void) {
  string str;
  // string bstr, astr;
  int j = 0;
  cin >> str;
  int len = str.size();
  vector<string> bstr(len / 2);
  vector<string> astr(len / 2);

  // for(int i = 0; i < ((str.size() - 1) / 2); i++){
  //     if(str.at(i) != str.at(str.size() - 1 -i)){
  //         cout << "No" << endl;
  //         return 1;
  //     }

  // }

  // cout << len << endl;
  for (int i = 0; i < (len / 2); i++) {
    // cout << "i == " << i << endl;
    bstr.at(i) = str.at(i);
    astr.at(i) = str.at((len + 1) / 2 + i);
  }
  // cout << bstr.size() << endl;
  // cout << astr.size() << endl;

  for (int i = 0; i < bstr.size(); i++) {
    if (bstr.at(i) != astr.at(i)) {
      cout << "No" << endl;
      return 1;
    }
    if (i < (bstr.size() / 2)) {
      // cout << "i =" << i << endl;
      if (!((bstr.at(i) == bstr.at(bstr.size() - 1 - i)) &&
            (astr.at(i) == astr.at(astr.size() - 1 - i)))) {
        // cout << i << endl;
        // cout << bstr.size() - 1 << endl;
        // cout << bstr.at(i) << bstr.at(bstr.size() / 2 - 1) << endl;
        // cout << astr.at(i) << astr.at(astr.size() / 2 - 1) << endl;
        cout << "No" << endl;
        return 1;
      }
    }
  }

  // for(int i = ((str.size() + 1) / 2); i <= ((str.size() + 1) / 2) +
  // ((str.size() / 4) - 1); i++){

  //     if(str.at(i) != str.at(str.size() - 1 - j)){

  //         cout << "No" << endl;
  //         return 1;
  //     }
  //     j = j + 1;
  // }

  cout << "Yes" << endl;
  return 0;
}
Problem p02730 (C++) — buggy submission, verdict: Runtime Error

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

bool kaibun(string S, int A, int B) {
  // Sの文字数は3以上の奇数
  // SのA文字目からB文字目までが回文かどうかを判定する関数
  int i = A - 1;
  int j = B - 1;
  while (i <= j) {
    if (S.at(i) != S.at(j))
      return false;
    i += 1;
    j += -1;
  }
  return true;
}

int main() {
  string S;
  cin >> S;
  int N = S.size();
  if (kaibun(S, 1, N) && kaibun(S, 1, (N - 1) / 2) && kaibun(S, (N + 3) / 2, N))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Error: 0

Fixed submission:

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

bool kaibun(string S, int A, int B) {
  // Sの文字数は3以上の奇数
  // SのA文字目からB文字目までが回文かどうかを判定する関数
  int i = A - 1;
  int j = B - 1;
  while (i != j) {
    if (S.at(i) != S.at(j))
      return false;
    i += 1;
    j += -1;
  }
  return true;
}

int main() {
  string S;
  cin >> S;
  int N = S.size();
  if (kaibun(S, 1, N) && kaibun(S, 1, (N - 1) / 2) && kaibun(S, (N + 3) / 2, N))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p02730 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int main(void) {
  string str;
  // string bstr, astr;
  int j = 0;
  int flag = 1;
  cin >> str;
  int len = str.size();
  vector<string> bstr(len / 2);
  vector<string> astr(len / 2);

  for (int i = 0; i < (len / 2); i++) {

    bstr.at(i) = str.at(i);
    astr.at(i) = str.at((len + 1) / 2 + i);
  }

  for (int i = 0; i < bstr.size(); i++) {
    if (bstr.at(i) != astr.at(i)) {
      // cout << "No" << endl;
      flag = 0;
    }
    if (i < (bstr.size() / 2)) {
      if (!((bstr.at(i) == bstr.at(bstr.size() - 1 - i)) &&
            (astr.at(i) == astr.at(astr.size() - 1 - i)))) {
        // cout << "No" << endl;
        flag = 0;
      }
    }
  }

  if (flag == 1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main(void) {
  string str;
  int flag = 1;
  int j = 0;
  cin >> str;
  // cout << str.size() << endl;
  for (int i = 0; i < ((str.size() - 1) / 2); i++) {
    if (str.at(i) != str.at(str.size() - 1 - i)) {
      flag = 0;
    }
  }
  // cout << "YES1" << endl;
  // cout << (str.size() / 4) - 1 << endl;
  // cout << str.at(str.size() - 1) << endl;
  // cout << str.at((str.size() - 1) ) << endl;

  for (int i = 0; i <= (str.size() / 4) - 1; i++) {
    if (str.at(i) != str.at(((str.size() - 1) / 2) - 1 - i)) {
      // cout << str.at(i) << " " << str.at((str.size() - 1) / 2) - 1 - i <<
      // endl;
      flag = 0;
    }
  }
  // cout << "YES2" << endl;
  for (int i = ((str.size() + 1) / 2);
       i <= ((str.size() + 1) / 2) + ((str.size() / 4) - 1); i++) {

    if (str.at(i) != str.at(str.size() - 1 - j)) {
      // cout << i << endl;
      // cout << str.at(i) << " " << str.at(str.size() - 1 - j) << endl;
      flag = 0;
    }
    j = j + 1;
  }

  if (flag == 1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}
Problem p02730 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int main() {
  string s;
  cin >> s;
  int length = s.length();
  int flag = 1;
  for (int i = 0; i < length / 2; i++) {
    if (s[i] != s[length - 1 - i]) {
      flag = 0;
    }
  }
  int a = (length - 1) / 2;
  for (int i = 0; i < a - 1; ++i) {
    if (s[i] != s[a - 1 - i]) {
      flag = 0;
    }
  }
  int b = (length + 3) / 2;
  for (int i = b - 1; i < length - 1; i++) {
    if (s[i] != s[length - 1 - i]) {
      flag = 0;
    }
  }
  if (flag) {
    cout << "Yes\\n";
  } else {
    cout << "No\\n";
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  string s;
  cin >> s;
  int length = s.length();
  for (int i = 0; i < length; i++) {
    if (s[i] != s[length - 1 - i]) {
      cout << "No\\n";
      exit(1);
    }
  }
  int a = (length - 1) / 2;
  for (int i = 0; i < a; ++i) {
    if (s[i] != s[a - 1 - i]) {
      cout << "No\\n";
      exit(1);
    }
  }
  int b = (length + 3) / 2;
  for (int i = b - 1; i < length; i++) {
    if (s[i] != s[length - 1 - i]) {
      cout << "No\\n";
      exit(1);
    }
  }
  cout << "Yes\\n";
}
Problem p02730 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  string S;
  cin >> S;
  bool b = true;
  int n = S.size();
  for (int i = 0; i <= n / 2; i++) {
    if (S.at(i) != S.at(n - 1 - i)) {
      b = false;
      break;
    }
  }
  for (int i = 0; i < (n - 1) / 2; i++) {
    if (S.at(i) != S.at((n - 2) / 2 - i)) {
      b = false;
      break;
    }
  }
  for (int i = n - 1; i < n - ((n + 3) / 2); i--) {
    if (S.at(i) != S.at(i - (n + 3) / 2)) {
      b = false;
      break;
    }
  }
  if (b)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Error: 0

Fixed submission:

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

int main() {
  string S;
  cin >> S;
  bool b = true;
  int n = S.size();
  for (int i = 0; i <= n / 2; i++) {
    if (S.at(i) != S.at(n - 1 - i)) {
      b = false;
      break;
    }
  }
  for (int i = 0; i < (n - 1) / 4; i++) {
    if (S.at(i) != S.at((n - 2) / 2 - i)) {
      b = false;
      break;
    }
  }
  for (int i = n - 1; i < (n + 3) / 2; i--) {
    if (S.at(i) != S.at(i - (n + 3) / 2)) {
      b = false;
      break;
    }
  }
  if (b)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p02730 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

bool is(string s, int len) {

  bool y = true;
  for (int i = 0; i < len / 2; i++) {

    if (s[i] != s[len - 1 - i]) {
      y = false;
      break;
    }
  }

  return y;
}

int main() {
  string s;
  while (cin >> s) {
    int n = s.length();
    if (is(s, n) && is(s.substr(0, n / 2), n / 2) &&
        is(s.substr((n + 1) / 2), n / 2))
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }

  return 0;
}


Error: 0

Fixed submission:

#include <iostream>

using namespace std;

bool is(string s, int len) {

  bool y = true;
  for (int i = 0; i < len / 2; i++) {
    //		cout << s[i] << " : " << s[len-1-i] << endl;
    if (s[i] != s[len - 1 - i]) {
      y = false;
      break;
    }
  }

  if (len / 2 > 1) {
    //		cout << "come\\n";
    string s1 = s.substr(0, len / 2);
    string s2 = s.substr(len / 2 + 1, len / 2);
    //		cout << "S1=" << s1 << endl;
    //		cout << "S2=" << s2 << endl;
    y = is(s1, len / 2);

    y = is(s2, len / 2);
  }
  return y;
}

int main() {
  string s;
  while (cin >> s) {
    if (is(s, s.length()))
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }

  return 0;
}