Under construction

Still being built. Things may change

Candy Factory

Time limit0.5sMemory limit1024 MB

Summary
Given two belts of candies, apply Q rotations, prefix swaps of length R, and gripper resizes, then print both belts' final contents.
Level

Medium7 of 10

Topics
Tree, Simulation, Implementation
Solved
No attempts yet

Problem

Anz really loves candy. So he invested all the money he had earned so far to build a candy factory.

In the packaging stage, the final step of the factory, candies of various kinds are handled with two conveyor belts and one gripper. Each conveyor belt has NN cells. The gripper picks up all candies from the first cell up to any chosen cell at once.

The possible operations are as follows. Initially, every cell of each conveyor belt holds one candy.

  • SS: Using the gripper, swap the candies between the two conveyor belts from the first cell up to the RR-th cell. RR is the current size of the gripper.
    • In other words, swap the candy in cell 1 of belt 1 with the candy in cell 1 of belt 2, then swap the candies in cell 2, and so on, finally swapping the candies in cell RR.
  • LL xx: Move conveyor belt xx one cell to the left.
    • Every candy except the one in the first cell moves from position pp to position (p−1)(p-1). The candy in the first cell moves to position NN.
  • RR xx: Move conveyor belt xx one cell to the right.
    • Every candy except the one in cell NN moves from position pp to position (p+1)(p+1). The candy in cell NN moves to the first cell.
  • II: Increase the gripper size by 1. The input never makes the gripper size greater than NN.
  • DD: Decrease the gripper size by 1. The input never makes the gripper size less than 1.

Input

The first line contains the size of the two conveyor belts NN, the initial gripper size RR, and the number of operations QQ.

The second line gives the candies on conveyor belt 1 from the leftmost cell to the rightmost cell, in order, with no spaces.

The third line gives the candies on conveyor belt 2 from the leftmost cell to the rightmost cell, in order, with no spaces.

Each candy is represented by an uppercase English letter.

The next QQ lines each give one operation to process.

Output

After all operations are processed, print the candies on conveyor belt 1 on the first line, in the same format as the input. Print the candies on conveyor belt 2 on the second line, in the same format.

Constraints

  • 1≤N≤500,0001 \le N \le 500{,}000
  • 1≤R≤N1 \le R \le N
  • 1≤Q≤500,0001 \le Q \le 500{,}000
  • 1≤x≤21 \le x \le 2

Examples1

  1. Example 1

    Input
    5 2 5
    ABCDE
    FGHIJ
    S
    L 1
    R 2
    I
    S
    
    Expected output
    JABEF
    GCDHI