Codeforces Round 350 (Div. 2)
E
Correct Bracket Sequence Editor
Codeforces
1700
原题
← D2F →
翻译中…

Recently Polycarp started to develop a text editor that works only with correct bracket sequences (abbreviated as CBS).

翻译中…

Note that a bracket sequence is correct if it is possible to get a correct mathematical expression by adding "+"-s and "1"-s to it. For example, sequences "(())()", "()" and "(()(()))" are correct, while ")(", "(()" and "(()))(" are not. Each bracket in CBS has a pair. For example, in "(()(()))":

翻译中…
  • 1st bracket is paired with 8th,
  • 2d bracket is paired with 3d,
  • 3d bracket is paired with 2d,
  • 4th bracket is paired with 7th,
  • 5th bracket is paired with 6th,
  • 6th bracket is paired with 5th,
  • 7th bracket is paired with 4th,
  • 8th bracket is paired with 1st.
翻译中…

Polycarp's editor currently supports only three operations during the use of CBS. The cursor in the editor takes the whole position of one of the brackets (not the position between the brackets!). There are three operations being supported:

翻译中…
  • «L» — move the cursor one position to the left,
  • «R» — move the cursor one position to the right,
  • «D» — delete the bracket in which the cursor is located, delete the bracket it's paired to and all brackets between them (that is, delete a substring between the bracket in which the cursor is located and the one it's paired to).
翻译中…

After the operation "D" the cursor moves to the nearest bracket to the right (of course, among the non-deleted). If there is no such bracket (that is, the suffix of the CBS was deleted), then the cursor moves to the nearest bracket to the left (of course, among the non-deleted).

翻译中…

There are pictures illustrated several usages of operation "D" below.

翻译中…

image

翻译中…

All incorrect operations (shift cursor over the end of CBS, delete the whole CBS, etc.) are not supported by Polycarp's editor.

翻译中…

Polycarp is very proud of his development, can you implement the functionality of his editor?

翻译中…

Input

翻译中…

The first line contains three positive integers $*n*$, $*m*$ and $*p*$ ($2 ≤ *n* ≤ 500 000$, $1 ≤ *m* ≤ 500 000$, $1 ≤ *p* ≤ *n*$) — the number of brackets in the correct bracket sequence, the number of operations and the initial position of cursor. Positions in the sequence are numbered from left to right, starting from one. It is guaranteed that $*n*$ is even.

翻译中…

It is followed by the string of $*n*$ characters "(" and ")" forming the correct bracket sequence.

翻译中…

Then follow a string of $*m*$ characters "L", "R" and "D" — a sequence of the operations. Operations are carried out one by one from the first to the last. It is guaranteed that the given operations never move the cursor outside the bracket sequence, as well as the fact that after all operations a bracket sequence will be non-empty.

翻译中…

Output

翻译中…

Print the correct bracket sequence, obtained as a result of applying all operations to the initial sequence.

翻译中…

Note

翻译中…

In the first sample the cursor is initially at position $5$. Consider actions of the editor:

翻译中…
  1. command "R" — the cursor moves to the position $6$ on the right;
  2. command "D" — the deletion of brackets from the position $5$ to the position $6$. After that CBS takes the form (())(), the cursor is at the position $5$;
  3. command "L" — the cursor moves to the position $4$ on the left;
  4. command "D" — the deletion of brackets from the position $1$ to the position $4$. After that CBS takes the form (), the cursor is at the position $1$.
翻译中…

Thus, the answer is equal to ().

翻译中…

样例

Input #1
8 4 5
(())()()
RDLD
Output #1
()
InputCopy OutputCopy
Input #2
12 5 3
((()())(()))
RRDLD
Output #2
(()(()))
InputCopy OutputCopy
Input #3
8 8 8
(())()()
LLLLLLDD
Output #3
()()
InputCopy OutputCopy
题目信息
题号
670E
时间限制
2 s
内存限制
256 MB
标签
数据结构
并查集
字符串

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。