Problem p02730 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
// setbase - cout << setbase (16); cout << 100 << endl; Prints 64
// setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints
// xxx77 setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
// cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
using namespace std;
using namespace __gnu_pbds;

#define sp << " " <<
#define mod 1000000007
#define PI 3.14159265358979323
#define y second
#define x first
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define pqueue priority_queue<ll>
// #define pdqueue priority_queue< ll,vector<ll> ,greater< ll > >
#define codejamDebug(x) cout << "Case #" << x << ": ";
#define debug(x) cout << #x << " :" << x << endl;
#define rep(i, n) for (long long i = 0; i < n; i++)
#define f(i, a, b) for (long long i = a; i < b; i++)
#define fd(i, a, b) for (long long i = a; i >= b; i--)
#define sync                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<string> vs;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
  string s;
  cin >> s;
  int n = s.size();
  if (n % 2 == 0) {
    cout << "No";
    return 0;
  }
  bool ok = true;
  for (int i = 0; i < n / 2; i++) {
    if (s[i] != s[n - 1 - i]) {
      ok = false;
      break;
    }
  }
  if (!ok) {
    cout << "No";
    return 0;
  }
  string s1 = s.substr(0, n / 2);
  string s2 = s.substr((n + 1) / 2, n / 2);
  n = n / 2;
  for (int i = 0; i < n / 2; i++) {
    if (s1[i] != s1[n - 1 - i]) {
      ok = false;
      break;
    }
  }
  for (int i = 0; i < n / 2; i++) {
    if (s2[i] != s2[n - 1 - i]) {
      ok = false;
      break;
    }
  }
  if (!ok) {
    cout << "No";
    return 0;
  }
  cout << "Yes";
}

Error: WA

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
// setbase - cout << setbase (16); cout << 100 << endl; Prints 64
// setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints
// xxx77 setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
// cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
using namespace std;
using namespace __gnu_pbds;

#define sp << " " <<
#define mod 1000000007
#define PI 3.14159265358979323
#define y second
#define x first
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define pqueue priority_queue<ll>
// #define pdqueue priority_queue< ll,vector<ll> ,greater< ll > >
#define codejamDebug(x) cout << "Case #" << x << ": ";
#define debug(x) cout << #x << " :" << x << endl;
#define rep(i, n) for (long long i = 0; i < n; i++)
#define f(i, a, b) for (long long i = a; i < b; i++)
#define fd(i, a, b) for (long long i = a; i >= b; i--)
#define sync                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<string> vs;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// Handle:cyber_rajat

int main() {
  string s;
  cin >> s;
  int n = s.size();
  if (n % 2 == 0) {
    cout << "No";
    return 1;
  }
  bool ok = true;
  for (int i = 0; i < n / 2; i++) {
    if (s[i] != s[n - 1 - i]) {
      ok = false;
      break;
    }
  }
  if (!ok) {
    cout << "No";
    return 1;
  }

  for (int i = 0; i < n / 4; i++) {
    if (s[i] != s[n / 2 - 1 - i]) {
      ok = false;
      break;
    }
  }

  for (int i = (n + 1) / 2, j = 0; i < n; i++, j++) {
    if (s[i] != s[n - 1 - j]) {
      ok = false;
      break;
    }
  }
  if (!ok) {
    cout << "No";
    return 1;
  }
  cout << "Yes";
}