editor | 프로그래밍의 벗 PivotOJ
PivotOJ

editor

시간 제한: 300ms메모리 제한: 512MB출처: CHC 2004 National Competition #1 - JuniorsBOJ 1406

문제

You are given a text that is a sequence of characters.

Cursor can be positioned inside of the text (between any two consecutive characters), at the beginning (left of the first character) or at the end (right of the last character) of the text.

You are given sequence of operations you must perform on the text. 

Possible operations are: 

L move cursor one character to the left (if cursor is at the beginning, do nothing)
D move cursor one character to the right (if cursor is at the end, do nothing)
B delete character left of the cursor (if cursor is at the beginning, do nothing)
P $ add character rightofthecursor(character right of the cursor (character is any lowercase letter of English alphabet)

Before execution of given operations, cursor is at the end of the text. 

Write a program that will determine what would the text look like after execution of given operations. 

입력

In the first row there is the text. It consists only of lowercase letters of English alphabet and its maximal length is 100,000 characters.

In the next row there is an integer N, 1 ≤ N ≤ 500,000, number of given operations. 

In the next N rows there are operations given in the order of execution. 

출력

In first and only row you should write text after the execution of all the operations. 

예제

예제 1

입력
abcd
3
P x
L
P y
출력
abcdyx

예제 2

입력
abc
9
L
L
L
L
L
P x
L
B
P y
출력
yxabc

예제 3

입력
dmih
11
B
B
P x
L
B
B
B
P y
D
D
P z
출력
yxz
코드를 제출하려면 로그인하세요.