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

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

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

int N, A, B;
int S[111111];

signed main() {
  cin >> N >> A >> B;
  rep(i, N) cin >> S[i];

  if (A == B) {
    int X = 0;
    rep(i, N) X ^= S[i] % (A + 1);
    if (X)
      cout << "Hanako" << endl;
    else
      cout << "Jiro" << endl;
    return 0;
  }

  if (A > B) {
    int X = 0;
    rep(i, N) X ^= S[i] % (B + 1);
    if (X) {
      cout << "Hanako" << endl;
      return 0;
    }

    rep(i, N) {
      if (S[i] > B) {
        cout << "Hanako" << endl;
        return 0;
      }
    }
    cout << "Jiro" << endl;
    return 0;
  }

  int X = 0;
  rep(i, N) X ^= S[i] % (A + 1);
  if (X == 0) {
    cout << "Jiro" << endl;
    return 0;
  }

  vint lis;
  rep(i, N) if (S[i] > A) lis.pb(i);
  if (lis.size() == 0) {
    cout << "Hanako" << endl;
    return 0;
  }
  if (lis.size() > 1) {
    cout << "Jiro" << endl;
    return 0;
  }
  int k = lis[0];
  int Y = 0;
  rep(i, N) if (i != k) Y ^= S[i] % (A + 1);

  if (Y > A) {
    cout << "Jiro" << endl;
    return 0;
  }

  int tmp;
  if (S[k] % (A + 1) > Y)
    tmp = S[k] % (A + 1) - Y;
  else
    tmp = S[k] % (A + 1) + (A + 1 - Y);

  if (S[k] - tmp > A) {
    cout << "Jiro" << endl;
  } else {
    cout << "Hanako" << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

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

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

int N, A, B;
int S[111111];

signed main() {
  cin >> N >> A >> B;
  rep(i, N) cin >> S[i];

  if (A == B) {
    int X = 0;
    rep(i, N) X ^= S[i] % (A + 1);
    if (X)
      cout << "Hanako" << endl;
    else
      cout << "Jiro" << endl;
    return 0;
  }

  if (A > B) {
    int X = 0;
    rep(i, N) X ^= S[i] % (B + 1);
    if (X) {
      cout << "Hanako" << endl;
      return 0;
    }

    rep(i, N) {
      if (S[i] > B) {
        cout << "Hanako" << endl;
        return 0;
      }
    }
    cout << "Jiro" << endl;
    return 0;
  }

  int X = 0;
  rep(i, N) X ^= S[i] % (A + 1);
  if (X == 0) {
    cout << "Jiro" << endl;
    return 0;
  }

  vint lis;
  rep(i, N) if (S[i] > A) lis.pb(i);
  if (lis.size() == 0) {
    cout << "Hanako" << endl;
    return 0;
  }
  if (lis.size() > 1) {
    cout << "Jiro" << endl;
    return 0;
  }
  int k = lis[0];
  int Y = 0;
  rep(i, N) if (Y != k) Y ^= S[i] % (A + 1);

  if (Y > A) {
    cout << "Jiro" << endl;
    assert(0);
    return 0;
  }

  int tmp;
  if (S[k] % (A + 1) > Y)
    tmp = S[k] % (A + 1) - Y;
  else
    tmp = S[k] % (A + 1) + (A + 1 - Y);

  if (S[k] - tmp > A) {
    cout << "Jiro" << endl;
  } else {
    cout << "Hanako" << endl;
  }

  return 0;
}