Draining the Job Queue
Two worker schedulers, A and B, take turns draining a shared job queue. A always moves
first. Each scheduler is configured with the same fixed set of batch sizes S — on its turn, a
scheduler must remove exactly s jobs from the front of the queue for some s in S, provided
at least s jobs remain. A scheduler that cannot make a legal move (every batch size in S is
larger than the number of jobs left) stalls and loses the round. The scheduler that removes the
very last job earns the on-call bonus and wins.
You are given S and q independent starting queue sizes. For each starting size, assuming both
schedulers play optimally, determine who wins.
Input
The first line contains two integers k and q (1 ≤ k ≤ 10, 1 ≤ q ≤ 10^6) — the number of
allowed batch sizes and the number of queries.
The second line contains k distinct integers s_1, ..., s_k (1 ≤ s_i ≤ 100) — the allowed
batch sizes, in no particular order.
The third line contains q integers n_1, ..., n_q (0 ≤ n_i ≤ 10^6), the starting number of
jobs in the queue for each query.
Output
Print q lines. For the i-th query, print A if scheduler A wins with optimal play starting
from a queue of size n_i, or B if scheduler B wins.
Notes
In the first example S = {1, 4}. Starting from n = 2, A must remove 1 job (4 is too many),
leaving 1 job for B, who removes it and wins. Starting from n = 4, A removes all 4 jobs at
once and wins immediately.
Starting from n = 0 the queue is already empty, so A has no legal move and B wins by
default.