Problem p02730 (C++)

Buggy submission (status: Runtime Error):
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
//* vamsicool007    You are never wrong to do the right thing    vamsicool007 *
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
#include <bits/stdc++.h>
using namespace std;
#define flash                                                                  \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl "\n"
#define int long long
typedef long long ll;
typedef long double ld;
const int mod = 1000000007;
const int N = 200005;
vector<int> vis(N);
vector<vector<int>> adj(N);
void dfs(int v) {
  vis[v] = 1;
  for (auto i : adj[v]) {
    if (!vis[i]) {
      dfs(i);
    }
  }
  return;
}
bool isPrime(ll n) {
  if (n < 2)
    return false;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
ll factorial(ll n) { return (n == 1 || n == 0) ? 1 : n * factorial(n - 1); }
ll power(ll x, ll y) {
  ll res = 1;
  x = x;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % mod;
    y = y >> 1;
    x = (x * x) % mod;
  }
  return res % mod;
}
ll gcd(ll a, ll b) {
  if (a == 0)
    return b;
  return gcd(b % a, a);
}
ll lcm(ll a, ll b) { return (a / gcd(a, b) * b); }
ll max(ll a, ll b) {
  ll ans = a > b ? a : b;
  return ans;
}
ll min(ll a, ll b) {
  ll ans = a < b ? a : b;
  return ans;
}
int root(int a[], int i) {
  while (a[i] != i) {
    a[i] = a[a[i]];
    i = a[i];
  }
  return i;
}
void unionn(int a[], int i, int j) {
  int root_i = root(a, i);
  int root_j = root(a, j);
  a[root_i] = root_j;
  return;
}
void fun() {
#ifndef ONLINE_JUDGE
  freopen("infile.txt", "r", stdin);
  freopen("oufile.txt", "w", stdout);
#endif
}

signed main() {
  flash;
  fun();
  int t = 1;
  // cin>>t;
  while (t--) {
    string s;
    cin >> s;
    int n = s.size();
    int f = 0;
    for (int i = 0; i < n / 2; i++) {
      if (s[i] != s[n - i - 1]) {
        f = 1;
        break;
      }
    }
    if (!f) {
      int m = (n - 1) / 2;
      int f1 = 0;
      for (int i = 0; i < (n - 1) / 4; i++) {
        if (s[i] != s[m - 1 - i]) {
          f1 = 1;
          break;
        }
      }
      int j = (n + 3) / 2;
      int k = (2 * n + 3) / 4;
      int f2 = 0;
      for (int i = j; i < k; i++) {
        if (s[i] != s[k - i - 1]) {
          f2 = 1;
          break;
        }
      }
      if (!f1 && !f2)
        cout << "Yes";
      else
        cout << "No";
    } else
      cout << "No";
  }
  return 0;
}

Fixed submission:
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
//* vamsicool007    You are never wrong to do the right thing    vamsicool007 *
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
#include <bits/stdc++.h>
using namespace std;
#define flash                                                                  \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl "\n"
#define int long long
typedef long long ll;
typedef long double ld;
const int mod = 1000000007;
const int N = 200005;
vector<int> vis(N);
vector<vector<int>> adj(N);
void dfs(int v) {
  vis[v] = 1;
  for (auto i : adj[v]) {
    if (!vis[i]) {
      dfs(i);
    }
  }
  return;
}
bool isPrime(ll n) {
  if (n < 2)
    return false;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
ll factorial(ll n) { return (n == 1 || n == 0) ? 1 : n * factorial(n - 1); }
ll power(ll x, ll y) {
  ll res = 1;
  x = x;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % mod;
    y = y >> 1;
    x = (x * x) % mod;
  }
  return res % mod;
}
ll gcd(ll a, ll b) {
  if (a == 0)
    return b;
  return gcd(b % a, a);
}
ll lcm(ll a, ll b) { return (a / gcd(a, b) * b); }
ll max(ll a, ll b) {
  ll ans = a > b ? a : b;
  return ans;
}
ll min(ll a, ll b) {
  ll ans = a < b ? a : b;
  return ans;
}
int root(int a[], int i) {
  while (a[i] != i) {
    a[i] = a[a[i]];
    i = a[i];
  }
  return i;
}
void unionn(int a[], int i, int j) {
  int root_i = root(a, i);
  int root_j = root(a, j);
  a[root_i] = root_j;
  return;
}
void fun() {
#ifndef ONLINE_JUDGE
  freopen("infile.txt", "r", stdin);
  freopen("oufile.txt", "w", stdout);
#endif
}

signed main() {
  flash;
  // fun();
  int t = 1;
  // cin>>t;
  while (t--) {
    string s;
    cin >> s;
    int n = s.size();
    int f = 0;
    for (int i = 0; i < n / 2; i++) {
      if (s[i] != s[n - i - 1]) {
        f = 1;
        break;
      }
    }
    if (!f) {
      int m = (n - 1) / 2;
      int f1 = 0;
      for (int i = 0; i < (n - 1) / 4; i++) {
        if (s[i] != s[m - 1 - i]) {
          f1 = 1;
          break;
        }
      }
      int j = (n + 3) / 2;
      int k = (2 * n + 3) / 4;
      int f2 = 0;
      for (int i = j; i < k; i++) {
        if (s[i] != s[k - i - 1]) {
          f2 = 1;
          break;
        }
      }
      if (!f1 && !f2)
        cout << "Yes";
      else
        cout << "No";
    } else
      cout << "No";
  }
  return 0;
}