Problem list
Log in
#coci00009 · COCI 2006/2007 Contest 2

Kolone

Silver IV 0.6 s 32 MB

When moving, ants form rows so that each ant except the first is behind another ant. It is not widely known what happens when two rows of ants moving in opposite directions run into each other in a passage too narrow for both rows to pass through. One theory says that, in that situation, the ants will jump over each other.

From the moment the rows meet, every second each ant jumps over (or gets jumped over, as they agree upon) the ant in front of it so that the two ants swap places, but only if the other ant is moving in the opposite direction. Find the order of the ants after $T$ seconds.

Input

The first line contains two integers $N_1$ and $N_2$, the numbers of ants in the first and second rows, respectively.

The next two rows contain the orders of ants in the first and second row (first to last). Each ant is uniquely determined by an uppercase letter of the English alphabet (this letter is unique between both rows).

The last line of input contains the integer $T$ ($0 \le T \le 50$).

Output

Output the order of the ants after $T$ seconds on a single line. Our viewpoint is such that the first row of ants comes from our left side and the second one from our right side.

Example 1

Input
3 3
ABC
DEF
0
Output
CBADEF

Example 2

Input
3 3
ABC
DEF
2
Output
CDBEAF

Example 3

Input
3 4
JLA
CRUO
3
Output
CARLUJO
Source
COCI 2006/2007 Contest 2
Appears in
Not part of a ladder, contest or set yet.
Accepted 1 Submissions 1 Acceptance 100% Solvers 1

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code