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

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

#define int long long
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
#define each(it, v)                                                            \\
  for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
template <class T, class U> inline void chmin(T &t, U f) {
  if (t > f)
    t = f;
}
template <class T, class U> inline void chmax(T &t, U f) {
  if (t < f)
    t = f;
}

signed solve() {
  int N;
  cin >> N;
  vector<string> S(N), T(N);
  rep(i, N) cin >> S[i];
  rep(i, N) cin >> T[i];
  int A = 0, B = 0;
  rep(i, N) {
    if (S[i] == "kougekida" && T[i] == "kougekida") {
      if (A > B)
        return puts("Isono-kun");
      else if (A < B)
        return puts("Nakajima-kun");
      A = B = 0;
    } else if (S[i] == "kougekida") {
      if (A == 0)
        return puts("Nakajima-kun");
      if (A == 5 || T[i] != "mamoru")
        return puts("Isono-kun");
      A = 0;
    } else if (T[i] == "kougekida") {
      if (B == 0)
        return puts("Isono-kun");
      if (B == 5 || S[i] != "mamoru")
        return puts("Nakajima-kun");
      B = 0;
    } else {
      if (S[i] == "tameru")
        A = min(A + 1, 5ll);
      if (T[i] == "tameru")
        B = min(B + 1, 5ll);
    }
  }
  puts("Hikiwake-kun");
  return 0;
}

signed main() {
  solve();
  return 0;
}

Error: 13

Fixed submission:

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

#define int long long
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
#define each(it, v)                                                            \\
  for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
template <class T, class U> inline void chmin(T &t, U f) {
  if (t > f)
    t = f;
}
template <class T, class U> inline void chmax(T &t, U f) {
  if (t < f)
    t = f;
}

signed main() {
  int N;
  cin >> N;
  vector<string> S(N), T(N);
  rep(i, N) cin >> S[i];
  rep(i, N) cin >> T[i];
  int A = 0, B = 0;
  rep(i, N) {
    if (S[i] == "kougekida" && T[i] == "kougekida") {
      if (A > B)
        return puts("Isono-kun");
      else if (A < B)
        return puts("Nakajima-kun");
      A = B = 0;
    } else if (S[i] == "kougekida") {
      if (A == 0)
        return puts("Nakajima-kun");
      if (A == 5 || T[i] != "mamoru")
        return puts("Isono-kun");
      A = 0;
    } else if (T[i] == "kougekida") {
      if (B == 0)
        return puts("Isono-kun");
      if (B == 5 || S[i] != "mamoru")
        return puts("Nakajima-kun");
      B = 0;
    } else {
      if (S[i] == "tameru")
        A = min(A + 1, 5ll);
      if (T[i] == "tameru")
        B = min(B + 1, 5ll);
    }
  }
  puts("Hikiwake-kun");
  return 0;
}