Problem p03533 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

#ifdef DEBUG_MODE
#define DBG(n) n;
#else
#define DBG(n) ;
#endif
#define REP(i, n) for (ll(i) = (0); (i) < (n); ++i)
#define rep(i, s, g) for (ll(i) = (s); (i) < (g); ++i)
#define rrep(i, s, g) for (ll(i) = (s); i >= (g); --(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v, n)                                                           \
  {                                                                            \
    for (int W = 0; W < (n); W++)                                              \
      cerr << v[W] << ' ';                                                     \
    cerr << endl << endl;                                                      \
  }
#define SHOW2d(v, i, j)                                                        \
  {                                                                            \
    for (int aaa = 0; aaa < i; aaa++) {                                        \
      for (int bbb = 0; bbb < j; bbb++)                                        \
        cerr << v[aaa][bbb] << ' ';                                            \
      cerr << endl;                                                            \
    }                                                                          \
    cerr << endl;                                                              \
  }
#define ALL(v) v.begin(), v.end()
#define Decimal fixed << setprecision(20)
#define INF 1000000000
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> P;

int main() {
  string str;
  cin >> str;

  for (int i = 0; i < str.size() - 1; i++) {
    if (str[i] == 'A' && str[i + 1] == 'A') {
      cout << "NO" << endl;
      return 0;
    }
  }
  bool flag = false;
  for (int i = 0; i < str.size() - 2; i++) {
    if (str[i] == 'K' && str[i + 1] == 'I' && str[i + 2] == 'H') {
      flag = true;
    }
  }

  string tmp = "";

  for (int i = 0; i < str.size(); i++) {
    if (str[i] != 'A') {
      tmp += str[i];
    }
  }

  if (tmp == "KIHBR" && flag) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

#ifdef DEBUG_MODE
#define DBG(n) n;
#else
#define DBG(n) ;
#endif
#define REP(i, n) for (ll(i) = (0); (i) < (n); ++i)
#define rep(i, s, g) for (ll(i) = (s); (i) < (g); ++i)
#define rrep(i, s, g) for (ll(i) = (s); i >= (g); --(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v, n)                                                           \
  {                                                                            \
    for (int W = 0; W < (n); W++)                                              \
      cerr << v[W] << ' ';                                                     \
    cerr << endl << endl;                                                      \
  }
#define SHOW2d(v, i, j)                                                        \
  {                                                                            \
    for (int aaa = 0; aaa < i; aaa++) {                                        \
      for (int bbb = 0; bbb < j; bbb++)                                        \
        cerr << v[aaa][bbb] << ' ';                                            \
      cerr << endl;                                                            \
    }                                                                          \
    cerr << endl;                                                              \
  }
#define ALL(v) v.begin(), v.end()
#define Decimal fixed << setprecision(20)
#define INF 1000000000
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> P;

int main() {
  string str;
  cin >> str;

  if (str.size() < 3) {
    cout << "NO" << endl;
    return 0;
  }
  for (int i = 0; i < str.size() - 1; i++) {
    if (str[i] == 'A' && str[i + 1] == 'A') {
      cout << "NO" << endl;
      return 0;
    }
  }
  bool flag = false;
  for (int i = 0; i < str.size() - 2; i++) {
    if (str[i] == 'K' && str[i + 1] == 'I' && str[i + 2] == 'H') {
      flag = true;
    }
  }

  string tmp = "";

  for (int i = 0; i < str.size(); i++) {
    if (str[i] != 'A') {
      tmp += str[i];
    }
  }

  if (tmp == "KIHBR" && flag) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}