#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
struct node{
node* Prev;
node* Next;
char info;
};
class MyList{
int count_;
node *Head, *Tail;
int coursor;
public:
MyList() :Head(NULL), Tail(NULL), count_(0){};
void Add(char);
void Show();
void Del(int);
~MyList();
char ExactBracket(int i);
void SetCoursor(int p);
int GetCount();
void DoCommand(char x, int i);
};
int MyList::GetCount(){
return this->count_;
};
void MyList::Add(char x){
node *temp = new node;
temp->info = x;
temp->Next = NULL;
count_++;
if (!Head){
temp->Prev = NULL;
Head = temp;
Tail = Head;
}
else {
temp->Prev = Tail;
Tail->Next = temp;
Tail = temp;
}
}
void MyList::Show(){
node *t = Head;
while (t){
cout << t->info;
t = t->Next;
}
cout << "\n\n";
}
char MyList::ExactBracket(int i){
if(i>=count_)
return NULL;
node* tmp = Head;
for(int j = 0; j<i-1; j++){
tmp = tmp->Next;
}
return tmp->info;
}
void MyList::Del(int x){
if ((x==1) && (Head->Next)){ //Если удаляем первый, но есть и другие, то
node *temp=Head; //Указываем, что нам нужно начало списка
Head=Head->Next; //Сдвигаем начало на следующий за началом элемент
Head->Prev=NULL; //Делаем так, чтоб предыдущий началу элемент был пустым
delete temp; //Удаляем удаляемое начало
count_--; //Обязательно уменьшаем счетчик
return ; //И выходим из функции
} else if ((x==1) && (Head==Tail)){ //Если удаляем первый, но в списке только 1 элемент
Head->Next=NULL; //обнуляем все что нужно
Head=NULL;
delete Head; //Удаляем указатель на начало
count_=0; //Обязательно обозначаем, что в списке ноль элементов
return; //и выходим из функции
}
//Также может быть, что удаляемый элемент является последним элементом списка
if (x==count_){
node *temp=Tail; //Указываем, что нам нужен хвост
Tail=Tail->Prev; //Отодвигаем хвост немного назад
Tail->Next=NULL; //Обозначаем, что впереди за хвостом пусто
delete temp; //Очищаем память от бывшего хвоста
count_--; //Обязательно уменьшаем счетчик элементов
return; //И выходим из функции
}
//Если же удаляемый элемент лежит где-то в середине списка, то тогда его можно удалить
node *temp=Head,*temp2; //temp-Удаляемый элемент, temp2 нужен, чтобы не потерять данные
//cout<<count_<<"\n";
for (int i=0;i<x-1;i++) temp=temp->Next; //Идем к адресу удаляемого элемента
temp2=temp; //Временно запоминаем адрес удаляемого элемента
temp2->Prev->Next=temp->Next; //Записываем данные, что следующий за перед сейчас удаляемым элементом - это следующий от удаляемого
temp2->Next->Prev=temp->Prev; //а предыдущий для следующего - это предыдущий для удаляемого
delete temp; //теперь смело можно освободить память, удалив адрес на начало удаляемого элемента
count_--;
}
MyList::~MyList(){
// cout<<"\nDELETES\n";
while (Head){
// cout<<"Del is: "<<Head->x<<" ";
Tail=Head->Next;
delete Head;
Head=Tail;
}
}
void MyList::SetCoursor(int p){
this->coursor = p;
}
void MyList::DoCommand(char x, int i){
if (x == 'R'){
coursor++;
cout << coursor;
}
if (x == 'L'){
coursor--;
cout << coursor;
}
if (x == 'D')
{
int d = 1;
int tmP = coursor;
if(ExactBracket(tmP)=='('){
this->Del(tmP);
while (d!=0){
if(ExactBracket(tmP)=='('){
d++;
this->Del(tmP);
}
if (ExactBracket(tmP)==')'){
d--;
this->Del(tmP);
}
}
}
if(ExactBracket(tmP)==')'){
this->Del(tmP);
while (d!=0){
if(ExactBracket(tmP)==')'){
d++;
this->Del(tmP);
tmP--;
}
if (ExactBracket(tmP)=='('){
d--;
this->Del(tmP);
tmP--;
}
}
}
}
}
int main()
{
int n, m, p;//Скобки, команды, курсор
cin >> n >> m >> p;
string commands, brackets;
cin >> brackets >> commands;
MyList br;
br.SetCoursor(p);
for (int i = 0; i < n; i++){
br.Add(brackets[i]);
}
for (int i = 0; i < m; i++){
br.DoCommand(commands[i], i);
}
br.Show();
return 0;
}