Simulate a queue where boys swap with girls one position at a time over several seconds.
A school queue contains only boys and girls. Each second, every boy who is immediately before a girl swaps places with that girl. All such swaps happen simultaneously in one second.
Given the initial queue and the number of seconds that pass, determine the final arrangement of the queue.
Your task is to output the queue after the given number of seconds.
Example 1
Input
5 1 BGGBG
Output
GBGGB
Explanation
In the first second, the boy at position 1 swaps with the girl at position 2, and the boy at position 4 swaps with the girl at position 5.
Example 2
Input
5 2 BGGBG
Output
GGBGB
Explanation
After the first second the queue becomes GBGGB. In the second second, the boy at position 2 swaps with the girl at position 3.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.