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

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array) (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < n; i++)
#define rev(i, n) for (int i = n - 1; i >= 0; i--)
#define _GLIBCXX_DEBUG
#define int long long
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1) {
  unsigned day;
  if (dow < dow1)
    dow += 7;
  day = dow - dow1;
  day += 7 * n - 6;
  return day;
}
unsigned DayToWeekNumber(unsigned day) { return (day - 1) / 7 + 1; }
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0) {
  return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
  string S;
  cin >> S;
  rep(i, (S.size() + 1) / 2) {
    if (S.at(i) != S.at(S.size() - i - 1)) {
      cout << "No" << endl;
      return 0;
    }
  }
  rep(i, ((S.size() - 1) / 2 - 1) / 2) {
    if (S.at(i) != S.at((S.size() - 1) / 2 - 1 - i)) {
      cout << "No" << endl;
      return 0;
    }
  }
  int j = 0;
  for (int i = (S.size() + 3) / 2 - 1; i < S.size() - 1; i++, j++) {
    if (S.at(i) != S.at(S.size() - 1 - j)) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

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


Fixed submission:

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array) (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < n; i++)
#define rev(i, n) for (int i = n - 1; i >= 0; i--)
#define _GLIBCXX_DEBUG
#define int long long
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1) {
  unsigned day;
  if (dow < dow1)
    dow += 7;
  day = dow - dow1;
  day += 7 * n - 6;
  return day;
}
unsigned DayToWeekNumber(unsigned day) { return (day - 1) / 7 + 1; }
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0) {
  return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
  string S;
  cin >> S;
  rep(i, (S.size() + 1) / 2) {
    if (S.at(i) != S.at(S.size() - i - 1)) {
      cout << "No" << endl;
      return 0;
    }
  }
  rep(i, (S.size() - 1) / 2 - 1) {
    if (S.at(i) != S.at((S.size() - 1) / 2 - 1 - i)) {
      cout << "No" << endl;
      return 0;
    }
  }
  for (int i = (S.size() + 3) / 2 - 1; i < S.size(); i++) {
    if (S.at((S.size() + 3) / 2 - 1 + i) != S.at(S.size() - 1 - i)) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}