#B4249. Card Shuffle and Deal
Card Shuffle and Deal
Card Shuffle and Deal
In this problem, you are given a deck of \(2n\) cards whose types are recorded in a string. Initially, Alice arranges the \(2n\) cards face down in a single stack and records the type of each card from top to bottom.
Bob then performs a special shuffling procedure as follows:
- He splits the deck into two piles: the left pile consisting of the top \(n\) cards and the right pile consisting of the remaining \(n\) cards.
- He then builds a new deck by performing \(2n\) operations. In the \(i\)-th operation (for \(1 \le i \le 2n\)), he chooses the top card from one of the piles based on a decision string \(f\), where \[ f_i = \begin{cases} L & \text{if the card is taken from the left pile}, \\ R & \text{if the card is taken from the right pile}. \end{cases} \] The selected card is placed on the top of the new deck.
After shuffling, Bob deals the new deck by distributing cards alternately, starting with Alice (i.e. the first card goes to Alice, the second to Bob, the third to Alice, and so on). Your task is to determine the sequence of cards that Alice receives, in the order they are dealt.
inputFormat
The input consists of three lines:
- The first line contains a single integer \(n\) (\(1 \leq n \leq 10^5\)).
- The second line contains a string \(s\) of length \(2n\), representing the types of the cards from top to bottom.
- The third line contains a string \(f\) of length \(2n\), consisting of the characters 'L' and 'R'. It is guaranteed that exactly \(n\) characters are 'L' and \(n\) are 'R'.
outputFormat
Output a single string, which is the sequence of cards that Alice receives, in the order they are dealt.
sample
2
ABCD
LRRL
BC