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) { init(s, base_); }
  void init(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() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  RollingHash<1000000007> RH(s);
  int n = s.size(); //???????????¨Runtime Error
  for (int a = (n - 2) / 3, b; a >= 1; a--) {
    b = (n - a * 3) / 2;
    if (3 * a + 2 * b != n)
      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;
}

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) { init(s, base_); }
  void init(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() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  RollingHash<1000000007> RH(s);
  int ans = s.size();
  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;
    auto A1 = RH.get(0, a);
    auto B1 = RH.get(a, a + b);
    auto A2 = RH.get(a + b, a + b + a);
    auto B2 = RH.get(a + b + a, a + b + a + b);
    auto A3 = RH.get(a + b + a + b, a + b + a + b + a);
    if (A1 == A2 && A2 == A3 && B1 == B2) {
      chmin(ans, a + b);
    }
  }
  if (ans != s.size())
    cout << "Love " << s.substr(0, ans) << '!';
  else
    cout << "mitomerarenaiWA";
  cout << '\\n';
  return 0;
}