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

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

// #define int long long
#define DBG 1
#define dump(o)                                                                \\
  if (DBG) {                                                                   \\
    cerr << #o << " " << (o) << " ";                                           \\
  }
#define dumpl(o)                                                               \\
  if (DBG) {                                                                   \\
    cerr << #o << " " << (o) << endl;                                          \\
  }
#define dumpc(o)                                                               \\
  if (DBG) {                                                                   \\
    cerr << #o;                                                                \\
    for (auto &e : (o))                                                        \\
      cerr << " " << e;                                                        \\
    cerr << endl;                                                              \\
  }
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
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;
}

// Roling Hash
// RollingHash RH(s,base) base:[2,MOD)?????±??°
// RH.set(s,base):
// vector???????§???????????????????????????§????????????????????????????????????
// RH.get(l,r): [l,r)??????????????\\ O(1)
// 1000000007, 1000000009, 1000000021
template <long long MOD> class RollingHash {
public:
  int n;
  long long base;
  vector<long long> pow, hash;
  RollingHash() {}
  RollingHash(const string &s, long long base_ = 10007) { set(s, base_); }
  void set(const string &s, long long base_ = 10007) {
    n = s.size();
    base = base_;
    calc(s.c_str());
  }
  long long get(int x) const { return hash[x]; }
  long long get(int l, int r) const {
    return (get(r) - get(l) * pow[r - l] % MOD + MOD) % MOD;
  }
  void calc(const char *s) {
    pow.resize(n + 1);
    pow[0] = 1;
    hash.resize(n + 1);
    hash[0] = 0;
    for (int i = 0; i < n; i++) {
      pow[i + 1] = pow[i] * base % MOD;
      hash[i + 1] = (s[i] + hash[i] * base) % MOD;
    }
  }
};

using RH = RollingHash<1000000007>;

int main() {
  string s;

  while (cin >> s) {
    int n = s.size();
    int a = n % 2 == 0 ? 2 : 1;
    int b = n % 2 == 0 ? n / 2 - 1 : n / 2;
    int c = b + a;
    int d = n - a;
    RH rh(s);
    int ans = n;
    while (a < b) {
      int A = rh.get(0, a);
      if (rh.get(b, c) == A && rh.get(d, n) == A &&
          rh.get(a, b) == rh.get(c, d)) {
        ans = min(ans, b);
      }
      a += 2;
      b -= 1;
      c += 1;
      d -= 2;
    }
    if (ans != n) {
      cout << "Love " << s.substr(0, ans) << '!';
    } else {
      cout << "mitomerarenaiWA";
    }
    cout << '\\n';
  }
}

Error: 0

Fixed submission:

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

// #define int long long
#define DBG 1
#define dump(o)                                                                \\
  if (DBG) {                                                                   \\
    cerr << #o << " " << (o) << " ";                                           \\
  }
#define dumpl(o)                                                               \\
  if (DBG) {                                                                   \\
    cerr << #o << " " << (o) << endl;                                          \\
  }
#define dumpc(o)                                                               \\
  if (DBG) {                                                                   \\
    cerr << #o;                                                                \\
    for (auto &e : (o))                                                        \\
      cerr << " " << e;                                                        \\
    cerr << endl;                                                              \\
  }
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
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;
}

// Roling Hash
// RollingHash RH(s,base) base:[2,MOD)?????±??°
// RH.set(s,base):
// vector???????§???????????????????????????§????????????????????????????????????
// RH.get(l,r): [l,r)??????????????\\ O(1)
// 1000000007, 1000000009, 1000000021
template <long long MOD> class RollingHash {
public:
  int n;
  long long base;
  vector<long long> pow, hash;
  RollingHash() {}
  RollingHash(const string &s, long long base_ = 10007) { set(s, base_); }
  void set(const string &s, long long base_ = 10007) {
    n = s.size();
    base = base_;
    calc(s.c_str());
  }
  long long get(int x) const { return hash[x]; }
  long long get(int l, int r) const {
    return (get(r) - get(l) * pow[r - l] % MOD + MOD) % MOD;
  }
  void calc(const char *s) {
    pow.resize(n + 1);
    pow[0] = 1;
    hash.resize(n + 1);
    hash[0] = 0;
    for (int i = 0; i < n; i++) {
      pow[i + 1] = pow[i] * base % MOD;
      hash[i + 1] = (s[i] + hash[i] * base) % MOD;
    }
  }
};

signed main() {
  string s;
  cin >> s;
  RollingHash<MOD> RH(s);
  for (int a = (s.size() - 2) / 3, b; a >= 1; a--) {
    b = (s.size() - a * 3) / 2;
    if (3 * a + 2 * b != s.size())
      continue;
    if (RH.get(0, a) == RH.get(a + b, a + b + a) &&
        RH.get(0, a) == RH.get(a + b + a + b, a + b + a + b + a) &&
        RH.get(a, a + b) == RH.get(a + b + a, a + b + a + b)) {
      cout << "Love " << s.substr(0, a + b) << "!" << endl;
      return 0;
    }
  }
  cout << "mitomerarenaiWA" << endl;
  return 0;
}