The second door has been used 1, and there are four keys left, but none of the first three, that is, four times.
And then loop. . . The last 5+4+3+2+ 1= 15 (times)
In order to win, A will produce six cards after taking the penultimate card. Let A take four cards first, then B, and then count the remaining cards as multiples of six. Finally, after B takes it, there will only be 5~ 1 card.