Problem:
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

J - Unfair Game

Problem Statement

Rabbit Hanako and Fox Jiro are great friends going to JAG primary school. Today they decided to play the following game during the lunch break.

This game is played by two players with $N$ heaps of some number of stones. The players alternatively take their turn to play the game. Jiro is a kind gentleman, so he yielded the first turn to Hanako. In each turn, the player must take some stones, satisfying the following conditions:

If the player is Hanako, she must take between $1$ to $A$ stones, inclusive, from a heap.

If the player is Jiro, he must take between $1$ to $B$ stones, inclusive, from a heap.

The winner is the player who takes the last stone. Jiro thinks it is rude to go easy on her because he is a perfect gentleman. Therefore, he does him best. Of course, Hanako also does so.

Jiro is worried that he may lose the game. Being a cadet teacher working at JAG primary school as well as a professional competitive programmer, you should help him by programming. Your task is to write a program calculating the winner, assuming that they both play optimally.

Input

The first line contains three integers $N$, $A$, and $B$. $N$ ($1 \leq N \leq 10^5$) is the number of heaps. $A$ and $B$ ($1 \leq A, B \leq 10^9$) are the maximum numbers of stones that Hanako and Jiro can take in a turn, respectively. Then $N$ lines follow, each of which contains a single integer $S_i$ ($1 \leq S_i \leq 10^9$), representing the number of stones in the $i$-th heap at the beginning of the game.

Output

Output a line with "Hanako" if Hanako wins the game or "Jiro" in the other case.

Sample Input 1

3 5 4
3
6
12

Output for the Sample Input 1

Hanako

Sample Input 2

4 7 8
8
3
14
5

Output for the Sample Input 2

Jiro

Solution in C++11 (judge verdict: Wrong Answer)

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

int n, A, B, s[100005];

signed main(){
  
  cin>>n>>A>>B;
  
  for(int i=0;i<n;i++) cin>>s[i];
  
  if( A == B ){
    
    int x = 0;
    
    for(int i=0;i<n;i++)
      x ^= ( ( s[i] - 1 ) % A ) ;
    
    if( x == 0 ) cout<<"Jiro"<<endl;
    else cout<<"Hanako"<<endl;
    
  }
  
  if( A > B ){
    
    int flag = 0;
    
    for(int i=0;i<n;i++)
      if( A <= s[i] ) flag = 1;
    
    if( flag ) cout<<"Hanako"<<endl;
    else{
      
      int x = 0;
      
      for(int i=0;i<n;i++) x^=s[i];
      
      if( x == 0 ) cout<<"Jiro"<<endl;
      else cout<<"Hanako"<<endl;
      
    }
    
  }
  
  if( A < B ){
    
    int flag = 0;
    
    for(int i=0;i<n;i++)
      if( B <= s[i] ) flag = 1;
    
    if( flag ) cout<<"Jiro"<<endl;
    else{
      
      int x = 0;
    
      for(int i=0;i<n;i++) x^=s[i];
    
      if( x == 0 ) cout<<"Jiro"<<endl;
      else cout<<"Hanako"<<endl;
      
    }
    
  }
  
  return 0;
}