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

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

#define FOR(i, a, b) for (ll i = a; (i) < (b); ++(i))
#define RFOR(i, a, b) for (ll i = a; (i) >= (b); --(i))
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define UNIQ(v)                                                                \\
  sort(ALL(v));                                                                \\
  v.erase(unique(ALL(v)), v.end())
#define BIT(n) (1LL << (n))
#define DEBUG(a) cerr << #a << " = " << a << endl

const int inf = 1001001001;
const int mod = (int)1e9 + 7;
// const ll inf = 1e15;
// const ll mod = 1e9+7;

int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};

int main() {
  string s;
  cin >> s;
  string rs = s;
  int l = s.size();
  reverse(ALL(rs));

  string kai = s.substr(0, (l - 1) / 2);
  while (kai.size() > 1) {
    if (kai.back() != kai.front()) {
      cout << "No" << endl;
      return 0;
    }
    kai.pop_back();
    kai.erase(0, 1);
  }

  if (s.substr(0, (l - 1) / 2) == rs.substr(0, (l - 1) / 2)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Error: 0

Fixed submission:

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

#define FOR(i, a, b) for (ll i = a; (i) < (b); ++(i))
#define RFOR(i, a, b) for (ll i = a; (i) >= (b); --(i))
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define UNIQ(v)                                                                \\
  sort(ALL(v));                                                                \\
  v.erase(unique(ALL(v)), v.end())
#define BIT(n) (1LL << (n))
#define DEBUG(a) cerr << #a << " = " << a << endl

const int inf = 1001001001;
const int mod = (int)1e9 + 7;
// const ll inf = 1e15;
// const ll mod = 1e9+7;

int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};

int main() {
  string s;
  cin >> s;
  string rs = s;
  int l = s.size();
  reverse(ALL(rs));

  string kai = s.substr(0, (l - 1) / 2);
  while (kai.size() != 1) {
    if (kai.back() != kai.front()) {
      cout << "No" << endl;
      return 0;
    }
    kai.pop_back();
    kai.erase(0, 1);
  }

  if (s.substr(0, (l - 1) / 2) == rs.substr(0, (l - 1) / 2)) {
    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 S, word1, word2;
  int L, j, k, l;

  bool yesno;
  yesno = true;
  cin >> S;
  L = S.size();
  j = L;

  for (int i = 0; i < L / 2; i++) {
    word1 = S.at(i);
    word2 = S.at(j - 1);
    if (word1 == word2) {
      j--;
    } else {
      yesno = false;
      break;
    }
  }

  j = (L - 1) / 2;
  k = j;
  for (int i = 0; i < k / 2; i++) {
    word1 = S.at(i);
    word2 = S.at(j - 1);
    if (word1 == word2) {
      j--;
    } else {
      yesno = false;
      break;
    }
  }

  j = (L + 3) / 2;
  k = j;
  l = L;
  for (int i = 0; i < (L - k) / 2; i++) {
    word1 = S.at(l - 1);
    word2 = S.at(j - 1);
    if (word1 == word2) {
      j++;
      l--;
    } else {
      yesno = false;
      break;
    }
  }

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


Error: 0

Fixed submission:

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

int main() {

  string str, gudge;
  int s, s2, s3, s4, s5, s6;

  cin >> str;
  s = str.size();
  s2 = (s - 1) / 2;
  s3 = s - 1;
  s4 = s2 - 1;
  s5 = (s + 3) / 2;
  s6 = (s - s5) / 2 - 1;
  gudge = "Yes";

  for (int i = 0; i < s2; i++) {
    if (str.at(i) == str.at(s3)) {
      s3 = s3 - 1;
    } else {
      gudge = "No";
      break;
    }
  }

  for (int i = 0; i < s2; i++) {
    if (str.at(i) == str.at(s4)) {
      s4 = s4 - 1;
    } else {
      gudge = "No";
      break;
    }
  }

  for (int i = 0; i < s6; i++) {
    if (str.at(s) == str.at(s5)) {
      s5 = s5 + 1;
    } else {
      gudge = "No";
      break;
    }
  }

  cout << gudge << endl;
}
Problem p02730 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define MOD_1_000_000_007 (1000000007LL)
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i, n) for (long long i = 1; i < (long long)(n); i++)
#define rep2(i, n) for (long long i = 2; i < (long long)(n); i++)
#define rep0c(i, n) for (long long i = 0; i <= (long long)(n); i++)
#define rep1c(i, n) for (long long i = 1; i <= (long long)(n); i++)
#define rep2c(i, n) for (long long i = 2; i <= (long long)(n); i++)
#define repc0(n, i) for (long long i = (long long)(n); i >= 0; i--)
#define repc1(n, i) for (long long i = (long long)(n); i >= 1; i--)
#define repc2(n, i) for (long long i = (long long)(n); i >= 2; i--)

namespace solver {
using namespace std;
typedef long long ll;

string S;

void init() { cin >> S; }

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

void solve() {
  int n = S.size();
  int nn = (n - 1) / 2;
  if (is_palindrome(S) && is_palindrome(S.substr(0, nn)) &&
      is_palindrome(S.substr((n + 1) / 2, nn)))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
} // namespace solver

int main() {
  solver::init();
  solver::solve();
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define MOD_1_000_000_007 (1000000007LL)
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i, n) for (long long i = 1; i < (long long)(n); i++)
#define rep2(i, n) for (long long i = 2; i < (long long)(n); i++)
#define rep0c(i, n) for (long long i = 0; i <= (long long)(n); i++)
#define rep1c(i, n) for (long long i = 1; i <= (long long)(n); i++)
#define rep2c(i, n) for (long long i = 2; i <= (long long)(n); i++)
#define repc0(n, i) for (long long i = (long long)(n); i >= 0; i--)
#define repc1(n, i) for (long long i = (long long)(n); i >= 1; i--)
#define repc2(n, i) for (long long i = (long long)(n); i >= 2; i--)

namespace solver {
using namespace std;
typedef long long ll;

string S;

void init() { cin >> S; }

bool rec(string s) {
  if (s.size() == 1)
    return true;
  int n = s.size();
  int nn = (n - 1) / 2;
  return s.substr(0, nn) == s.substr((n + 1) / 2, nn) && rec(s.substr(0, nn));
}

void solve() {
  if (rec(S))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
} // namespace solver

int main() {
  solver::init();
  solver::solve();
  return 0;
}
Problem p02730 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int a, b, c;
  string S;
  cin >> S;
  b = (S.size() + 1) / 2;
  a = (S.size() - 1) / 2 - 1;
  c = b / 2;
  for (int i = 0; i < c; i++) {
    if (S.at(i) != S.at(a - i)) {
      cout << "No" << endl;
      break;
    } else if (S.at(S.size() - i - 1) != S.at(b + i)) {
      cout << "No" << endl;
      break;
    } else if (S.at(i * 2) != S.at(S.size() - (i * 2) - 1)) {
      cout << "No" << endl;
      break;
    } else if (S.at(i * 2 + 1) != S.at(S.size() - (i * 2) - 2)) {
      cout << "No" << endl;
      break;
    } else if (i < c - 1) {
      continue;
    }
    cout << "Yes" << endl;
  }
}


Error: 0

Fixed submission:

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

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

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

#define lli long long int
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define INF 1000000007
#define endl "\\n"

lli n, m;
string a, a2, a3;

int main() {
  cin >> a;
  for (int i = 0; i < a.size(); i++) {
    if (a[i] != a[a.size() - i - 1]) {
      cout << "No";
      return 0;
    }
  }
  for (int i = 0; i < (a.size() - 1) / 2; i++) {
    a2.pb(a[i]);
  }
  for (int i = (a.size() + 3) / 2 - 1; i < a.size(); i++) {
    a3.pb(a[i]);
  }
  for (int i = 0; i < a2.size(); i++) {
    if (a2[i] != a2[a2.size() - i - 1]) {
      cout << "No";
      return 0;
    }
  }
  for (int i = 0; i < a3.size(); i++) {
    if (a3[i] != a3[a3.size() - i - 1]) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
}

Error: -11

Fixed submission:

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

#define lli long long int
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define INF 1000000007
#define endl "\\n"

lli n, m;
string a, a2, a3;

int main() {
#ifndef ONLINE_JUDGE
  freopen("zgir.gir", "r", stdin);
  freopen("zcik.cik", "w", stdout);
#endif
  cin >> a;
  for (int i = 0; i < a.size(); i++) {
    if (a[i] != a[a.size() - i - 1]) {
      cout << "No";
      return 0;
    }
  }
  for (int i = 0; i < (a.size() - 1) / 2; i++) {
    a2.pb(a[i]);
  }
  for (int i = (a.size() + 3) / 2 - 1; i < a.size(); i++) {
    a3.pb(a[i]);
  }
  for (int i = 0; i < a2.size(); i++) {
    if (a2[i] != a2[a2.size() - i - 1]) {
      cout << "No";
      return 0;
    }
  }
  for (int i = 0; i < a3.size(); i++) {
    if (a3[i] != a3[a3.size() - i - 1]) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
}
Problem p02730 (C++) — buggy submission, verdict: Runtime Error

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

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

  int a, b, c, d, N;
  N = S.size();
  a = 0;
  b = (N - 3) / 2;
  c = (N + 1) / 2;
  d = N - 1;

  int result = 1;

  for (int i = 0; i < (N - 1) / 2; i++) {
    if (S.at(a + i) == S.at(d - i)) {
    } else {
      result = 0;
      break;
    }
  }
  for (int i = 0; i < (N - 1) / 4; i++) {
    if (S.at(a + i) == S.at(b - i)) {
    } else {
      result = 0;
      break;
    }
  }
  for (int i = 0; i < (N - 1) / 4; i++) {
    if (S.at(c + i) == S.at(d - i)) {
    } else {
      result = 0;
      break;
    }
  }

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

Error: 0

Fixed submission:

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

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

  int a, b, c, d, N;
  N = S.size();
  a = 0;
  b = (N - 3) / 2;
  c = (N + 1) / 2;
  d = N - 1;

  int result = 1;

  if (N == 3) {
    if (S.at(0) != S.at(2)) {
      result = 0;
    }
  }

  for (int i = 0; i < (N - 1) / 4; i++) {
    if (!(S.at(a + i) == S.at(b - i) && S.at(b - i) == S.at(c + i) &&
          S.at(c + i) == S.at(d - i))) {
      result = 0;
      break;
    }
  }

  if ((N + 1) % 4 == 0) {
    a = (N + 1) / 4;
    b = (3 * (N + 1)) / 4;
    if (S.at(a) != S.at(b)) {
      result = 0;
    }
  }

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

#include <iostream>
using namespace std;
int main() {
  string s;
  cin >> s;
  int first = 0;
  int last = s.length() - 1;
  bool palindrome = true;
  while (first <= last) {
    if (s[first++] != s[last--]) {
      palindrome = false;
      break;
    }
  }
  first = 0;
  last = (s.length() - 3) / 2;
  while (first <= last) {
    if (s[first++] != s[last--]) {
      palindrome = false;
      break;
    }
  }
  first = (s.length() + 1) / 2;
  last = s.length() - 1;
  while (first <= last) {
    if (s[first++] != s[last--]) {
      palindrome = false;
      break;
    }
  }
  if (palindrome) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  string s;
  cin >> s;
  int first = 0;
  int last = s.length() - 1;
  bool palindrome = true;
  while (first <= last) {
    if (s[first++] != s[last++]) {
      palindrome = false;
      break;
    }
  }
  first = 0;
  last = (s.length() - 1) / 2;
  while (first <= last) {
    if (s[first++] != s[last++]) {
      palindrome = false;
      break;
    }
  }
  first = (s.length() + 3) / 2;
  last = s.length() - 1;
  while (first <= last) {
    if (s[first++] != s[last++]) {
      palindrome = false;
      break;
    }
  }
  if (palindrome) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}
Problem p02730 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define fastio() ios_base::sync_with_stdio(false)
#define rmod(x, y) ((((x) % (y)) + (y)) % (y))
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
template <typename T, typename R = null_type, typename C = less<T>>
tree<T, R, C, rb_tree_tag, tree_order_statistics_node_update> ordered_set() {
  return tree<T, R, C, rb_tree_tag, tree_order_statistics_node_update>();
}

int main() {
  string s;
  cin >> s;
  int n = s.size();
  string s1 = s.substr(0, ((n - 1) / 2));
  string s2 = s.substr((n + 3) / 2 - 1);
  string rs1 = s1;
  reverse(rs1.begin(), rs1.end());
  string rs2 = s2;
  reverse(rs2.begin(), rs2.end());
  string rs = s;
  reverse(s.begin(), s.end());
  if (s == rs && s1 == rs1 && s2 == rs2)
    puts("Yes");
  else
    puts("No");

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define fastio() ios_base::sync_with_stdio(false)
#define rmod(x, y) ((((x) % (y)) + (y)) % (y))
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
template <typename T, typename R = null_type, typename C = less<T>>
tree<T, R, C, rb_tree_tag, tree_order_statistics_node_update> ordered_set() {
  return tree<T, R, C, rb_tree_tag, tree_order_statistics_node_update>();
}

int main() {
  string s;
  cin >> s;
  int n = s.size();
  string s1 = s.substr(0, ((n - 1) / 2));
  string s2 = s.substr((n + 3) / 2 + 1);
  string rs1 = s1;
  reverse(rs1.begin(), rs1.end());
  string rs2 = s2;
  reverse(rs2.begin(), rs2.end());
  string rs = s;
  reverse(s.begin(), s.end());
  if (s == rs && s1 == rs1 && s2 == rs2)
    puts("Yes");
  else
    puts("No");

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

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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  string t;
  bool flag = true;
  bool ans = true;
  for (int i = 0; i < n / 2; i++) {
    if (s.at(i) == s.at(n - i - 1)) {
      t += s.at(i);
    } else {
      flag = false;
      break;
    }
  }

  if (flag) {
    int x = t.size();

    if (x == 1) {
      cout << "Yes" << endl;
      return 0;
    }

    for (int i = 0; i < x / 2; i++) {
      if (t.at(i) != t.at(x - i - 1)) {
        ans = false;
      }
    }
  } else {
    cout << "No" << endl;
    return 0;
  }

  if (ans) {
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;
}


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


Fixed submission:

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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  string t;
  bool flag = true;
  bool ans = true;
  for (int i = 0; i < (n / 2 - 0.0000001); i++) {
    if (s.at(i) == s.at(n - i - 1)) {
      t += s.at(i);
    } else {
      flag = false;
      break;
    }
  }

  if (flag) {
    int x = t.size();
    if (x == 1) {
      cout << "Yes" << endl;
      return 0;
    }
    if (x == 2) {
      if (t.at(0) == t.at(1))
        cout << "Yes" << endl;
      else
        cout << "No" << endl;
      return 0;
    }

    for (int i = 0; i < (x / 2 - 0.000001); i++) {
      if (t.at(i) != t.at(n - i - 1)) {
        ans = false;
      }
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define ld long double
#define pii pair<int, int>
#define fi first
#define se second
#define mex 1000005
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define int long long
bool palin(string s) {
  int n = s.size();
  int q = 0;
  for (int i = 0; i < n / 2; i++) {
    if (s[i] != s[n - i - 1])
      q = 1;
  }
  if (q == 0)
    return true;
  return false;
}

signed main() {
  fast string s;
  cin >> s;
  string s1 = s;
  int n = s.size();
  // reverse(s1.begin(),s1.end());
  if (palin(s)) {
    s1 = s.substr(0, (n - 1) / 2);
    if (palin(s1)) {
      s1 = s.substr((n + 3) / 2 - 1, n - ((n + 3) / 2) + 1);
      if (palin(s1))
        cout << "Yes";
      else
        cout << "No";
    } else
      cout << "No";
  } else
    cout << "No";
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define ld long double
#define pii pair<int, int>
#define fi first
#define se second
#define mex 1000005
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define int long long

signed main() {
  fast string s;
  cin >> s;
  string s1 = s;
  int n = s.size();
  reverse(s1.begin(), s1.end());
  if (s1.compare(s) == 0) {
    s1 = s.substr(0, (n - 1) / 2);
    string s2 = s1;
    reverse(s2.begin(), s2.end());
    if (s2.compare(s1) == 0) {
      s1 = s.substr((n + 3) / 2 + 1);
      // cout<<s1<<endl;
      s2 = s1;
      reverse(s2.begin(), s2.end());
      if (s2.compare(s1) == 0)
        cout << "Yes";
      else
        cout << "No";
    } else
      cout << "No";
  } else
    cout << "No";
}
Problem p02730 (C++) — buggy submission, verdict: Runtime Error

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

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

Error: WA

Fixed submission:

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

int main() {
  string s;
  cin >> s;
  bool e = true;
  int a = s.size();
  for (int i = 0; i < (a / 2); i++) {
    if (s.at(i) != s.at(a - 1 - i)) {
      e = false;
      break;
    }
  }
  int b = (a - 1) / 2;
  for (int i = 0; i < (b / 2); i++) {
    if (s.at(i) != s.at(b - i)) {
      e = false;
      break;
    }
  }
  int c = (a + 3) / 2;
  for (int i = 0; i < ((a - 1 - c) / 2); i++) {
    if (s.at(c + i) != s.at(a - i)) {
      e = false;
      break;
    }
  }
  if (e == true)
    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 S;
  int N;
  int M = 0;
  cin >> S;
  N = S.size();
  for (int i = 0; i < (N - 1) / 2; i++) {
    if (S.at(i) != S.at((N - 1) / 2 + 1 + i)) {
      M = 1;
    }
  }
  if (M == 1) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << 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 S;
  int N;
  int M = 0;
  cin >> S;
  N = S.size();
  for (int i = 0; i < (N - 1) / 2; i++) {
    if (S.at(i) != S.at((N + 3) / 2 + i)) {
      M = 1;
    }
  }
  if (M == 1) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << 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(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
string rev(string x) {
  reverse(all(x));
  return x;
}
int main() {
  string s;
  cin >> s;
  int count = 0;
  int n = s.size();
  int a = (n - 1) / 2;
  int b = (n + 1) / 2;
  string srev = rev(s);
  if (s == srev) {
    count++;
  }
  string s1 = s.substr(0, a);
  string srev1 = rev(s1);
  if (s1 == srev1) {
    count++;
  }
  string s2 = s.substr(b);
  string srev2 = rev(s2);
  if (s2 == srev2) {
    count++;
  }
  if (count == 3)
    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 1) > this->size() (which is 0)


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
int main() {
  string s;
  int count = 0;
  reverse(all(s));
  string srev = s;
  reverse(all(s));
  if (s == srev)
    count++;
  int n = s.size();
  int a = (n - 1) / 2;
  int b = (n + 3) / 2;
  string str1 = s.substr(0, a);
  reverse(all(str1));
  string str11 = str1;
  reverse(all(str1));
  if (str1 == str11)
    count++;
  string str2 = s.substr(b, n - b + 1);
  reverse(all(str2));
  string str22 = str2;
  reverse(all(str2));
  if (str2 == str22)
    count++;

  if (count == 3)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p02730 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;

bool kaibun(string s) {
  string r = s;
  reverse(r.begin(), r.end());
  return s == r;
}

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

  string ans = "No";
  if (kaibun(s) and kaibun(s.substr(0, (n - 1) / 2)) and
      kaibun(s.substr(((n + 3) / 2) - 1, n)))
    ans = "Yes";
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;

bool kaibun(string s) {
  int n = s.size();
  string l = s.substr(0, n / 2);
  string r = s.substr((n / 2) + 1, n);
  if (n % 2 == 1) {
    string l = s.substr(0, (n - 1) / 2);
    string r = s.substr((n + 3) / 2, n);
  }
  return l == r;
}

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

  string ans = "No";
  if (kaibun(s) and kaibun(s.substr(0, (n - 1) / 2)) and
      kaibun(s.substr((n / 2) + 1, n)))
    ans = "Yes";
  cout << ans << endl;
  return 0;
}