#P1033C. Permutation Game
Permutation Game
Description
After a long day, Alice and Bob decided to play a little game. The game board consists of cells in a straight line, numbered from to , where each cell contains a number between and . Furthermore, no two cells contain the same number.
A token is placed in one of the cells. They take alternating turns of moving the token around the board, with Alice moving first. The current player can move from cell to cell only if the following two conditions are satisfied:
- the number in the new cell must be strictly larger than the number in the old cell (i.e. ), and
- the distance that the token travels during this turn must be a multiple of the number in the old cell (i.e. ).
Whoever is unable to make a move, loses. For each possible starting position, determine who wins if they both play optimally. It can be shown that the game is always finite, i.e. there always is a winning strategy for one of the players.
The first line contains a single integer () — the number of numbers.
The second line contains integers (). Furthermore, there are no pair of indices such that .
Print — a string of characters, where the -th character represents the outcome of the game if the token is initially placed in the cell . If Alice wins, then has to be equal to "A"; otherwise, has to be equal to "B".
Input
The first line contains a single integer () — the number of numbers.
The second line contains integers (). Furthermore, there are no pair of indices such that .
Output
Print — a string of characters, where the -th character represents the outcome of the game if the token is initially placed in the cell . If Alice wins, then has to be equal to "A"; otherwise, has to be equal to "B".
Note
In the first sample, if Bob puts the token on the number (not position):
- : Alice can move to any number. She can win by picking , from which Bob has no move.
- : Alice can move to and . Upon moving to , Bob can win by moving to . If she chooses instead, she wins, as Bob has only a move to , from which Alice can move to .
- : Alice can only move to , after which Bob wins by moving to .
- , , or : Alice wins by moving to .
- , : Alice has no move, and hence she loses immediately.