Bracelet Making


Submit solution

Points: 1
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type
Allowed languages
C, C++, Java, Python

After spending a long time working for AUCPL Inc., Lily decides to take a break to attend her favorite artist's concert. At the show, it is a tradition for fans to exchange or gift handcrafted bracelets to foster community, connection and lasting memories. With an upcoming concert approaching, Lily, being a devoted fan, decides to prepare several bracelets in advance using her bracelet-making kit.

To create a bracelet, Lily starts with an empty elastic cord. She performs a sequence of actions, where each action is one of the following:

  • Insert a bead onto either end of the cord (left or right), or
  • Move some beads from one end of the cord to the other, transferring one by one.

You are given the complete sequence of Lily's actions for constructing a single bracelet. Determine the final arrangement of beads on the bracelet after all actions have been performed.

Input

The first line contains an integer n (0 \le n \le 10^5), the number of Lily's actions.

The next n lines each contains an action. These lines will take the form INSERT LEFT x (x.length = 1), INSERT RIGHT x (x.length = 1), MOVE LEFT y (1 \leq y \leq 100) or MOVE RIGHT y (1 \leq y \leq 100).

  • INSERT LEFT x: insert a bead engraved with message x to the left end
  • INSERT RIGHT x: insert a bead engraved with message x to the right end
  • MOVE LEFT y: move y beads from the right end to the left end one by one
  • MOVE RIGHT y: move y beads from the left end to the right end one by one

It is guaranteed that the first action is always an INSERT.

Output

Output the final message on the bracelet, from left to right, as a string.

Example

Input 1
10
INSERT LEFT u
INSERT LEFT a
INSERT LEFT n
INSERT LEFT i
INSERT RIGHT c
INSERT RIGHT p
INSERT RIGHT l
INSERT RIGHT j
INSERT RIGHT o
MOVE LEFT 2
Output 1
joinaucpl

Starting with an empty bracelet cord, after performing the first 4 INSERT LEFT actions, the bracelet is as follow:

Image 1

After performing the INSERT RIGHT actions:

Image 2

Finally, we move the 2 rightmost beads (j, o) from right to left. Since we moved one by one, the bead 'o' get inserted before bead 'j', which results in the final bracelet:

Image 3

Input 2
6
INSERT LEFT a
INSERT LEFT a
INSERT RIGHT b
INSERT LEFT b
MOVE RIGHT 3
MOVE LEFT 1
Output 2
abba
Input 3
2
INSERT LEFT a
MOVE LEFT 20

Since she transfers each bead one by one, there's always an available bead in the cord for her to transfer in the next move.

Output 3
a

Comments

There are no comments at the moment.