This page is still under construction.

Parts of this page are still being built. What you see may change.

Red Chips, Green Chips

Time limit1sMemory limit128 MB

Summary
With r red and g green chips, players alternately remove k chips of one color where k divides the other color's count; decide the winner under optimal play.
Level

Hard8 of 10

Topics
Game theory, Math, Number theory, Implementation
Solved
No attempts yet

Problem

There are rr red chips and gg green chips on a desk. Two players, A and B, take turns, with A moving first.

On your turn, you do the following:

  1. Choose one of the two colors, red or green.
  2. Remove kk chips of the chosen color from the desk. Here kk must be a positive integer that divides the number of chips of the other (not chosen) color, and it cannot exceed the number of chips remaining in the chosen color.

The player who removes the last chip wins.

Assuming both players play optimally, write a program that determines who always wins.

Input

The first line contains two integers rr and gg separated by a space. (1≤r,g≤1091 \le r, g \le 10^9)

Output

Print A player wins if A can always win, or B player wins if B can always win.

Examples3

  1. Example 1

    Input
    2 1
    
    Expected output
    A player wins
    
  2. Example 2

    Input
    1 1
    
    Expected output
    B player wins
    
  3. Example 3

    Input
    2 2
    
    Expected output
    B player wins