#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d,n,x;
    cin>>a>>b>>c>>d>>n;
    string s;
    int cc=0;
    for (int i=0;i<n;i++)
    {
        cin>>x;
        cc+=x;
        while(x--)
        {
            s+=(char)(97+i);
        }
    }
    //cout<<s<<endl;
    int co=0;
    char arr[max(b,d)][a+c];
    if (max(b,d)==b)
    {
        for (int i=d;i<b;i++)
        {
            for (int j=a;j<a+c;j++)
                arr[i][j]='.';
        }
        int f=0;
        if (d%2==0)
        {
            for (int i=d-1;i>=0;i--)
            {
                if (f==0)
                {
                    for (int j=a;j<a+c;j++)
                    {
                        arr[i][j]=s[co];
                        co++;
                    }
                    f=1;
                }
                else
                {
                    for (int j=a+c-1;j>=a;j--)
                    {
                        arr[i][j]=s[co];
                        co++;
                    }
                    f=0;
                }

            }
        }
        else
        {
            for (int i=d-1;i>=0;i--)
            {
                if (f==1)
                {
                    for (int j=a;j<a+c;j++)
                    {
                        arr[i][j]=s[co];
                        co++;
                    }
                    f=0;
                    if(co==cc)
                        break;
                }
                else
                {
                    for (int j=a+c-1;j>=a;j--)
                    {
                        arr[i][j]=s[co];
                        co++;
                    }
                    f=1;
                    if(co==cc)
                        break;
                }

            }

        }
        int tm=0,bm=b-1,lm=0,rm=a-1;
        while(tm<=bm&&lm<=rm)
        {
            for (int j=rm;j>=lm;j--)
            {
                arr[tm][j]=s[co];
                co++;
            }
                    if(co==cc)
                        break;
            tm++;
            for (int j=tm;j<=bm;j++)
            {
                arr[j][lm]=s[co];
                co++;
            }
                                if(co==cc)
                        break;
            lm++;
            for (int j=lm;j<=rm;j++)
            {
                arr[bm][j]=s[co];
                co++;
            }
                                if(co==cc)
                        break;
            bm--;
            for (int j=bm;j>=tm;j--)
            {
                arr[j][rm]=s[co];
                co++;
            }
                                if(co==cc)
                        break;
            rm--;
        }
    }
    else
    {
        for (int i=b;i<d;i++)
        {
            for (int j=0;j<a;j++)
                arr[i][j]='.';
        }
        int f=1;
        if (b%2==0)
        {
            for (int i=b-1;i>=0;i--)
            {
                if (f==1)
                {
                    for (int j=a-1;j>=0;j--)
                    {
                        arr[i][j]=s[co];
                        co++;
                    }
                    f=0;
                                        if(co==cc)
                        break;
                }
                else
                {
                    for (int j=0;j<a;j++)
                    {
                        arr[i][j]=s[co];
                        co++;
                    }
                    f=1;
                                        if(co==cc)
                        break;
                }
            }
        }
        else
        {
            for (int i=b-1;i>=0;i--)
            {
                if (f==1)
                {
                    for (int j=0;j<a;j++)
                    {
                        arr[i][j]=s[co];
                        co++;
                    }
                    f=0;
                                        if(co==cc)
                        break;
                }
                else
                {
                    for (int j=a-1;j>=0;j--)
                    {
                        arr[i][j]=s[co];
                        co++;
                    }
                    f=1;
                                        if(co==cc)
                        break;
                }

            }

        }
        int tm=0,bm=d-1,lm=a,rm=a+c-1;
        while(tm<=bm&&lm<=rm)
        {
            for (int j=lm;j<=rm;j++)
            {
                arr[tm][j]=s[co];
                co++;
            }
            tm++;
                                if(co==cc)
                        break;
            for (int j=tm;j<=bm;j++)
            {
                //cout<<"lamba";
                arr[j][rm]=s[co];
                co++;
            }
            rm--;
                                if(co==cc)
                        break;
            for (int j=rm;j>=lm;j--)
            {
                arr[bm][j]=s[co];
                co++;
            }
            bm--;
                                if(co==cc)
                        break;
            for (int j=bm;j>=tm;j--)
            {
                arr[j][lm]=s[co];
                co++;
            }
            lm++;
                                if(co==cc)
                        break;
        }
    }
    cout<<"YES"<<endl;
    for (int i=0;i<max(b,d);i++)
    {
        for (int j=0;j<a+c;j++)
            cout<<arr[i][j];
        cout<<endl;
    }
    //cout<<arr[1][3]<<"da"<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d,n,x;
    cin>>a>>b>>c>>d>>n;
    string s;
    int cc=0;
    for (int i=0;i<n;i++)
    {
        cin>>x;
        cc+=x;
        while(x--)
        {
            s+=(char)(97+i);
        }
    }
    //cout<<s<<endl;
    int co=0;
    char arr[max(b,d)][a+c];
    if (max(b,d)==b)
    {
        for (int i=d;i<b;i++)
        {
            for (int j=a;j<a+c;j++)
                arr[i][j]='.';
        }
        int f=0;
        if (d%2==0)
        {
            for (int i=d-1;i>=0;i--)
            {
                if (f==0)
                {
                    for (int j=a;j<a+c;j++)
                    {
                        arr[i][j]=s[co];
                        co++;
                    }
                    f=1;
                }
                else
                {
                    for (int j=a+c-1;j>=a;j--)
                    {
                        arr[i][j]=s[co];
                        co++;
                    }
                    f=0;
                }

            }
        }
        else
        {
            for (int i=d-1;i>=0;i--)
            {
                if (f==1)
                {
                    for (int j=a;j<a+c;j++)
                    {
                        arr[i][j]=s[co];
                        co++;
                    }
                    f=0;
                    if(co==cc)
                        break;
                }
                else
                {
                    for (int j=a+c-1;j>=a;j--)
                    {
                        arr[i][j]=s[co];
                        co++;
                    }
                    f=1;
                    if(co==cc)
                        break;
                }

            }

        }
        int tm=0,bm=b-1,lm=0,rm=a-1;
        while(tm<=bm&&lm<=rm)
        {
            for (int j=rm;j>=lm;j--)
            {
                arr[tm][j]=s[co];
                co++;
            }
                    if(co==cc)
                        break;
            tm++;
            for (int j=tm;j<=bm;j++)
            {
                arr[j][lm]=s[co];
                co++;
            }
                                if(co==cc)
                        break;
            lm++;
            for (int j=lm;j<=rm;j++)
            {
                arr[bm][j]=s[co];
                co++;
            }
                                if(co==cc)
                        break;
            bm--;
            for (int j=bm;j>=tm;j--)
            {
                arr[j][rm]=s[co];
                co++;
            }
                                if(co==cc)
                        break;
            rm--;
        }
    }
    else
    {
        for (int i=b;i<d;i++)
        {
            for (int j=0;j<a;j++)
                arr[i][j]='.';
        }
        int f=0;
        if (b%2==0)
        {
            for (int i=b-1;i>=0;i--)
            {
                if (f==0)
                {
                    for (int j=a-1;j>=0;j--)
                    {
                        arr[i][j]=s[co];
                        co++;
                    }
                    f=1;
                                        if(co==cc)
                        break;
                }
                else
                {
                    for (int j=0;j<a;j++)
                    {
                        arr[i][j]=s[co];
                        co++;
                    }
                    f=0;
                                        if(co==cc)
                        break;
                }
            }
        }
        else
        {
            for (int i=d-1;i>=0;i--)
            {
                if (f==1)
                {
                    for (int j=a-1;j>=0;j--)
                    {
                        arr[i][j]=s[co];
                        co++;
                    }
                    f=0;
                                        if(co==cc)
                        break;
                }
                else
                {
                    for (int j=0;j<a;j++)
                    {
                        arr[i][j]=s[co];
                        co++;
                    }
                    f=1;
                                        if(co==cc)
                        break;
                }

            }

        }
        int tm=0,bm=d-1,lm=a,rm=a+c-1;
        while(tm<=bm&&lm<=rm)
        {
            for (int j=lm;j<=rm;j++)
            {
                arr[tm][j]=s[co];
                co++;
            }
            tm++;
                                if(co==cc)
                        break;
            for (int j=tm;j<=bm;j++)
            {
                //cout<<"lamba";
                arr[j][rm]=s[co];
                co++;
            }
            rm--;
                                if(co==cc)
                        break;
            for (int j=rm;j>=lm;j--)
            {
                arr[bm][j]=s[co];
                co++;
            }
            bm--;
                                if(co==cc)
                        break;
            for (int j=bm;j>=tm;j--)
            {
                arr[j][lm]=s[co];
                co++;
            }
            lm++;
                                if(co==cc)
                        break;
        }
    }
    cout<<"YES"<<endl;
    for (int i=0;i<max(b,d);i++)
    {
        for (int j=0;j<a+c;j++)
            cout<<arr[i][j];
        cout<<endl;
    }
    //cout<<arr[1][3]<<"da"<<endl;
}


#include<iostream>
#include<memory.h>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<limits.h>
#include<functional>
#include<map>
#include<vector>
#include<cstring>
#include<set>
#include<algorithm>
#include<cmath>
#include<stack>
using namespace std;

const int maxn = 500000 + 5;
int n, m, p;

struct node {
	int index;
	int link;
	char a;
	int nxt;
	int pre;
}nodes[maxn];

void ini(int n) {
	for (int i = 0; i < n; ++i) {
		nodes[i].nxt = i + 1;
		nodes[i].pre = i - 1;
	}
	nodes[0].pre = nodes[n - 1].nxt = -1;
	nodes[n].index = -1;
}

stack<node> st;

void insert(node & x) {
	if (st.empty() || x.a == '(')
		st.push(x);
	else {
		node temp = st.top();
		nodes[temp.index].link = x.index;
		x.link = temp.index;
		st.pop();
	}
}

int head, tail;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	string op;
	while (cin >> n >> m >> p) {
		getchar();
		getline(cin, s);
		ini(n);
		head = 0, tail = n-1;
		for (int i = 0; i < n; ++i) {
			nodes[i].a = s[i];
			nodes[i].index = i;
			insert(nodes[i]);
		}

		getline(cin, op);
		int cur = p - 1;
		for (int i = 0; i < m; ++i) {
			if (op[i] == 'L') cur = nodes[cur].pre;
			else if (op[i] == 'R') cur = nodes[cur].nxt;
			else {
				int a = min(nodes[cur].index, nodes[cur].link);
				int b = max(nodes[cur].index, nodes[cur].link);
				if (nodes[a].pre != -1)
					nodes[nodes[a].pre].nxt = nodes[nodes[b].nxt].index;
				else
					head = nodes[b].nxt;
				if (nodes[b].nxt != -1)
					nodes[nodes[b].nxt].pre = nodes[nodes[a].pre].index;
				else
					tail = nodes[a].pre;

				if (nodes[b].nxt != -1)
					cur = nodes[b].nxt;
				else
					cur = nodes[a].pre;
			}
		}

		if (head > tail) cout << endl;
		int ptr = head;
		while (ptr != tail) {
			cout << nodes[ptr].a;
			ptr = nodes[ptr].nxt;
		}
		cout << nodes[ptr].a << endl;

	}
	return 0;
}


#include<iostream>
#include<memory.h>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<limits.h>
#include<functional>
#include<map>
#include<vector>
#include<cstring>
#include<set>
#include<algorithm>
#include<cmath>
#include<stack>
using namespace std;

const int maxn = 500000 + 5;
int n, m, p;

struct node {
	int index;
	int link;
	char a;
	int nxt;
	int pre;
}nodes[maxn];

void ini(int n) {
	for (int i = 0; i < n; ++i) {
		nodes[i].nxt = i + 1;
		nodes[i].pre = i - 1;
	}
	nodes[0].pre = nodes[n - 1].nxt = -1;
	nodes[n].index = -1;
}

stack<node> st;

void insert(node & x) {
	if (st.empty() || x.a == '(')
		st.push(x);
	else {
		node temp = st.top();
		nodes[temp.index].link = x.index;
		x.link = temp.index;
		st.pop();
	}
}

int head, tail;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	string op;
	while (cin >> n >> m >> p) {
		getchar();
		getline(cin, s);
		ini(n);
		head = 0, tail = n-1;
		for (int i = 0; i < n; ++i) {
			nodes[i].a = s[i];
			nodes[i].index = i;
			insert(nodes[i]);
		}

		getline(cin, op);
		int cur = p - 1;
		for (int i = 0; i < m; ++i) {
			if (op[i] == 'L') cur = nodes[cur].pre;
			else if (op[i] == 'R') cur = nodes[cur].nxt;
			else {
				if (cur == -1) continue;
				int a = min(nodes[cur].index, nodes[cur].link);
				int b = max(nodes[cur].index, nodes[cur].link);

				if (nodes[a].pre == -1 && nodes[b].nxt == -1)
					head = tail = -1, cur = -1;//
				else if (nodes[a].pre == -1) {
					head = cur = nodes[b].nxt;
					nodes[nodes[b].nxt].pre = -1;
				}
				else if (nodes[b].nxt == -1) {
					tail = cur = nodes[a].pre;
					nodes[nodes[a].pre].nxt = -1;
				}

				else {
					nodes[nodes[a].pre].nxt=cur = nodes[nodes[b].nxt].index;
					nodes[nodes[b].nxt].pre = nodes[nodes[a].pre].index;
				}
			}
		}

		if (head == -1 || head > tail) cout << endl;
		int ptr = head;
		while (ptr != tail) {
			cout << nodes[ptr].a;
			ptr = nodes[ptr].nxt;
		}
		cout << nodes[ptr].a << endl;

	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int const N = 5e5 + 41;

int n, m, p, l[N], r[N], del[N], nxt[N], pr[N];
char s[N];
vector<int> st;

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
#endif
	scanf("%d %d %d",&n,&m,&p);
	for(int i=0;i<=n;++i){
		nxt[i] = i+1;
		pr[i] = i-1;
	}
	getchar();
	for(int i=1;i<=n;++i){
		s[i] = getchar();
		if(st.size() == 0){
			st.push_back(i);
		}else{
			if(s[i] == ')'){
				r[st.back()] = i;
				l[i] = st.back();
				st.pop_back();
			}else{
				st.push_back(i);
			}
		}
	}
	getchar();

	for(int i=0;i<m;++i){
		char t = getchar();
		if(t == 'L'){
			p = pr[p];
		}
		if(t == 'R'){
			p = nxt[p];
		}
		if(t == 'D'){
			if(s[p] == '('){
				int ri = r[p];
				int pb = pr[p];
				while(p <= ri){
					del[p] = 1;
					p = nxt[p];
				}
				int pa = p;
				nxt[pb] = pa;
				pr[pa] = pb;
				if(p > n){
					p = pb;
				}
			}else{
				int le = l[p];
				int pa = nxt[p];
				while(p >= le){
					del[p] = 1;
					p = pr[p];
				}
				int pb = p;
				nxt[pb] = pa;
				pr[pa] = pb;
				if(pa < n){
					p = pa;
				}
			}
		}
	}

	for(int i=1;i<=n;++i){
		if(!del[i]){
			printf("%c",s[i]);
		}
	}
	printf("\n");

	return 0;
}


#pragma comment(linker, "/STACK:108777216")
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <deque>
#include <map>
#include <algorithm>
using namespace std;

int const INT_INF = 1000000000;
int const MAX_CH = 1000000 + 100;

int n,m,p;
char st[MAX_CH],comm[MAX_CH];

int ms[MAX_CH], ms_len = 0;

int nxt_parent[MAX_CH], nxt_rank[MAX_CH];
int prv_parent[MAX_CH], prv_rank[MAX_CH];
int nxt_ancestor[MAX_CH], prv_ancestor[MAX_CH];
int nxt[MAX_CH], prv[MAX_CH];

int lnk[MAX_CH], is_lnk_FW[MAX_CH];
int is_del[MAX_CH];

int find_next(int v) {
	if (nxt_parent[v] != v)
		nxt_parent[v] = find_next(nxt_parent[v]);
	return nxt_parent[v];
}

void nxt_union(int a, int b) {
	int x = find_next(a);
	int y = find_next(b);

	if (nxt_rank[x] > nxt_rank[y]) {
		nxt_parent[y] = x;
		nxt_ancestor[x] = max(nxt_ancestor[x], nxt_ancestor[y]);
	}
	else {
		nxt_parent[x] = y;
		nxt_ancestor[y] = max(nxt_ancestor[y], nxt_ancestor[x]);
	}

	nxt_rank[y] += nxt_rank[x] == nxt_rank[y];
}

int find_prev(int v) {
	if (prv_parent[v] != v)
		prv_parent[v] = find_prev(prv_parent[v]);
	return prv_parent[v];
}

void prv_union(int a, int b) {
	int x = find_prev(a);
	int y = find_prev(b);

	if (prv_rank[x] > prv_rank[y]) {
		prv_parent[y] = x;
		prv_ancestor[x] = min(prv_ancestor[x], prv_ancestor[y]);
	}
	else {
		prv_parent[x] = y;
		prv_ancestor[y] = min(prv_ancestor[y], prv_ancestor[x]);
	}

	prv_rank[y] += prv_rank[x] == prv_rank[y];
}

int get_next(int v) {
	if (v == -1)
		return -1;
	return nxt_ancestor[find_next(v)];
}

int get_prev(int v) {
	if (v == -1)
		return -1;
	return prv_ancestor[find_prev(v)];
}

int main() {
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);

	gets(st);
	sscanf(st,"%d%d%d",&n,&m,&p);
	gets(st);
	gets(comm);

	for (int i=0; i+1<n; i++) {
		nxt[i] = i+1;
		nxt_parent[i] = i;
	}
	nxt[n-1] = -1;
	nxt_parent[n-1] = n-1;
	for (int i=0; i<n; i++)
		nxt_ancestor[i] = nxt[i];

	for (int i=1; i<n; i++) {
		prv[i] = i-1;
		prv_parent[i] = i;
	}
	prv[0] = -1;
	prv_parent[0] = 0;
	for (int i=0; i<n; i++)
		prv_ancestor[i] = prv[i];

	for (int i=0; i<n; i++)
		if (st[i] == '(') ms[ms_len++] = i;
		else {
			lnk[ms[ms_len-1]] = i;
			is_lnk_FW[ms[ms_len-1]] = 1;

			lnk[i] = ms[ms_len-1];

			ms_len--;
		}

	p--;
	for (int i=0; i<m; i++)
		if (comm[i] == 'R') {
			if (get_next(p) != -1)
				p = get_next(p);
		}
		else if (comm[i] == 'L') {
			if (get_prev(p) != -1)
				p = get_prev(p);
		}
		else if (comm[i] == 'D') {
			is_del[p] = 1;
			is_del[lnk[p]] = 1;

			int new_p = p;

			if (is_lnk_FW[p]) {
				if (get_next(lnk[p]) != -1)
					new_p = get_next(lnk[p]);
				else
					new_p = get_prev(p);
			}
			else {
				if (get_next(p) != -1)
					new_p = get_next(p);
				else
					new_p = get_prev(lnk[p]);
			}

			int a = lnk[p];
			int b = p;

			if (a > b)
				swap(a,b);

			if (get_prev(a) != -1)
				nxt_union(get_prev(a), b);
			nxt_union(a, b);

			if (get_next(b) != -1)
				prv_union(a, get_next(b));
			prv_union(a, b);

			p = new_p;
		}

	int mx_del = -1;
	for (int i=0; i<n; i++) {
		if (is_del[i]) {
			mx_del = max(mx_del, i);
			mx_del = max(mx_del, lnk[i]);
		}
		if (i > mx_del)
			mx_del = -1;
		if (i > mx_del)
			printf("%c",st[i]);
	}

	return 0;
}


#pragma comment(linker, "/STACK:108777216")
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <deque>
#include <map>
#include <algorithm>
using namespace std;

int const INT_INF = 1000000000;
int const MAX_CH = 1000000 + 100;

int n,m,p;
char st[MAX_CH],comm[MAX_CH];

int ms[MAX_CH], ms_len = 0;

int nxt_parent[MAX_CH], nxt_rank[MAX_CH];
int prv_parent[MAX_CH], prv_rank[MAX_CH];
int nxt_ancestor[MAX_CH], prv_ancestor[MAX_CH];
int nxt[MAX_CH], prv[MAX_CH];

int lnk[MAX_CH], is_lnk_FW[MAX_CH];
int is_del[MAX_CH];

int find_next(int v) {
	if (nxt_parent[v] != v)
		nxt_parent[v] = find_next(nxt_parent[v]);
	return nxt_parent[v];
}

void nxt_union(int a, int b) {
	int x = find_next(a);
	int y = find_next(b);

	if (nxt_rank[x] > nxt_rank[y]) {
		nxt_parent[y] = x;
		nxt_ancestor[x] = max(nxt_ancestor[x], nxt_ancestor[y]);
	}
	else {
		nxt_parent[x] = y;
		nxt_ancestor[y] = max(nxt_ancestor[y], nxt_ancestor[x]);
	}

	nxt_rank[y] += nxt_rank[x] == nxt_rank[y];
}

int find_prev(int v) {
	if (prv_parent[v] != v)
		prv_parent[v] = find_prev(prv_parent[v]);
	return prv_parent[v];
}

void prv_union(int a, int b) {
	int x = find_prev(a);
	int y = find_prev(b);

	if (prv_rank[x] > prv_rank[y]) {
		prv_parent[y] = x;
		prv_ancestor[x] = min(prv_ancestor[x], prv_ancestor[y]);
	}
	else {
		prv_parent[x] = y;
		prv_ancestor[y] = min(prv_ancestor[y], prv_ancestor[x]);
	}

	prv_rank[y] += prv_rank[x] == prv_rank[y];
}

int get_next(int v) {
	if (v == -1)
		return -1;
	return nxt_ancestor[find_next(v)];
}

int get_prev(int v) {
	if (v == -1)
		return -1;
	return prv_ancestor[find_prev(v)];
}

int main() {
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);

	gets(st);
	sscanf(st,"%d%d%d",&n,&m,&p);
	gets(st);
	gets(comm);

	for (int i=0; i+1<n; i++) {
		nxt[i] = i+1;
		nxt_parent[i] = i;
	}
	nxt[n-1] = -1;
	nxt_parent[n-1] = n-1;
	for (int i=0; i<n; i++)
		nxt_ancestor[i] = nxt[i];

	for (int i=1; i<n; i++) {
		prv[i] = i-1;
		prv_parent[i] = i;
	}
	prv[0] = -1;
	prv_parent[0] = 0;
	for (int i=0; i<n; i++)
		prv_ancestor[i] = prv[i];

	for (int i=0; i<n; i++)
		if (st[i] == '(') ms[ms_len++] = i;
		else {
			lnk[ms[ms_len-1]] = i;
			is_lnk_FW[ms[ms_len-1]] = 1;

			lnk[i] = ms[ms_len-1];

			ms_len--;
		}

	p--;
	for (int i=0; i<m; i++)
		if (comm[i] == 'R') {
			if (get_next(p) != -1)
				p = get_next(p);
		}
		else if (comm[i] == 'L') {
			if (get_prev(p) != -1)
				p = get_prev(p);
		}
		else if (comm[i] == 'D') {
			is_del[p] = 1;
			is_del[lnk[p]] = 1;

			int new_p = p;

			if (is_lnk_FW[p]) {
				if (get_next(lnk[p]) != -1)
					new_p = get_next(lnk[p]);
				else
					new_p = get_prev(p);
			}
			else {
				if (get_next(p) != -1)
					new_p = get_next(p);
				else
					new_p = get_prev(lnk[p]);
			}

			int a = lnk[p];
			int b = p;

			if (a > b)
				swap(a,b);

			if (a > 0)
				nxt_union(a-1, b);
			nxt_union(a, b);
			nxt_union(b, b);

			prv_union(a, a);
			if (b + 1 < n)
				prv_union(a, b+1);
			prv_union(a, b);

			p = new_p;
		}

	int mx_del = -1;
	for (int i=0; i<n; i++) {
		if (is_del[i]) {
			mx_del = max(mx_del, i);
			mx_del = max(mx_del, lnk[i]);
		}
		if (i > mx_del)
			mx_del = -1;
		if (i > mx_del)
			printf("%c",st[i]);
	}

	return 0;
}


#pragma comment(linker, "/STACK:108777216")
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <deque>
#include <map>
#include <algorithm>
using namespace std;

int const INT_INF = 1000000000;
int const MAX_CH = 1000000 + 100;

int n,m,p;
char st[MAX_CH],comm[MAX_CH];

int ms[MAX_CH], ms_len = 0;

int nxt_parent[MAX_CH], nxt_rank[MAX_CH];
int prv_parent[MAX_CH], prv_rank[MAX_CH];
int nxt_ancestor[MAX_CH], prv_ancestor[MAX_CH];
int nxt[MAX_CH], prv[MAX_CH];

int lnk[MAX_CH], is_lnk_FW[MAX_CH];
int is_del[MAX_CH];

int find_next(int v) {
	if (nxt_parent[v] != v)
		nxt_parent[v] = find_next(nxt_parent[v]);
	return nxt_parent[v];
}

void nxt_union(int a, int b) {
	int x = find_next(a);
	int y = find_next(b);

	if (nxt_rank[x] > nxt_rank[y]) {
		nxt_parent[y] = x;
		nxt_ancestor[x] = max(nxt_ancestor[x], nxt_ancestor[y]);
	}
	else {
		nxt_parent[x] = y;
		nxt_ancestor[y] = max(nxt_ancestor[y], nxt_ancestor[x]);
	}

	nxt_rank[y] += nxt_rank[x] == nxt_rank[y];
}

int find_prev(int v) {
	if (prv_parent[v] != v)
		prv_parent[v] = find_prev(prv_parent[v]);
	return prv_parent[v];
}

void prv_union(int a, int b) {
	int x = find_prev(a);
	int y = find_prev(b);

	if (prv_rank[x] > prv_rank[y]) {
		prv_parent[y] = x;
		prv_ancestor[x] = min(prv_ancestor[x], prv_ancestor[y]);
	}
	else {
		prv_parent[x] = y;
		prv_ancestor[y] = min(prv_ancestor[y], prv_ancestor[x]);
	}

	prv_rank[y] += prv_rank[x] == prv_rank[y];
}

int get_next(int v) {
	if (v == -1)
		return -1;
	return nxt[nxt_ancestor[find_next(v)]];
}

int get_prev(int v) {
	if (v == -1)
		return -1;
	return prv[prv_ancestor[find_prev(v)]];
}

int main() {
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);

	gets(st);
	sscanf(st,"%d%d%d",&n,&m,&p);
	gets(st);
	gets(comm);

	for (int i=0; i+1<n; i++) {
		nxt[i] = i+1;
		nxt_parent[i] = i;
	}
	nxt[n-1] = -1;
	nxt_parent[n-1] = n-1;
	for (int i=0; i<n; i++)
		nxt_ancestor[i] = i;

	for (int i=1; i<n; i++) {
		prv[i] = i-1;
		prv_parent[i] = i;
	}
	prv[0] = -1;
	prv_parent[0] = 0;
	for (int i=0; i<n; i++)
		prv_ancestor[i] = i;

	for (int i=0; i<n; i++)
		if (st[i] == '(') ms[ms_len++] = i;
		else {
			lnk[ms[ms_len-1]] = i;
			is_lnk_FW[ms[ms_len-1]] = 1;

			lnk[i] = ms[ms_len-1];

			ms_len--;
		}

	p--;
	for (int i=0; i<m; i++)
		if (comm[i] == 'R') {
			if (get_next(p) != -1)
				p = get_next(p);
		}
		else if (comm[i] == 'L') {
			if (get_prev(p) != -1)
				p = get_prev(p);
		}
		else if (comm[i] == 'D') {
			is_del[p] = 1;
			is_del[lnk[p]] = 1;

			int new_p = p;

			if (is_lnk_FW[p]) {
				if (get_next(lnk[p]) != -1)
					new_p = get_next(lnk[p]);
				else
					new_p = get_prev(p);
			}
			else {
				if (get_next(p) != -1)
					new_p = get_next(p);
				else
					new_p = get_prev(lnk[p]);
			}

			int a = lnk[p];
			int b = p;

			if (a > b)
				swap(a,b);

			if (get_prev(a) != -1)
				nxt_union(get_prev(a), b);
			nxt_union(a, b);

			if (get_next(b) != -1)
				prv_union(a, get_next(b));
			prv_union(a, b);

			p = new_p;
		}

	int mx_del = -1;
	for (int i=0; i<n; i++) {
		if (is_del[i]) {
			mx_del = max(mx_del, i);
			mx_del = max(mx_del, lnk[i]);
		}
		if (i > mx_del)
			mx_del = -1;
		if (i > mx_del)
			printf("%c",st[i]);
	}

	return 0;
}


//#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:2899887000")
#include <cstdio>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <bitset>
#include <map>
#include <iostream>
#include <iomanip>
#include <stack>
#include <string>
#include <random>
#include <list>
#include <functional>
#include <utility>
#include <numeric>
#include <cstring>
#include <memory>

using namespace std;

#define LOCAL 0
#define ll long long
#define uint unsigned int
#define get_time (int)(clock() * 1000.0 / CLOCKS_PER_SEC)

const int MAXN = 500000 + 5;

int main()
{
#if LOCAL == 1
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
#endif

    int n, m, pos;
    scanf("%d %d %d", &n, &m, &pos);

    char buf[MAXN] = {};
    scanf("%s", 1 + buf);

    char com[MAXN] = {};
    scanf("%s", com);

    vector <int> par(1 + n + 1);
    vector <int> right(1 + n + 1);
    vector <int> left(1 + n + 1);

    stack <int> st;

    for (int i = 1; i <= n; ++i)
    {
        if (buf[i] == '(')
            st.push(i);
        else
        {
            int id = st.top();
            st.pop();
            par[i] = id;
            par[id] = i;
        }

        left[i] = i - 1;
        right[i] = i + 1;
    }

    for (int i = 0; i < m; ++i)
    {
        if (com[i] == 'R')
            pos = right[pos];
        else if (com[i] == 'L')
            pos = left[pos];
        else if (com[i] == 'D')
        {
            int L = pos;
            int R = par[pos];
            if (buf[pos] == ')')
                swap(L, R);
            left[right[R]] = left[L];
            right[left[L]] = right[R];
            pos = right[R];
            if (pos == n + 1)
                pos = left[L];
        }
    }

    while (left[pos] != 0)
        pos = left[pos];

    while (pos != n + 1)
    {
        putc(buf[pos], stdout);
        pos = right[pos];
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
const int inf = 2147483647;
const double PI = acos(-1.0);
const double e = 2.718281828459;
const int mod = 1000000007;
typedef long long LL;
#pragma comment(linker, "/STACK:102400000,102400000")
//freopen("in.txt","r",stdin); //输入重定向,输入数据将从in.txt文件中读取
//freopen("out.txt","w",stdout); //输出重定向,输出数据将保存在out.txt文件中cin
char s[500005], x[500005];
struct node
{
	int id;
	char str;
}w;
vector<node>vc;
vector<int>mp[500005];
int vis[500005];
int main()
{
	int n, m, p, i, j;
	while (cin >> n >> m >> p)
	{
		scanf("%s%s", s + 1, x);
		vc.clear();
		for (i = 1; s[i]; ++i)
		{
			w.id = i;
			w.str = s[i];
			if (vc.size() == 0)
				vc.push_back(w);
			else
			{
				node q = vc.back();
				if (q.str != s[i])
				{
					mp[q.id].push_back(i);
					mp[i].push_back(q.id);
					vc.pop_back();
				}
				else
				{
					vc.push_back(w);
				}
			}
		}
		memset(vis, 0, sizeof(vis));
		int pos = p;
		for (i = 0; x[i]; ++i)
		{
			if (x[i] == 'R')
			{
				pos++;
				while (pos <= n)
				{
					if (!vis[pos])
						break;
					pos++;
				}
			}
			else if (x[i] == 'L')
			{
				pos--;
				while (pos >= 1)
				{
					if (!vis[pos])
						break;
					pos--;
				}
			}
			else if (x[i] == 'D')
			{
				vis[pos] = 1;
				vis[mp[pos][0]] = 1;
				if (mp[pos][0] == n || pos == n)
				{
					while (pos)
					{
						if (!vis[pos])
						{
							break;
						}
						pos--;
					}
				}
				else
				{
					int pp = pos;
					pos = max(mp[pos][0], pos) + 1;
					while (pos <= n)
					{
						if (!vis[pos])
						{
							break;
						}
						pos++;
					}
					if (pos > n)
					{
						while (pp)
						{
							if (!vis[pp])
							{
								break;
							}
							pp--;
						}
						pos = pp;
					}
				}
			}
			//cout << pos << endl;
		}
		for (i = 1; s[i]; ++i)
		{
			if (!vis[i])
				printf("%c", s[i]);
			else
			{
				i = mp[i][0];
			}
		}
		printf("\n");

	}
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
const int inf = 2147483647;
const double PI = acos(-1.0);
const double e = 2.718281828459;
const int mod = 1000000007;
typedef long long LL;
#pragma comment(linker, "/STACK:102400000,102400000")
//freopen("in.txt","r",stdin); //输入重定向,输入数据将从in.txt文件中读取
//freopen("out.txt","w",stdout); //输出重定向,输出数据将保存在out.txt文件中cin
char s[500005], x[500005];
struct node
{
	int id;
	char str;
}w;
vector<node>vc;
vector<int>mp[500005];
int vis[500005];
int main()
{
	int n, m, p, i, j;
	while (cin >> n >> m >> p)
	{
		scanf("%s%s", s + 1, x);
		vc.clear();
		for (i = 1; s[i]; ++i)
		{
			w.id = i;
			w.str = s[i];
			if (vc.size() == 0)
				vc.push_back(w);
			else
			{
				node q = vc.back();
				if (q.str != s[i])
				{
					mp[q.id].push_back(i);
					mp[i].push_back(q.id);
					vc.pop_back();
				}
				else
				{
					vc.push_back(w);
				}
			}
		}
		memset(vis, 0, sizeof(vis));
		int pos = p;
		for (i = 0; x[i]; ++i)
		{
			if (x[i] == 'R')
			{
				pos++;
				while (pos <= n)
				{
					if (!vis[pos])
						break;
					else
					{
						pos = max(mp[pos][0], pos) + 1;
					}

				}
			}
			else if (x[i] == 'L')
			{
				pos--;
				while (pos >= 1)
				{
					if (!vis[pos])
						break;
					else
					{
						pos = min(pos, mp[pos][0]) - 1;
					}
				}
			}
			else if (x[i] == 'D')
			{
				vis[pos] = 1;
				vis[mp[pos][0]] = 1;
				if (mp[pos][0] == n || pos == n)
				{
					pos = min(pos, mp[pos][0]);
					pos--;
					while (pos >= 1)
					{
						if (!vis[pos])
						{
							break;
						}
						pos--;
					}
				}
				else
				{
					int pp = pos;
					pos = max(mp[pos][0], pos) + 1;
					while (pos <= n)
					{
						if (!vis[pos])
						{
							break;
						}
						pos++;
					}
					if (pos > n)
					{
						while (pp >= 1)
						{
							if (!vis[pp])
							{
								break;
							}
							pp--;
						}
						pos = pp;
					}
				}
			}
			//cout << pos << endl;
		}
		for (i = 1; s[i]; ++i)
		{
			if (!vis[i])
				printf("%c", s[i]);
			else
			{
				i = mp[i][0];
			}
		}
		printf("\n");

	}
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
const int inf = 2147483647;
const double PI = acos(-1.0);
const double e = 2.718281828459;
const int mod = 1000000007;
typedef long long LL;
#pragma comment(linker, "/STACK:102400000,102400000")
//freopen("in.txt","r",stdin); //输入重定向,输入数据将从in.txt文件中读取
//freopen("out.txt","w",stdout); //输出重定向,输出数据将保存在out.txt文件中cin
char s[500005], x[500005];
set<int>st;
struct node
{
	int id;
	char str;
}w;
vector<node>vc;
vector<int>mp[500005];
int vis[500005];
int main()
{
	int n, m, p, i, j;
	while (cin >> n >> m >> p)
	{
		scanf("%s%s", s + 1, x);
		vc.clear();
		st.clear();
		for (i = 1; s[i]; ++i)
		{
			st.insert(i);
			w.id = i;
			w.str = s[i];
			if (vc.size() == 0)
				vc.push_back(w);
			else
			{
				node q = vc.back();
				if (q.str != s[i])
				{
					mp[q.id].push_back(i);
					mp[i].push_back(q.id);
					vc.pop_back();
				}
				else
				{
					vc.push_back(w);
				}
			}
		}
		memset(vis, 0, sizeof(vis));
		int pos = p;
		for (i = 0; x[i]; ++i)
		{
			if (x[i] == 'R')
			{
				int pp = pos;
				pos = *st.lower_bound(pos + 1);
			}
			else if (x[i] == 'L')
			{
				int pp = pos;
				pos = *(--st.lower_bound(pos));
			}
			else if (x[i] == 'D')
			{

				for (int j = min(pos, mp[pos][0]); j <= max(pos, mp[pos][0]); ++j)
				{
					if (vis[j])
						j = mp[j][0]+ 1;
					st.erase(j);
				}
				vis[pos] = 1;
				vis[mp[pos][0]] = 1;
				if (mp[pos][0] == n || pos == n)
				{
					pos = *st.rbegin();
				}
				else
				{
					pos = *st.lower_bound(pos + 1);
				}
			}
			//cout << pos << endl;
		}
		for (i = 1; s[i]; ++i)
		{
			if (!vis[i])
				printf("%c", s[i]);
			else
			{
				i = mp[i][0];
			}
		}
		printf("\n");

	}
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
const int inf = 2147483647;
const double PI = acos(-1.0);
const double e = 2.718281828459;
const int mod = 1000000007;
typedef long long LL;
#pragma comment(linker, "/STACK:102400000,102400000")
//freopen("in.txt","r",stdin); //输入重定向,输入数据将从in.txt文件中读取
//freopen("out.txt","w",stdout); //输出重定向,输出数据将保存在out.txt文件中cin
char s[500005], x[500005];
set<int>st;
struct node
{
	int id;
	char str;
}w;
vector<node>vc;
vector<int>mp[500005];
int vis[500005];
int main()
{
	int n, m, p, i, j;
	while (cin >> n >> m >> p)
	{
		scanf("%s%s", s + 1, x);
		vc.clear();
		st.clear();
		for (i = 1; s[i]; ++i)
		{
			st.insert(i);
			w.id = i;
			w.str = s[i];
			if (vc.size() == 0)
				vc.push_back(w);
			else
			{
				node q = vc.back();
				if (q.str != s[i])
				{
					mp[q.id].push_back(i);
					mp[i].push_back(q.id);
					vc.pop_back();
				}
				else
				{
					vc.push_back(w);
				}
			}
		}
		memset(vis, 0, sizeof(vis));
		int pos = p;
		for (i = 0; x[i]; ++i)
		{
			if (x[i] == 'R')
			{
				int pp = pos;
				pos = *st.lower_bound(pos + 1);
			}
			else if (x[i] == 'L')
			{
				int pp = pos;
				pos = *(--st.lower_bound(pos));
			}
			else if (x[i] == 'D')
			{
				int end = *st.rbegin();
				for (int j = min(pos, mp[pos][0]); j <= max(pos, mp[pos][0]); ++j)
				{
					if (vis[j])
						j = mp[j][0]+ 1;
					st.erase(j);
				}
				vis[pos] = 1;
				vis[mp[pos][0]] = 1;
				if (mp[pos][0] == end || pos == end)
				{
					pos = *st.rbegin();
				}
				else
				{
					pos = *st.lower_bound(pos + 1);
				}
			}
			//cout << pos << endl;
		}
		for (i = 1; s[i]; ++i)
		{
			if (!vis[i])
				printf("%c", s[i]);
			else
			{
				i = mp[i][0];
			}
		}
		printf("\n");

	}
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
const int inf = 2147483647;
const double PI = acos(-1.0);
const double e = 2.718281828459;
const int mod = 1000000007;
typedef long long LL;
#pragma comment(linker, "/STACK:102400000,102400000")
//freopen("in.txt","r",stdin); //输入重定向,输入数据将从in.txt文件中读取
//freopen("out.txt","w",stdout); //输出重定向,输出数据将保存在out.txt文件中cin
char s[500005], x[500005];
struct node
{
	int id;
	char str;
}w;
vector<node>vc;
vector<int>mp[500005];
int vis[500005];
int main()
{
	int n, m, p, i, j;
	while (cin >> n >> m >> p)
	{
		scanf("%s%s", s + 1, x);
		vc.clear();
		for (i = 1; s[i]; ++i)
		{
			w.id = i;
			w.str = s[i];
			if (vc.size() == 0)
				vc.push_back(w);
			else
			{
				node q = vc.back();
				if (q.str != s[i])
				{
					mp[q.id].push_back(i);
					mp[i].push_back(q.id);
					vc.pop_back();
				}
				else
				{
					vc.push_back(w);
				}
			}
		}
		memset(vis, 0, sizeof(vis));
		int pos = p;
		for (i = 0; x[i]; ++i)
		{
			if (x[i] == 'R')
			{
				pos++;
				while (pos <= n)
				{
					if (!vis[pos])
						break;
					pos++;
				}
			}
			else if (x[i] == 'L')
			{
				pos--;
				while (pos >= 1)
				{
					if (!vis[pos])
						break;
					pos--;
				}
			}
			else if (x[i] == 'D')
			{
				vis[pos] = 1;
				vis[mp[pos][0]] = 1;
				if (mp[pos][0] == n || pos == n)
				{
					while (pos)
					{
						if (!vis[pos])
						{
							break;
						}
						pos--;
					}
				}
				else
				{
					int pp = pos;
					pos = mp[pos][0] + 1;
					while (pos <= n)
					{
						if (!vis[pos])
						{
							break;
						}
						pos++;
					}
					if (pos > n)
					{
						while (pp)
						{
							if (!vis[pp])
							{
								break;
							}
							pp--;
						}
						pos = pp;
					}
				}
			}
			//cout << pos << endl;
		}
		for (i = 1; s[i]; ++i)
		{
			if (!vis[i])
				printf("%c", s[i]);
			else
			{
				i = mp[i][0];
			}
		}
		printf("\n");

	}
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
const int inf = 2147483647;
const double PI = acos(-1.0);
const double e = 2.718281828459;
const int mod = 1000000007;
typedef long long LL;
#pragma comment(linker, "/STACK:102400000,102400000")
//freopen("in.txt","r",stdin); //输入重定向,输入数据将从in.txt文件中读取
//freopen("out.txt","w",stdout); //输出重定向,输出数据将保存在out.txt文件中cin
char s[500005], x[500005];
set<int>st;
struct node
{
	int id;
	char str;
}w;
vector<node>vc;
vector<int>mp[500005];
int vis[500005];
int main()
{
	int n, m, p, i, j;
	while (cin >> n >> m >> p)
	{
		scanf("%s%s", s + 1, x);
		vc.clear();
		st.clear();
		for (i = 1; s[i]; ++i)
		{
			st.insert(i);
			w.id = i;
			w.str = s[i];
			if (vc.size() == 0)
				vc.push_back(w);
			else
			{
				node q = vc.back();
				if (q.str != s[i])
				{
					mp[q.id].push_back(i);
					mp[i].push_back(q.id);
					vc.pop_back();
				}
				else
				{
					vc.push_back(w);
				}
			}
		}
		memset(vis, 0, sizeof(vis));
		int pos = p;
		for (i = 0; x[i]; ++i)
		{
			if (x[i] == 'R')
			{
				int pp = pos;
				pos = *st.lower_bound(pos + 1);
			}
			else if (x[i] == 'L')
			{
				int pp = pos;
				pos = *(--st.lower_bound(pos - 1));
			}
			else if (x[i] == 'D')
			{

				for (int j = min(pos, mp[pos][0]); j <= max(pos, mp[pos][0]); ++j)
				{
					if (vis[j])
						j = mp[j][0]+ 1;
					st.erase(j);
				}
				vis[pos] = 1;
				vis[mp[pos][0]] = 1;
				if (mp[pos][0] == n || pos == n)
				{
					pos = *st.rbegin();
				}
				else
				{
					pos = *st.lower_bound(pos + 1);
				}
			}
			//cout << pos << endl;
		}
		for (i = 1; s[i]; ++i)
		{
			if (!vis[i])
				printf("%c", s[i]);
			else
			{
				i = mp[i][0];
			}
		}
		printf("\n");

	}
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
const int inf = 2147483647;
const double PI = acos(-1.0);
const double e = 2.718281828459;
const int mod = 1000000007;
typedef long long LL;
#pragma comment(linker, "/STACK:102400000,102400000")
//freopen("in.txt","r",stdin); //输入重定向,输入数据将从in.txt文件中读取
//freopen("out.txt","w",stdout); //输出重定向,输出数据将保存在out.txt文件中cin
char s[500005], x[500005];
struct node
{
	int id;
	char str;
}w;
vector<node>vc;
vector<int>mp[500005];
int vis[500005];
int main()
{
	int n, m, p, i, j;
	while (cin >> n >> m >> p)
	{
		scanf("%s%s", s + 1, x);
		vc.clear();
		for (i = 1; s[i]; ++i)
		{
			w.id = i;
			w.str = s[i];
			if (vc.size() == 0)
				vc.push_back(w);
			else
			{
				node q = vc.back();
				if (q.str != s[i])
				{
					mp[q.id].push_back(i);
					mp[i].push_back(q.id);
					vc.pop_back();
				}
				else
				{
					vc.push_back(w);
				}
			}
		}
		memset(vis, 0, sizeof(vis));
		int pos = p;
		for (i = 0; x[i]; ++i)
		{
			if (x[i] == 'R')
			{
				pos++;
				while (pos <= n)
				{
					if (!vis[pos])
						break;
					pos++;
				}
			}
			else if (x[i] == 'L')
			{
				pos--;
				while (pos >= 1)
				{
					if (!vis[pos])
						break;
					pos--;
				}
			}
			else if (x[i] == 'D')
			{
				vis[pos] = 1;
				vis[mp[pos][0]] = 1;
				if (mp[pos][0] == n || pos == n)
				{
					pos = min(pos, mp[pos][0]);
					pos--;
					while (pos >= 1)
					{
						if (!vis[pos])
						{
							break;
						}
						pos--;
					}
				}
				else
				{
					int pp = pos;
					pos = max(mp[pos][0], pos) + 1;
					while (pos <= n)
					{
						if (!vis[pos])
						{
							break;
						}
						pos++;
					}
					if (pos > n)
					{
						while (pp >= 1)
						{
							if (!vis[pp])
							{
								break;
							}
							pp--;
						}
						pos = pp;
					}
				}
			}
			//cout << pos << endl;
		}
		for (i = 1; s[i]; ++i)
		{
			if (!vis[i])
				printf("%c", s[i]);
			else
			{
				i = mp[i][0];
			}
		}
		printf("\n");

	}
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
const int inf = 2147483647;
const double PI = acos(-1.0);
const double e = 2.718281828459;
const int mod = 1000000007;
typedef long long LL;
#pragma comment(linker, "/STACK:102400000,102400000")
//freopen("in.txt","r",stdin); //输入重定向,输入数据将从in.txt文件中读取
//freopen("out.txt","w",stdout); //输出重定向,输出数据将保存在out.txt文件中cin
char s[500005], x[500005];
struct node
{
	int id;
	char str;
}w;
vector<node>vc;
vector<int>mp[500005];
int vis[500005];
int main()
{
	int n, m, p, i, j;
	while (cin >> n >> m >> p)
	{
		scanf("%s%s", s + 1, x);
		vc.clear();
		for (i = 1; s[i]; ++i)
		{
			w.id = i;
			w.str = s[i];
			if (vc.size() == 0)
				vc.push_back(w);
			else
			{
				node q = vc.back();
				if (q.str != s[i])
				{
					mp[q.id].push_back(i);
					mp[i].push_back(q.id);
					vc.pop_back();
				}
				else
				{
					vc.push_back(w);
				}
			}
		}
		memset(vis, 0, sizeof(vis));
		int pos = p;
		for (i = 0; x[i]; ++i)
		{
			if (x[i] == 'R')
			{
				int pp = pos;
				pos++;
				while (pos <= n)
				{
					if (!vis[pos])
						break;
					else
					{
						pos = max(mp[pos][0], pos) + 1;
					}
				}
				if (pos > n)
				{
					pos = pp;
				}
			}
			else if (x[i] == 'L')
			{
				int pp = pos;
				pos--;
				while (pos >= 1)
				{
					if (!vis[pos])
						break;
					else
					{
						pos = min(pos, mp[pos][0]) - 1;
					}
				}
				if (pos < 1)
				{
					pos = pp;
				}
			}
			else if (x[i] == 'D')
			{
				vis[pos] = 1;
				vis[mp[pos][0]] = 1;
				if (mp[pos][0] == n || pos == n)
				{
					pos = min(pos, mp[pos][0]);
					pos--;
					while (pos >= 1)
					{
						if (!vis[pos])
						{
							break;
						}
						pos--;
					}
				}
				else
				{
					int pp = pos;
					pos = max(mp[pos][0], pos) + 1;
					while (pos <= n)
					{
						if (!vis[pos])
						{
							break;
						}
						pos++;
					}
					if (pos > n)
					{
						while (pp >= 1)
						{
							if (!vis[pp])
							{
								break;
							}
							pp--;
						}
						pos = pp;
					}
				}
			}
			//cout << pos << endl;
		}
		for (i = 1; s[i]; ++i)
		{
			if (!vis[i])
				printf("%c", s[i]);
			else
			{
				i = mp[i][0];
			}
		}
		printf("\n");

	}
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
const int inf = 2147483647;
const double PI = acos(-1.0);
const double e = 2.718281828459;
const int mod = 1000000007;
typedef long long LL;
#pragma comment(linker, "/STACK:102400000,102400000")
//freopen("in.txt","r",stdin); //输入重定向,输入数据将从in.txt文件中读取
//freopen("out.txt","w",stdout); //输出重定向,输出数据将保存在out.txt文件中cin
char s[500005], x[500005];
struct node
{
	int id;
	char str;
}w;
vector<node>vc;
vector<int>mp[500005];
int vis[500005];
int main()
{
	int n, m, p, i, j;
	while (cin >> n >> m >> p)
	{
		scanf("%s%s", s + 1, x);
		vc.clear();
		for (i = 1; s[i]; ++i)
		{
			w.id = i;
			w.str = s[i];
			if (vc.size() == 0)
				vc.push_back(w);
			else
			{
				node q = vc.back();
				if (q.str != s[i])
				{
					mp[q.id].push_back(i);
					mp[i].push_back(q.id);
					vc.pop_back();
				}
				else
				{
					vc.push_back(w);
				}
			}
		}
		memset(vis, 0, sizeof(vis));
		int pos = p;
		for (i = 0; x[i]; ++i)
		{
			if (x[i] == 'R')
			{
				int pp = pos;
				pos++;
				while (pos <= n)
				{
					if (!vis[pos])
						break;
					else
					{
						pos = max(mp[pos][0], pos) + 1;
					}
				}
				if (pos > n)
				{
					pos = pp;
				}
			}
			else if (x[i] == 'L')
			{
				int pp = pos;
				pos--;
				while (pos >= 1)
				{
					if (!vis[pos])
						break;
					else
					{
						pos = min(pos, mp[pos][0]) - 1;
					}
				}
				if (pos < 1)
				{
					pos = pp;
				}
			}
			else if (x[i] == 'D')
			{
				vis[pos] = 1;
				vis[mp[pos][0]] = 1;
				if (mp[pos][0] == n || pos == n)
				{
					pos = min(pos, mp[pos][0]);
					pos--;
					while (pos >= 1)
					{
						if (!vis[pos])
						{
							break;
						}
						else
						{
							pos = min(pos, mp[pos][0]) - 1;
						}
					}
				}
				else
				{
					int pp = pos;
					pos = max(mp[pos][0], pos) + 1;
					while (pos <= n)
					{
						if (!vis[pos])
						{
							break;
						}
						else
							pos = max(mp[pos][0], pos) + 1;
					}
					if (pos > n)
					{
						while (pp >= 1)
						{
							if (!vis[pp])
							{
								break;
							}
							else
								pp = min(pp, mp[pp][0]) - 1;
						}
						pos = pp;
					}
				}
			}
			//cout << pos << endl;
		}
		for (i = 1; s[i]; ++i)
		{
			if (!vis[i])
				printf("%c", s[i]);
			else
			{
				i = mp[i][0];
			}
		}
		printf("\n");

	}
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
const int inf = 2147483647;
const double PI = acos(-1.0);
const double e = 2.718281828459;
const int mod = 1000000007;
typedef long long LL;
#pragma comment(linker, "/STACK:102400000,102400000")
//freopen("in.txt","r",stdin); //输入重定向,输入数据将从in.txt文件中读取
//freopen("out.txt","w",stdout); //输出重定向,输出数据将保存在out.txt文件中cin
char s[500005], x[500005];
set<int>st;
struct node
{
	int id;
	char str;
}w;
vector<node>vc;
vector<int>mp[500005];
int vis[500005];
int main()
{
	int n, m, p, i, j;
	while (cin >> n >> m >> p)
	{
		scanf("%s%s", s + 1, x);
		vc.clear();
		st.clear();
		for (i = 1; s[i]; ++i)
		{
			st.insert(i);
			w.id = i;
			w.str = s[i];
			if (vc.size() == 0)
				vc.push_back(w);
			else
			{
				node q = vc.back();
				if (q.str != s[i])
				{
					mp[q.id].push_back(i);
					mp[i].push_back(q.id);
					vc.pop_back();
				}
				else
				{
					vc.push_back(w);
				}
			}
		}
		memset(vis, 0, sizeof(vis));
		int pos = p;
		for (i = 0; x[i]; ++i)
		{
			if (x[i] == 'R')
			{
				int pp = pos;
				pos = *st.lower_bound(pos + 1);
			}
			else if (x[i] == 'L')
			{
				int pp = pos;
				pos = *(--st.lower_bound(pos));
			}
			else if (x[i] == 'D')
			{
				int end = *st.rbegin();
				for (int j = min(pos, mp[pos][0]); j <= max(pos, mp[pos][0]); ++j)
				{
					while(vis[j])
						j = max(mp[j][0], j)+ 1;
					st.erase(j);
				}
				vis[pos] = 1;
				vis[mp[pos][0]] = 1;
				if (mp[pos][0] == end || pos == end)
				{
					pos = *st.rbegin();
				}
				else
				{
					pos = *st.lower_bound(pos + 1);
				}
			}
			//cout << pos << endl;
		}
		for (i = 1; s[i]; ++i)
		{
			if (!vis[i])
				printf("%c", s[i]);
			else
			{
				i = mp[i][0];
			}
		}
		printf("\n");

	}
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
const int inf = 2147483647;
const double PI = acos(-1.0);
const double e = 2.718281828459;
const int mod = 1000000007;
typedef long long LL;
#pragma comment(linker, "/STACK:102400000,102400000")
//freopen("in.txt","r",stdin); //输入重定向,输入数据将从in.txt文件中读取
//freopen("out.txt","w",stdout); //输出重定向,输出数据将保存在out.txt文件中cin
char s[500005], x[500005];
set<int>st;
struct node
{
	int id;
	char str;
}w;
vector<node>vc;
vector<int>mp[500005];
int vis[500005];
int main()
{
	int n, m, p, i, j;
	while (cin >> n >> m >> p)
	{
		scanf("%s%s", s + 1, x);
		vc.clear();
		st.clear();
		for (i = 1; s[i]; ++i)
		{
			st.insert(i);
			w.id = i;
			w.str = s[i];
			if (vc.size() == 0)
				vc.push_back(w);
			else
			{
				node q = vc.back();
				if (q.str != s[i])
				{
					mp[q.id].push_back(i);
					mp[i].push_back(q.id);
					vc.pop_back();
				}
				else
				{
					vc.push_back(w);
				}
			}
		}
		memset(vis, 0, sizeof(vis));
		int pos = p;
		for (i = 0; x[i]; ++i)
		{
			if (x[i] == 'R')
			{
				int pp = pos;
				pos = *st.lower_bound(pos + 1);
			}
			else if (x[i] == 'L')
			{
				int pp = pos;
				pos = *(--st.lower_bound(pos - 1));
			}
			else if (x[i] == 'D')
			{
				vis[pos] = 1;
				vis[mp[pos][0]] = 1;
				for (int j = min(pos, mp[pos][0]); j <= max(pos, mp[pos][0]); ++j)
				{
					if (vis[j])
						j = mp[j][0]+ 1;
					st.erase(j);
				}
				if (mp[pos][0] == n || pos == n)
				{
					pos = *st.rbegin();
				}
				else
				{
					pos = *st.lower_bound(pos + 1);
				}
			}
			//cout << pos << endl;
		}
		for (i = 1; s[i]; ++i)
		{
			if (!vis[i])
				printf("%c", s[i]);
			else
			{
				i = mp[i][0];
			}
		}
		printf("\n");

	}
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <deque>
#include <set>
#include <cstring>
#include <string>

#define SQR(x) (x)*(x)

#define INF 2000000000
#define N 1000
#define M 1000

using namespace std;

struct Node {
	Node* left;
	Node* right;
	char symbol;
	Node(Node* left, Node* right, char symbol) {
		this->left = left;
		this->right = right;
		this->symbol = symbol;
	}
};

Node* head;
Node* tail;
Node* iter;

void add(char c) {
	if (!head) {
		head = new Node(0, 0, c);
		tail = head;
		iter = head;
	}
	else {
		Node* node = new Node(tail, 0, c);
		tail->right = node;
		tail = node;
	}
}

void goLeft() {
	iter = iter->left;
}

void goRight() {
	iter = iter->right;
}

int main() {
	ios_base::sync_with_stdio(false);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int n, m, p;
	cin >> n >> m >> p;
	string str;
	cin >> str;
	for (int i = 0; i < str.length(); ++i) {
		add(str[i]);
	}
	for (int i = 0; i < p - 1; ++i) {
		goRight();
	}
	string comands;
	cin >> comands;
	for (int i = 0; i < comands.length(); ++i) {
		if (comands[i] == 'L') {
			goLeft();
		}
		else if (comands[i] == 'R') {
			goRight();
		}
		else {
			if (iter->symbol == '(') {
				Node* mem = iter;
				int counter = 1;
				while (counter) {
					goRight();
					if (iter->symbol == '(') {
						++counter;
					}
					else {
						--counter;
					}
				}
				if (mem->left)
					mem->left->right = iter->right;
				if (iter->right)
					iter->right->left = mem->left;
				bool flag = (iter == head);
				if (iter->right)
					iter = iter->right;
				else
					iter = mem->left;
				if (flag) {
					head = iter;
				}
			}
			else {
				Node* mem = iter;
				int counter = -1;
				while (counter) {
					goLeft();
					if (iter->symbol == '(') {
						++counter;
					}
					else {
						--counter;
					}
				}
				if (iter->left)
					iter->left->right = mem->right;
				if (mem->right)
					mem->right->left = iter->left;
				bool flag = (iter == head);
				if (mem->right)
					iter = mem->right;
				else
					iter = iter->left;
				if (flag) {
					head = iter;
				}
			}
		}
	}
	iter = head;
	while (iter) {
		cout << iter->symbol;
		goRight();
	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <deque>
#include <set>
#include <cstring>
#include <string>

#define SQR(x) (x)*(x)

#define INF 2000000000
#define N 1000
#define M 1000

using namespace std;

struct Node {
	Node* left;
	Node* right;
	char symbol;
	Node(Node* left, Node* right, char symbol) {
		this->left = left;
		this->right = right;
		this->symbol = symbol;
	}
};

Node* head;
Node* tail;
Node* iter;

void add(char c) {
	if (!head) {
		head = new Node(0, 0, c);
		tail = head;
	}
	else {
		Node* node = new Node(tail, 0, c);
		tail->right = node;
		tail = node;
	}
}

void goLeft() {
	iter = iter->left;
}

void goRight() {
	iter = iter->right;
}

int main() {
	ios_base::sync_with_stdio(false);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int n, m, p;
	cin >> n >> m >> p;
	string str;
	cin >> str;
	for (int i = 0; i < str.length(); ++i) {
		add(str[i]);
	}
	iter = head;
	for (int i = 0; i < p - 1; ++i) {
		goRight();
	}
	string comands;
	cin >> comands;
	for (int i = 0; i < comands.length(); ++i) {
		if (comands[i] == 'L') {
			goLeft();
		}
		else if (comands[i] == 'R') {
			goRight();
		}
		else {
			if (iter->symbol == '(') {
				Node* mem = iter;
				int counter = 1;
				while (counter != 0) {
					goRight();
					if (iter->symbol == '(') {
						++counter;
					}
					else {
						--counter;
					}
				}
				if (mem->left)
					mem->left->right = iter->right;
				if (iter->right)
					iter->right->left = mem->left;
				bool flag = (mem == head);
				if (iter->right)
					iter = iter->right;
				else
					iter = mem->left;
				if (flag) {
					head = iter;
				}
			}
			else {
				Node* mem = iter;
				int counter = -1;
				while (counter) {
					goLeft();
					if (iter->symbol == '(') {
						++counter;
					}
					else {
						--counter;
					}
				}
				if (iter->left)
					iter->left->right = mem->right;
				if (mem->right)
					mem->right->left = iter->left;
				bool flag = (iter == head);
				if (mem->right)
					iter = mem->right;
				else
					iter = iter->left;
				if (flag) {
					head = iter;
				}
			}
		}
	}
	iter = head;
	while (iter) {
		cout << iter->symbol;
		goRight();
	}

	return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

const int MAXN = 6e5;

struct abcd
{
	int l, r;
};

int n, m, pos,before[MAXN],d[MAXN];
char s1[MAXN],s2[MAXN];
abcd p[MAXN];

int main()
{
	//freopen("F:\\rush.txt", "r", stdin);
	scanf("%d%d%d", &n, &m, &pos);
	scanf("%s", s1 + 1);
	int now = 0;
	for (int i = 1;i <= n;i++)
		if (s1[i] == '(')
			before[++now] = i;
		else
		{
			d[before[now]] = i;
			d[i] = before[now];
			now--;
		}
	p[0].r = 1;
	for (int i = 1; i <= n; i++)
		p[i].l = i - 1, p[i].r = i + 1;
	scanf("%s", s2 + 1);
	for (int i = 1; i <= m; i++)
		if (s2[i] == 'R')
			pos = p[pos].r;
		else
			if (s2[i] == 'L')
				pos = p[pos].l;
			else
			{
				int left = min(d[pos], pos);
				int right = max(d[pos], pos);
				p[p[left].l].r = p[right].r;
				p[p[right].r].l = p[left].l;
				pos = p[right].r;
				if (pos == n + 1)
					pos = p[pos].l;
				//if (pos == 0)
				//	pos = p[0].r;
			}
	now = p[0].r;
	while (now != n + 1)
	{
		putchar(s1[now]);
		now = p[now].r;
	}
	puts("");
	return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

const int MAXN = 6e5;

struct abcd
{
	int l, r;
};

int n, m, pos,before[MAXN],d[MAXN];
char s1[MAXN],s2[MAXN];
abcd p[MAXN];

int main()
{
	//freopen("F:\\rush.txt", "r", stdin);
	scanf("%d%d%d", &n, &m, &pos);
	scanf("%s", s1 + 1);
	int now = 0;
	for (int i = 1;i <= n;i++)
		if (s1[i] == '(')
			before[++now] = i;
		else
		{
			d[before[now]] = i;
			d[i] = before[now];
			now--;
		}
	p[0].r = 1;
	for (int i = 1; i <= n; i++)
		p[i].l = i - 1, p[i].r = i + 1;
	scanf("%s", s2 + 1);
	for (int i = 1; i <= m; i++)
		if (s2[i] == 'R')
			pos = p[pos].r;
		else
			if (s2[i] == 'L')
				pos = p[pos].l;
			else
			{
				int left = min(d[pos], pos);
				int right = max(d[pos], pos);
				p[p[left].l].r = p[right].r;
				p[p[right].r].l = p[left].l;
				pos = p[right].r;
				if (pos == n + 1)
					pos = p[pos].l;
				if (pos == 0)
					pos = p[0].r;
			}
	now = p[0].r;
	while (now != n + 1)
	{
		putchar(s1[now]);
		now = p[now].r;
	}
	puts("");
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <functional>
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <assert.h>
#include <bitset>
#include <string>
#include <cstdio>
#include <math.h>
#include <complex>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <set>
#include <bitset>
#include <map>
using namespace std;

#define int64 long long
#define mp make_pair

#ifdef _DEBUG
const int N = 310;
#else
const int N = 3000010;
#endif

const int inf = 1e9+1;

#define left var1
#define right var2

int n, m, p, k, left[N], right[N], neigbour[N], a[N];
string s, w;

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	scanf("%d%d%d\n", &n, &m, &p);
	cin >> s;
	cin >> w;
	k = 0;
	p--;
	for (int i = 0; i < n; i++)
		if (s[i] == '(')
		{
			a[++k] = i;
		}
		else
		{
			neigbour[i] = a[k];
			neigbour[a[k]] = i;
			k--;
		}
	for (int i = 0; i < n; i++) left[i] = i - 1;
	for (int i = 0; i < n; i++) right[i] = i + 1;
	for (int i = 0; i < m; i++)
	{
		if (w[i] == 'R') p = right[p];
		else if (w[i] == 'L') p = left[p];
		else
		{
			int j = neigbour[p];
			int k = p;
			if (k > j) swap(k, j);
			int j1 = left[k];
			int j2 = right[j];
			if (j1 != -1) right[j1] = j2;
			if (j2 != n) left[j2] = j1;
			if (j2 != n) p = j2;
			else p = j1;
		}
	}
	while (left[p] != -1) p = left[p];
	while (p != n)
	{
		cout << s[p];
		p = right[p];
	}
	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>		//UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>		//do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;

#define MR 500010

char s[MR], o[MR];

int main()
{
    map<int, int> M;
    list < pair < char, int > > L;
    vector < int > V;
    int n, m, p;
    scanf("%d%d%d%s%s", &n, &m, &p, s, o); p--;
    REP(i, n)
    {
        L.push_back(MP(s[i], i));
        if (s[i] == ')')
        {
            M[V.back()] = i;
            M[i] = V.back();
            V.pop_back();
        }
        else V.push_back(i);
    }
    auto it = L.begin();
    while (p)
    {
        it++;
        p--;
    }
    REP(i, m)
    {
        if (o[i] == 'L') it--;
        else if (o[i] == 'R') it++;
        else
        {
            bool dir = 1;
            if (M[it->second] < it->second) dir = 0;
            int search = M[it->second];
            while (true)
            {
                auto it1 = it;
                if (dir) it1++;
                else it1--;
                L.erase(it);
                it = it1;
                if (it->second == search)
                {
                    it1 = it;
                    it1++;
                    if (it1 == L.end())
                    {
                        it1--; it1--;
                    }
                    L.erase(it);
                    it = it1;
                    break;
                }
            }
        }
    }
    int dl = 0;
    for (it = L.begin(); it != L.end(); it++)
    {
        s[dl++] = it->first;
    }
    s[dl++] = 0;
    printf("%s\n", s);
    return 0;
}


#include<iostream>
#include<string>
using namespace std;

struct Node{
    char b;
    Node *p,*q;
};
Node *head,*tail,*cursor;

void delr()
{
    Node *tmp;
    int cnt=0;

    tmp=cursor->p;
    for(;;){
        if(cursor->b=='(') cnt++;
        else cnt--;
        cursor=cursor->q;
        if(cnt==0) break;
    }
    cursor->p = tmp;
    tmp ->q = cursor;
    if(cursor->b==NULL) cursor=cursor->p;

}
void dell()
{
    Node *tmp;
    int cnt=0;

    tmp=cursor->q;
    for(;;){
        if(cursor->b==')') cnt++;
        else cnt--;
        cursor=cursor->p;
        if(cnt==0) break;
    }
    cursor->q = tmp;
    tmp ->p = cursor;
    if(tmp->b!=NULL) cursor=cursor->q;
}
int main()
{
    int n,m,p,i;
    string op,br;
    Node *newnode=NULL;

    cin >> n >> m >> p;
    cin >> &br[1] >> op;
    head=new Node();
    tail=new Node();

    cursor=head;
    for(i=1;i<=n;i++){
        newnode=new Node();
        newnode->b = br[i];
        cursor->q = newnode;
        newnode ->p = cursor;
        cursor=cursor->q;
    }
    newnode -> q= tail;
    tail->p = newnode;
    tail->b = NULL;
    cursor=head;
    for(i=1;i<=p;i++){
        cursor=cursor->q;
    }
    for(i=0;i<m;i++){
        if(op[i]=='R') cursor=cursor->q;
        if(op[i]=='L') cursor=cursor->p;
        if(op[i]=='D'){
            if(cursor->b=='(') delr();
            else dell();
        }
    }
    cursor=head->q;
    for(;;){
        cout << cursor->b;
        cursor=cursor->q;
        if(cursor->b==NULL) break;
    }
}


#include<iostream>
#include<string>
using namespace std;

struct Node{
    char b;
    Node *p,*q;
};
Node *head,*tail,*cursor;

void delr()
{
    Node *tmp;
    int cnt=0;

    tmp=cursor->p;
    for(;;){
        if(cursor->b=='(') cnt++;
        else cnt--;
        cursor=cursor->q;
        if(cnt==0) break;
    }
    cursor->p = tmp;
    tmp ->q = cursor;
    if(cursor->b==NULL) cursor=cursor->p;

}
void dell()
{
    Node *tmp;
    int cnt=0;

    tmp=cursor->q;
    for(;;){
        if(cursor->b==')') cnt++;
        else cnt--;
        cursor=cursor->p;
        if(cnt==0) break;
    }
    cursor->q = tmp;
    tmp ->p = cursor;
    if(tmp->b!=NULL) cursor=cursor->q;
}
int main()
{
    int n,m,p,i;
    string op,br;
    Node *newnode;

    cin >> n >> m >> p;
    cin >> &br[1] >> op;
    head=new Node();
    tail=new Node();
    cursor=head;
    for(i=1;i<=n;i++){
        newnode=new Node();
        newnode->b = br[i];
        cursor->q = newnode;
        newnode ->p = cursor;
        cursor=cursor->q;
    }
    newnode -> q= tail;
    tail->p = newnode;
    tail->b = NULL;
    cursor=head;
    for(i=1;i<=p;i++){
        cursor=cursor->q;
    }
    for(i=0;i<m;i++){
        if(op[i]=='R') cursor=cursor->q;
        if(op[i]=='L') cursor=cursor->p;
        if(op[i]=='D'){
            if(cursor->b=='(') delr();
            else dell();
        }
    }
    cursor=head->q;
    for(;;){
        cout << cursor->b;
        cursor=cursor->q;
        if(cursor->b==NULL) break;
    }
}


#include<iostream>
#include<string>
using namespace std;

struct Node{
    char b;
    Node *p,*q;
};
Node *head,*tail,*cursor;

void delr()
{
    Node *tmp;
    int cnt=0;

    tmp=cursor->p;
    for(;;){
        if(cursor->b=='(') cnt++;
        else cnt--;
        cursor=cursor->q;
        if(cnt==0) break;
    }
    cursor->p = tmp;
    tmp ->q = cursor;
    if(cursor->b==NULL) cursor=cursor->p;

}
void dell()
{
    Node *tmp;
    int cnt=0;

    tmp=cursor->q;
    for(;;){
        if(cursor->b==')') cnt++;
        else cnt--;
        cursor=cursor->p;
        if(cnt==0) break;
    }
    cursor->q = tmp;
    tmp ->p = cursor;
    if(tmp->b!=NULL) cursor=cursor->q;
}
int main()
{
    int n,m,p,i;
    string op,br;
    Node *newnode=NULL;

    cin >> n >> m >> p;
    cin >> br;
    cin >> op;
    head=new Node();
    tail=new Node();

    cursor=head;
    for(i=0;i<n;i++){
        newnode=new Node();
        newnode->b = br[i];
        cursor->q = newnode;
        newnode ->p = cursor;
        cursor=cursor->q;
    }
    newnode -> q= tail;
    tail->p = newnode;
    tail->b = NULL;
    cursor=head;
    for(i=1;i<=p;i++){
        cursor=cursor->q;
    }
    for(i=0;i<m;i++){
        if(op[i]=='R') cursor=cursor->q;
        if(op[i]=='L') cursor=cursor->p;
        if(op[i]=='D'){
            if(cursor->b=='(') delr();
            else dell();
        }
    }
    cursor=head->q;
    for(;;){
        cout << cursor->b;
        cursor=cursor->q;
        if(cursor->b==NULL) break;
    }
}


#include <cstdio>

int n, m, p;
char A[500010], B[500010];

int stack[500010], left_link[500010], right_link[500010];
int S[500010];

int main ()
{
	scanf("%d%d%d", &n, &m, &p);
	scanf("%s", A+1);
	scanf("%s", B+1);

	int i, sp = 0;
	for(i=1; i<=n; i++){
		if ( A[i] == '(' ) stack[++sp] = i;
		else {
			S[i] = stack[sp];
			S[stack[sp]] = i;
			sp --;
		}
	}

	for(i=1; i<=n; i++){
		left_link[i] = i-1;
		right_link[i] = i+1;
	} right_link[0] = 1, left_link[n+1] = n;

	int tmp1, tmp2;
	for(i=1; i<=m; i++){
		if ( B[i] == 'R' ){
			p = right_link[p];
		} else if ( B[i] == 'L' ){
			p = left_link[p];
		} else {
			if ( A[p] == ')' ){
				tmp1 = right_link[p];
				tmp2 = left_link[S[p]];

				left_link[tmp1] = tmp2;
				right_link[tmp2] = tmp1;

				p = tmp1;
			} else {
				tmp1 = left_link[p];
				tmp2 = right_link[S[p]];

				right_link[tmp1] = tmp2;
				left_link[tmp2] = tmp1;

				p = tmp2;
			}
		}
	}

	p = 0;
	for(;;){
		p = right_link[p];
		if ( p > n ) break;
		printf("%c", A[p]);
	} printf("\n");

	return 0;
}


#include <cstdio>

int n, m, p;
char A[500010], B[500010];

int stack[500010], left_link[500010], right_link[500010];
int S[500010];

int main ()
{
	scanf("%d%d%d", &n, &m, &p);
	scanf("%s", A+1);
	scanf("%s", B+1);

	int i, sp = 0;
	for(i=1; i<=n; i++){
		if ( A[i] == '(' ) stack[++sp] = i;
		else {
			S[i] = stack[sp];
			S[stack[sp]] = i;
			sp --;
		}
	}

	for(i=1; i<=n; i++){
		left_link[i] = i-1;
		right_link[i] = i+1;
	} right_link[0] = 1, left_link[n+1] = n;

	int tmp1, tmp2;
	for(i=1; i<=m; i++){
		if ( B[i] == 'R' ){
			p = right_link[p];
		} else if ( B[i] == 'L' ){
			p = left_link[p];
		} else {
			if ( A[p] == ')' ){
				tmp1 = right_link[p];
				tmp2 = left_link[S[p]];

				left_link[tmp1] = tmp2;
				right_link[tmp2] = tmp1;

				if ( tmp1 > n ) p = tmp2;
				else p = tmp1;
			} else {
				tmp1 = left_link[p];
				tmp2 = right_link[S[p]];

				right_link[tmp1] = tmp2;
				left_link[tmp2] = tmp1;

				if ( tmp2 > n ) p = tmp1;
				else p = tmp2;
			}
		}
	}

	p = 0;
	for(;;){
		p = right_link[p];
		if ( p > n ) break;
		printf("%c", A[p]);
	} printf("\n");

	return 0;
}


//#define ONLINE_JUDGE

#if defined(ONLINE_JUDGE)
#define _SECURE_SCL 0
#endif

#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <functional>
#include <memory>
#include <cmath>
#include <climits>
#include <numeric>
#include <tuple>
#include <list>
#include <memory.h>
#include <stdint.h>

#if !defined(__GNUC__)
#else // !defined(__GNUC__)
#define _CrtDbgBreak() __builtin_trap()
#endif // !defined(__GNUC__)

#if defined(ONLINE_JUDGE)
#define LOCAL_TEST 0
#else
#define LOCAL_TEST 1
#endif

#if LOCAL_TEST
struct AssertsCounter
{
	AssertsCounter(): counter(0) {}
	~AssertsCounter() { std::cout << std::endl << "DIAG: " << (counter == 0 ? "OK" : "!!!") << " Asserts count: " << counter << std::endl; }
	void Increment() { counter++; }
	uint32_t counter;
};
AssertsCounter g_assertsCounter;
#define LOCAL_ASSERT(expr) { if (!(expr)) {std::cout << "ASSERT FAILED (" << __LINE__ << "): '" << #expr << "'" << std::endl; g_assertsCounter.Increment(); _CrtDbgBreak(); } }
#define LOCAL_ASSERT_EQ(expr1, expr2) { if ((expr1) != (expr2)) {std::cout << "ASSERT FAILED (" << __LINE__ << "): '" << #expr1 << "' == '" << #expr2 << "' (" << (expr1) << " vs " << (expr2) << "')" << std::endl; g_assertsCounter.Increment(); _CrtDbgBreak(); } }
#else
#define LOCAL_ASSERT(expr)
#define LOCAL_ASSERT_EQ(expr1, expr2)
#endif

typedef std::string string8_t;
typedef long double ld_t;

typedef std::vector<size_t> vector_size_t;
typedef std::vector<int32_t> vector_int32_t;
typedef std::vector<uint32_t> vector_uint32_t;
typedef std::vector<int64_t> vector_int64_t;
typedef std::vector<uint64_t> vector_uint64_t;
typedef std::vector<string8_t> vector_string8_t;

typedef std::vector<vector_size_t> vector_2d_size_t;
typedef std::vector<vector_int32_t> vector_2d_int32_t;
typedef std::vector<vector_uint32_t> vector_2d_uint32_t;
typedef std::vector<vector_int64_t> vector_2d_int64_t;
typedef std::vector<vector_uint64_t> vector_2d_uint64_t;

typedef std::set<size_t> set_size_t;
typedef std::set<int32_t> set_int32_t;
typedef std::set<uint32_t> set_uint32_t;
typedef std::set<int64_t> set_int64_t;
typedef std::set<uint64_t> set_uint64_t;
typedef std::set<string8_t> set_string8_t;

typedef std::multiset<size_t> multiset_size_t;
typedef std::multiset<string8_t> multiset_string8_t;

// Auxiliary functions definition
//
template<typename T> void UpdateMin(T& a, const T b) {a = std::min(a, b);}
template<typename T> void UpdateMax(T& a, const T b) {a = std::max(a, b);}

static const ld_t Eps = 1.0e-09;
template<typename T> bool IsEqual(const T a, const T b) { return std::abs(a - b) < Eps; }
template<typename T> bool IsGreater(const T a, const T b) { return a > b + Eps; }
template<typename T> bool IsLess(const T a, const T b) { return a + Eps < b; }

template<typename T> string8_t ToStr(const T& val) { std::ostringstream ostr; ostr << val; return ostr.str(); }
template<typename T> bool FromStr(const string8_t& str, T& val) {std::istringstream istr(str); istr >> val; return !!istr; }

template<typename T> std::istream& operator>>(std::istream& ist, std::vector<T>& data)
{
	LOCAL_ASSERT(!!ist);
	for (size_t i = 0; i < data.size(); i++) { ist >> data[i]; }
	return ist;
}

template<typename T> T Read(std::istream& ist)
{
	LOCAL_ASSERT(!!ist);
	T val; ist >> val; return val;
}

template<typename T> std::ostream& operator<<(std::ostream& ost, const std::vector<T>& data)
{
	for (size_t i = 0; i < data.size(); i++) { if (i != 0) { ost << ' '; } ost << data[i]; }
	return ost;
}

#if defined(ONLINE_JUDGE)
template<size_t id> class StopWatch { };
#else
#include <library/lib_stopwatch.h>
#include <library/lib_random.h>
library::random::Rand g_rnd;
#endif

typedef std::list<size_t> list_size_t;
typedef std::vector<list_size_t::iterator> vector_list_iterator_t;

bool Solve(std::istream& ist, std::ostream& ost, const bool multipleTestMode)
{
	StopWatch<1> sw; (void)sw;

	//
	size_t n, m, p;
	ist >> n >> m >> p;

	if (multipleTestMode && !ist)
		return false;

	string8_t s;
	ist >> s;

	string8_t q;
	ist >> q;

#if LOCAL_TEST
	ost << std::endl << "Next test: " << std::endl << "S: " << s << std::endl << "Q: " << q << std::endl;
#endif

	vector_size_t pairOf(n);
	vector_size_t stack;
	for (size_t i = 0; i < s.size(); i++)
	{
		if (s[i] == '(')
		{
			stack.push_back(i);
			continue;
		}

		LOCAL_ASSERT(!stack.empty());
		const size_t openPos = *stack.rbegin();
		stack.pop_back();

		pairOf[openPos] = i;
		pairOf[i] = openPos;
	}

#if LOCAL_TEST
	for (size_t i = 0; i < n; i++)
	{
		const size_t p1 = i;
		const size_t p2 = pairOf[i];
		LOCAL_ASSERT(s[p1] != s[p2]);
	}
#endif

	list_size_t chain;
	vector_list_iterator_t chainRefs(n);

	for (size_t i = 0; i < n; i++)
	{
		chain.push_back(i);
		chainRefs[i] = chain.end();
		--chainRefs[i];
	}

	list_size_t::iterator pos = chain.begin();
	std::advance(pos, p - 1);

	for (size_t i = 0; i < q.size(); i++)
	{
		const char c = q[i];
		if (c == 'L')
		{
			LOCAL_ASSERT(pos != chain.begin());
			--pos;
			continue;
		}

		if (c == 'R')
		{
			++pos;
			LOCAL_ASSERT(pos != chain.end());
			continue;
		}

		if (c == 'D')
		{
			const size_t index = *pos;
			const size_t pairIndex = pairOf[index];

			const size_t leftIndex = std::min(index, pairIndex);
			const size_t rightIndex = std::max(index, pairIndex);

			list_size_t::iterator beginErasePos = chainRefs[leftIndex];
			list_size_t::iterator endErasePos = chainRefs[rightIndex];
			++endErasePos;

			chain.erase(beginErasePos, endErasePos);
			pos = endErasePos;
			if (pos == chain.end())
			{
				--pos;
			}
		}
	}

	string8_t ans;
	for (list_size_t::const_iterator p = chain.begin(); p != chain.end(); ++p)
	{
		const size_t index = *p;
		ans += s[index];
	}

	ost << ans << std::endl;

	return multipleTestMode;
}

#if LOCAL_TEST
void Test()
{
	using namespace library::random;
	const auto genVector = GenFactory::CreateGenVector(GenRange<size_t>(2, 10), GenRange<int32_t>(-100, +200));

	for (size_t t = 0; t < 10; t++)
	{
		const vector_int32_t data = genVector();
		// size_t ans = GetAns(data);
	}
}
#endif

int main(int argc, const char *argv[])
{
#if LOCAL_TEST
	Test();
#endif

    std::ios_base::sync_with_stdio(false);
    std::istream* ist = &std::cin;
    std::ostream* ost = &std::cout;

    std::unique_ptr<std::istream> fileInput;

    if (argc > 1)
    {
        fileInput.reset(new std::ifstream(argv[1]));
        if (!(*fileInput))
        {
            std::cout << "File not found: " << argv[1] << std::endl;
        }
        ist = fileInput.get();
    }

#if defined(ONLINE_JUDGE)
    Solve(*ist, *ost, false);
#else
    while(Solve(*ist, *ost, true)) {};
#endif
}


//#define ONLINE_JUDGE

#if defined(ONLINE_JUDGE)
#define _SECURE_SCL 0
#endif

#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <functional>
#include <memory>
#include <cmath>
#include <climits>
#include <numeric>
#include <tuple>
#include <memory.h>
#include <stdint.h>

#if !defined(__GNUC__)
#else // !defined(__GNUC__)
#define _CrtDbgBreak() __builtin_trap()
#endif // !defined(__GNUC__)

#if defined(ONLINE_JUDGE)
#define LOCAL_TEST 0
#else
#define LOCAL_TEST 1
#endif

#if LOCAL_TEST
struct AssertsCounter
{
	AssertsCounter(): counter(0) {}
	~AssertsCounter() { std::cout << std::endl << "DIAG: " << (counter == 0 ? "OK" : "!!!") << " Asserts count: " << counter << std::endl; }
	void Increment() { counter++; }
	uint32_t counter;
};
AssertsCounter g_assertsCounter;
#define LOCAL_ASSERT(expr) { if (!(expr)) {std::cout << "ASSERT FAILED (" << __LINE__ << "): '" << #expr << "'" << std::endl; g_assertsCounter.Increment(); _CrtDbgBreak(); } }
#define LOCAL_ASSERT_EQ(expr1, expr2) { if ((expr1) != (expr2)) {std::cout << "ASSERT FAILED (" << __LINE__ << "): '" << #expr1 << "' == '" << #expr2 << "' (" << (expr1) << " vs " << (expr2) << "')" << std::endl; g_assertsCounter.Increment(); _CrtDbgBreak(); } }
#else
#define LOCAL_ASSERT(expr)
#define LOCAL_ASSERT_EQ(expr1, expr2)
#endif

typedef std::string string8_t;
typedef long double ld_t;

typedef std::vector<size_t> vector_size_t;
typedef std::vector<int32_t> vector_int32_t;
typedef std::vector<uint32_t> vector_uint32_t;
typedef std::vector<int64_t> vector_int64_t;
typedef std::vector<uint64_t> vector_uint64_t;
typedef std::vector<string8_t> vector_string8_t;

typedef std::vector<vector_size_t> vector_2d_size_t;
typedef std::vector<vector_int32_t> vector_2d_int32_t;
typedef std::vector<vector_uint32_t> vector_2d_uint32_t;
typedef std::vector<vector_int64_t> vector_2d_int64_t;
typedef std::vector<vector_uint64_t> vector_2d_uint64_t;

typedef std::set<size_t> set_size_t;
typedef std::set<int32_t> set_int32_t;
typedef std::set<uint32_t> set_uint32_t;
typedef std::set<int64_t> set_int64_t;
typedef std::set<uint64_t> set_uint64_t;
typedef std::set<string8_t> set_string8_t;

typedef std::multiset<size_t> multiset_size_t;
typedef std::multiset<string8_t> multiset_string8_t;

// Auxiliary functions definition
//
template<typename T> void UpdateMin(T& a, const T b) {a = std::min(a, b);}
template<typename T> void UpdateMax(T& a, const T b) {a = std::max(a, b);}

static const ld_t Eps = 1.0e-09;
template<typename T> bool IsEqual(const T a, const T b) { return std::abs(a - b) < Eps; }
template<typename T> bool IsGreater(const T a, const T b) { return a > b + Eps; }
template<typename T> bool IsLess(const T a, const T b) { return a + Eps < b; }

template<typename T> string8_t ToStr(const T& val) { std::ostringstream ostr; ostr << val; return ostr.str(); }
template<typename T> bool FromStr(const string8_t& str, T& val) {std::istringstream istr(str); istr >> val; return !!istr; }

template<typename T> std::istream& operator>>(std::istream& ist, std::vector<T>& data)
{
	LOCAL_ASSERT(!!ist);
	for (size_t i = 0; i < data.size(); i++) { ist >> data[i]; }
	return ist;
}

template<typename T> T Read(std::istream& ist)
{
	LOCAL_ASSERT(!!ist);
	T val; ist >> val; return val;
}

template<typename T> std::ostream& operator<<(std::ostream& ost, const std::vector<T>& data)
{
	for (size_t i = 0; i < data.size(); i++) { if (i != 0) { ost << ' '; } ost << data[i]; }
	return ost;
}

#if defined(ONLINE_JUDGE)
template<size_t id> class StopWatch { };
#else
#include <library/lib_stopwatch.h>
#include <library/lib_random.h>
library::random::Rand g_rnd;
#endif

typedef std::list<size_t> list_size_t;
typedef std::vector<list_size_t::iterator> vector_list_iterator_t;

bool Solve(std::istream& ist, std::ostream& ost, const bool multipleTestMode)
{
	StopWatch<1> sw; (void)sw;

	//
	size_t n, m, p;
	ist >> n >> m >> p;

	if (multipleTestMode && !ist)
		return false;

	string8_t s;
	ist >> s;

	string8_t q;
	ist >> q;

#if LOCAL_TEST
	ost << std::endl << "Next test: " << std::endl << "S: " << s << std::endl << "Q: " << q << std::endl;
#endif

	vector_size_t pairOf(n);
	vector_size_t stack;
	for (size_t i = 0; i < s.size(); i++)
	{
		if (s[i] == '(')
		{
			stack.push_back(i);
			continue;
		}

		LOCAL_ASSERT(!stack.empty());
		const size_t openPos = *stack.rbegin();
		stack.pop_back();

		pairOf[openPos] = i;
		pairOf[i] = openPos;
	}

#if LOCAL_TEST
	for (size_t i = 0; i < n; i++)
	{
		const size_t p1 = i;
		const size_t p2 = pairOf[i];
		LOCAL_ASSERT(s[p1] != s[p2]);
	}
#endif

	list_size_t chain;
	vector_list_iterator_t chainRefs(n);

	for (size_t i = 0; i < n; i++)
	{
		chain.push_back(i);
		chainRefs[i] = chain.end();
		--chainRefs[i];
	}

	list_size_t::iterator pos = chain.begin();
	std::advance(pos, p - 1);

	for (size_t i = 0; i < q.size(); i++)
	{
		const char c = q[i];
		if (c == 'L')
		{
			LOCAL_ASSERT(pos != chain.begin());
			--pos;
			continue;
		}

		if (c == 'R')
		{
			++pos;
			LOCAL_ASSERT(pos != chain.end());
			continue;
		}

		if (c == 'D')
		{
			const size_t index = *pos;
			const size_t pairIndex = pairOf[index];

			const size_t leftIndex = std::min(index, pairIndex);
			const size_t rightIndex = std::max(index, pairIndex);

			list_size_t::iterator beginErasePos = chainRefs[leftIndex];
			list_size_t::iterator endErasePos = chainRefs[rightIndex];
			++endErasePos;

			chain.erase(beginErasePos, endErasePos);
			pos = endErasePos;
			if (pos == chain.end())
			{
				--pos;
			}
		}
	}

	string8_t ans;
	for (list_size_t::const_iterator p = chain.begin(); p != chain.end(); ++p)
	{
		const size_t index = *p;
		ans += s[index];
	}

	ost << ans << std::endl;

	return multipleTestMode;
}

#if LOCAL_TEST
void Test()
{
	using namespace library::random;
	const auto genVector = GenFactory::CreateGenVector(GenRange<size_t>(2, 10), GenRange<int32_t>(-100, +200));

	for (size_t t = 0; t < 10; t++)
	{
		const vector_int32_t data = genVector();
		// size_t ans = GetAns(data);
	}
}
#endif

int main(int argc, const char *argv[])
{
#if LOCAL_TEST
	Test();
#endif

    std::ios_base::sync_with_stdio(false);
    std::istream* ist = &std::cin;
    std::ostream* ost = &std::cout;

    std::unique_ptr<std::istream> fileInput;

    if (argc > 1)
    {
        fileInput.reset(new std::ifstream(argv[1]));
        if (!(*fileInput))
        {
            std::cout << "File not found: " << argv[1] << std::endl;
        }
        ist = fileInput.get();
    }

#if defined(ONLINE_JUDGE)
    Solve(*ist, *ost, false);
#else
    while(Solve(*ist, *ost, true)) {};
#endif
}


#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <stdlib.h>
#include <time.h>
#define mp(x,y) make_pair(x,y)
using namespace std;
int par[500005];
stack<int> st;
string s1,s2;
int p;
struct node{
	int key,cnt;
	node *l, *r;
	node(int k){
		this->l = this->r = NULL;
		this->key = k;
		this->cnt = 0;
	}
};
int cnt(node *t){
	return (t == NULL ? 0:t->cnt);
}
void upd(node *t){
	if(t != NULL)
		t->cnt = 1 + cnt(t->l) + cnt(t->r);
}
void split(node *t, node *&l, node *&r, int key){
	if(t == NULL){l = r = NULL;return;}
	if(t->key > key)
		split(t->l,l,t->l,key),r=t;
	else
		split(t->r,t->r,r,key),l=t;
	upd(t);
}
void merge(node *&t, node *l, node *r){
	if(l == NULL){t=r;return;}
	if(r == NULL){t=l;return;}
	if((rand() & 1) ^ (rand() & 1))
		merge(l->r,l->r,r),t=l;
	else
		merge(r->l,l,r->l),t=r;
	upd(t);
}
void output(node *t){
	if(t == NULL)return;
	output(t->l);
	cout<<s1[t->key];
	output(t->r);
}
node *t1 = NULL, *t2, *t3, *t4, *t5;
int main(){
	cin.tie(0);
	cout.tie(0);
	srand((unsigned)time(NULL));
	cin>>p>>p>>p;
	p--;
	cin>>s1>>s2;
	for(int i=0;i + 1 <(int)s1.size();i++){
		if(s1[i] == '(' && s1[i+1] == ')'){
			par[i]=i+1,par[i+1]=i;
			i+=2;
			while(!st.empty() && i!=(int)s1.size()){
				int j = st.top();
				st.pop();
				if(s1[j] == '(' && s1[i] == ')'){par[i]=j,par[j]=i,i++;}
				else {st.push(j);break;}
			}
			i--;
		}
		else st.push(i);
	}
	for(int i=0;i<(int)s1.size();i++){
		merge(t1,t1,new node(i));
	}
	split(t1,t1,t3,p);
	split(t1,t1,t2,p-1);
	for(int i=0;i<(int)s2.size();i++){
		switch(s2[i]){
		case 'R':
			t4 = t3;
			while(t4->l != NULL)t4 = t4->l;
			split(t3,t4,t3,t4->key);
			merge(t1,t1,t2);
			t2 = t4;
			break;
		case 'L':
			t4 = t1;
			while(t4->r != NULL)t4 = t4->r;
			split(t1,t1,t4,t4->key-1);
			merge(t3,t2,t3);
			t2 = t4;
			break;
		case 'D':
			if(par[t2->key] < t2->key)split(t1,t1,t4,par[t2->key]-1);
			else split(t3,t4,t3,par[t2->key]);
			if(t3 != NULL){
				t4 = t3;
				while(t4->l != NULL)t4 = t4->l;
				split(t3,t4,t3,t4->key);
				t2 = t4;
			}
			else{
				t4 = t1;
				while(t4->r != NULL)t4 = t4->r;
				split(t1,t1,t4,t4->key-1);
				t2 = t4;
			}
			break;
		}
	}
	merge(t1,t1,t2);
	merge(t1,t1,t3);
	output(t1);
	cout<<endl;
}


#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <stdlib.h>
#include <time.h>
#define mp(x,y) make_pair(x,y)
using namespace std;
int par[500005];
stack<int> st;
string s1,s2;
int p;
struct node{
	int key,cnt;
	node *l, *r;
	node(int k){
		this->l = this->r = NULL;
		this->key = k;
		this->cnt = 0;
	}
};
int cnt(node *t){
	return (t == NULL ? 0:t->cnt);
}
void upd(node *t){
	if(t != NULL)
		t->cnt = 1 + cnt(t->l) + cnt(t->r);
}
void split(node *t, node *&l, node *&r, int key){
	if(t == NULL){l = r = NULL;return;}
	if(t->key > key)
		split(t->l,l,t->l,key),r=t;
	else
		split(t->r,t->r,r,key),l=t;
	upd(t);
}
void merge(node *&t, node *l, node *r){
	if(l == NULL){t=r;return;}
	if(r == NULL){t=l;return;}
	if(rand() & 1)
		merge(l->r,l->r,r),t=l;
	else
		merge(r->l,l,r->l),t=r;
	upd(t);
}
void output(node *t){
	if(t == NULL)return;
	output(t->l);
	cout<<s1[t->key];
	output(t->r);
}
node *t1 = NULL, *t2, *t3, *t4, *t5;
int main(){
	cin.tie(0);
	cout.tie(0);
	srand((unsigned)time(NULL));
	cin>>p>>p>>p;
	p--;
	cin>>s1>>s2;
	for(int i=0;i + 1 <(int)s1.size();i++){
		if(s1[i] == '(' && s1[i+1] == ')'){
			par[i]=i+1,par[i+1]=i;
			i+=2;
			while(!st.empty() && i!=(int)s1.size()){
				int j = st.top();
				st.pop();
				if(s1[j] == '(' && s1[i] == ')'){par[i]=j,par[j]=i,i++;}
				else {st.push(j);break;}
			}
			i--;
		}
		else st.push(i);
	}
	for(int i=0;i<(int)s1.size();i++){
		merge(t1,t1,new node(i));
	}
	split(t1,t1,t3,p);
	split(t1,t1,t2,p-1);
	for(int i=0;i<(int)s2.size();i++){
		switch(s2[i]){
		case 'R':
			t4 = t3;
			while(t4->l != NULL)t4 = t4->l;
			split(t3,t4,t3,t4->key);
			merge(t1,t1,t2);
			t2 = t4;
			break;
		case 'L':
			t4 = t1;
			while(t4->r != NULL)t4 = t4->r;
			split(t1,t1,t4,t4->key-1);
			merge(t3,t2,t3);
			t2 = t4;
			break;
		case 'D':
			if(par[t2->key] < t2->key)split(t1,t1,t4,par[t2->key]-1);
			else split(t3,t4,t3,par[t2->key]);
			if(t3 != NULL){
				t4 = t3;
				while(t4->l != NULL)t4 = t4->l;
				split(t3,t4,t3,t4->key);
				t2 = t4;
			}
			else{
				t4 = t1;
				while(t4->r != NULL)t4 = t4->r;
				split(t1,t1,t4,t4->key-1);
				t2 = t4;
			}
			break;
		}
	}
	merge(t1,t1,t2);
	merge(t1,t1,t3);
	output(t1);
	cout<<endl;
}


#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <stack>
#define mp(x,y) make_pair(x,y)
using namespace std;
int par[500005];
stack<int> st;
string s1,s2;
int p;
struct node{
	int key,prior;
	node *l, *r;
	node(int k){
		this->l = this->r = NULL;
		this->key = k;
		this->prior = rand();
	}
};
void split(node *t, node *&l, node *&r, int key){
	if(t == NULL){l = r = NULL;return;}
	if(t->key > key)
		split(t->l,l,t->l,key),r=t;
	else
		split(t->r,t->r,r,key),l=t;
}
void merge(node *&t, node *l, node *r){
	if(l == NULL){t=r;return;}
	if(r == NULL){t=l;return;}
	if(l->prior > r->prior)
		merge(l->r,l->r,r),t=l;
	else
		merge(r->l,l,r->l),t=r;
}
void output(node *t){
	if(t == NULL)return;
	output(t->l);
	cout<<s1[t->key];
	output(t->r);
}
node *t1 = NULL, *t2, *t3, *t4, *t5;
int main(){
	cin.tie(0);
	cout.tie(0);
	cin>>p>>p>>p;
	p--;
	cin>>s1>>s2;
	for(int i=0;i + 1 <(int)s1.size();i++){
		if(s1[i] == '(' && s1[i+1] == ')'){
			par[i]=i+1,par[i+1]=i;
			i+=2;
			while(!st.empty() && i!=(int)s1.size()){
				int j = st.top();
				st.pop();
				if(s1[j] == '(' && s1[i] == ')'){par[i]=j,par[j]=i,i++;}
				else {st.push(j);break;}
			}
			i--;
		}
		else st.push(i);
	}
	for(int i=0;i<(int)s1.size();i++){
		merge(t1,t1,new node(i));
	}
	split(t1,t1,t3,p);
	split(t1,t1,t2,p-1);
	for(int i=0;i<(int)s2.size();i++){
		switch(s2[i]){
		case 'R':
			t4 = t3;
			while(t4->l != NULL)t4 = t4->l;
			split(t3,t4,t3,t4->key);
			merge(t1,t1,t2);
			t2 = t4;
			break;
		case 'L':
			t4 = t1;
			while(t4->r != NULL)t4 = t4->r;
			split(t1,t1,t4,t4->key-1);
			merge(t3,t2,t3);
			t2 = t4;
			break;
		case 'D':
			if(par[t2->key] < t2->key)split(t1,t1,t4,par[t2->key]-1);
			else split(t3,t4,t3,par[t2->key]);
			if(t3 != NULL){
				t4 = t3;
				while(t4->l != NULL)t4 = t4->l;
				split(t3,t4,t3,t4->key);
				t2 = t4;
			}
			else{
				t4 = t1;
				while(t4->r != NULL)t4 = t4->r;
				split(t1,t1,t4,t4->key-1);
				t2 = t4;
			}
			break;
		}
	}
	merge(t1,t1,t2);
	merge(t1,t1,t3);
	output(t1);
	cout<<endl;
}


#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <stack>
#define mp(x,y) make_pair(x,y)
using namespace std;
int par[500005];
stack<int> st;
string s1,s2;
int p;
struct node{
	int key,cnt;
	node *l, *r;
	node(int k){
		this->l = this->r = NULL;
		this->key = k;
		this->cnt = 0;
	}
};
int cnt(node *t){
	return (t == NULL ? 0:t->cnt);
}
void upd(node *t){
	if(t != NULL)
		t->cnt = 1 + cnt(t->l) + cnt(t->r);
}
void split(node *t, node *&l, node *&r, int key){
	if(t == NULL){l = r = NULL;return;}
	if(t->key > key)
		split(t->l,l,t->l,key),r=t;
	else
		split(t->r,t->r,r,key),l=t;
	upd(t);
}
void merge(node *&t, node *l, node *r){
	if(l == NULL){t=r;return;}
	if(r == NULL){t=l;return;}
	if(l->cnt > r->cnt)
		merge(l->r,l->r,r),t=l;
	else
		merge(r->l,l,r->l),t=r;
	upd(t);
}
void output(node *t){
	if(t == NULL)return;
	output(t->l);
	cout<<s1[t->key];
	output(t->r);
}
node *t1 = NULL, *t2, *t3, *t4, *t5;
int main(){
	cin.tie(0);
	cout.tie(0);
	cin>>p>>p>>p;
	p--;
	cin>>s1>>s2;
	for(int i=0;i + 1 <(int)s1.size();i++){
		if(s1[i] == '(' && s1[i+1] == ')'){
			par[i]=i+1,par[i+1]=i;
			i+=2;
			while(!st.empty() && i!=(int)s1.size()){
				int j = st.top();
				st.pop();
				if(s1[j] == '(' && s1[i] == ')'){par[i]=j,par[j]=i,i++;}
				else {st.push(j);break;}
			}
			i--;
		}
		else st.push(i);
	}
	for(int i=0;i<(int)s1.size();i++){
		merge(t1,t1,new node(i));
	}
	split(t1,t1,t3,p);
	split(t1,t1,t2,p-1);
	for(int i=0;i<(int)s2.size();i++){
		switch(s2[i]){
		case 'R':
			t4 = t3;
			while(t4->l != NULL)t4 = t4->l;
			split(t3,t4,t3,t4->key);
			merge(t1,t1,t2);
			t2 = t4;
			break;
		case 'L':
			t4 = t1;
			while(t4->r != NULL)t4 = t4->r;
			split(t1,t1,t4,t4->key-1);
			merge(t3,t2,t3);
			t2 = t4;
			break;
		case 'D':
			if(par[t2->key] < t2->key)split(t1,t1,t4,par[t2->key]-1);
			else split(t3,t4,t3,par[t2->key]);
			if(t3 != NULL){
				t4 = t3;
				while(t4->l != NULL)t4 = t4->l;
				split(t3,t4,t3,t4->key);
				t2 = t4;
			}
			else{
				t4 = t1;
				while(t4->r != NULL)t4 = t4->r;
				split(t1,t1,t4,t4->key-1);
				t2 = t4;
			}
			break;
		}
	}
	merge(t1,t1,t2);
	merge(t1,t1,t3);
	output(t1);
	cout<<endl;
}


#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <stack>
#define mp(x,y) make_pair(x,y)
using namespace std;
int par[500005];
stack<int> st;
string s1,s2;
int p;
struct node{
	int key,prior;
	node *l, *r;
	node(int k){
		this->l = this->r = NULL;
		this->key = k;
		this->prior = rand();
	}
};
void split(node *t, node *&l, node *&r, int key){
	if(t == NULL){l = r = NULL;return;}
	if(t->key > key)
		split(t->l,l,t->l,key),r=t;
	else
		split(t->r,t->r,r,key),l=t;
}
void merge(node *&t, node *l, node *r){
	if(l == NULL){t=r;return;}
	if(r == NULL){t=l;return;}
	if(l->cnt > r->cnt)
		merge(l->r,l->r,r),t=l;
	else
		merge(r->l,l,r->l),t=r;
}
void output(node *t){
	if(t == NULL)return;
	output(t->l);
	cout<<s1[t->key];
	output(t->r);
}
node *t1 = NULL, *t2, *t3, *t4, *t5;
int main(){
	cin.tie(0);
	cout.tie(0);
	cin>>p>>p>>p;
	p--;
	cin>>s1>>s2;
	for(int i=0;i + 1 <(int)s1.size();i++){
		if(s1[i] == '(' && s1[i+1] == ')'){
			par[i]=i+1,par[i+1]=i;
			i+=2;
			while(!st.empty() && i!=(int)s1.size()){
				int j = st.top();
				st.pop();
				if(s1[j] == '(' && s1[i] == ')'){par[i]=j,par[j]=i,i++;}
				else {st.push(j);break;}
			}
			i--;
		}
		else st.push(i);
	}
	for(int i=0;i<(int)s1.size();i++){
		merge(t1,t1,new node(i));
	}
	split(t1,t1,t3,p);
	split(t1,t1,t2,p-1);
	for(int i=0;i<(int)s2.size();i++){
		switch(s2[i]){
		case 'R':
			t4 = t3;
			while(t4->l != NULL)t4 = t4->l;
			split(t3,t4,t3,t4->key);
			merge(t1,t1,t2);
			t2 = t4;
			break;
		case 'L':
			t4 = t1;
			while(t4->r != NULL)t4 = t4->r;
			split(t1,t1,t4,t4->key-1);
			merge(t3,t2,t3);
			t2 = t4;
			break;
		case 'D':
			if(par[t2->key] < t2->key)split(t1,t1,t4,par[t2->key]-1);
			else split(t3,t4,t3,par[t2->key]);
			if(t3 != NULL){
				t4 = t3;
				while(t4->l != NULL)t4 = t4->l;
				split(t3,t4,t3,t4->key);
				t2 = t4;
			}
			else{
				t4 = t1;
				while(t4->r != NULL)t4 = t4->r;
				split(t1,t1,t4,t4->key-1);
				t2 = t4;
			}
			break;
		}
	}
	merge(t1,t1,t2);
	merge(t1,t1,t3);
	output(t1);
	cout<<endl;
}


#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <stack>
#define mp(x,y) make_pair(x,y)
using namespace std;
int par[500005];
stack<int> st;
string s1,s2;
int p;
struct node{
	int key,prior;
	node *l, *r;
	node(int k){
		this->l = this->r = NULL;
		this->key = k;
		this->prior = rand();
	}
};
void split(node *t, node *&l, node *&r, int key){
	if(t == NULL){l = r = NULL;return;}
	if(t->key > key)
		split(t->l,l,t->l,key),r=t;
	else
		split(t->r,t->r,r,key),l=t;
}
void merge(node *&t, node *l, node *r){
	if(l == NULL){t=r;return;}
	if(r == NULL){t=l;return;}
	if(l->prior > r->prior)
		merge(l->r,l->r,r),t=l;
	else
		merge(r->l,l,r->l),t=r;
}
void output(node *t){
	if(t == NULL)return;
	output(t->l);
	cout<<s1[t->key];
	output(t->r);
}
node *t1 = NULL, *t2, *t3, *t4, *t5;
int main(){
	cin>>p>>p>>p;
	p--;
	cin>>s1>>s2;
	for(int i=0;i + 1 <(int)s1.size();i++){
		if(s1[i] == '(' && s1[i+1] == ')'){
			par[i]=i+1,par[i+1]=i;
			i+=2;
			while(!st.empty() && i!=(int)s1.size()){
				int j = st.top();
				st.pop();
				if(s1[j] == '(' && s1[i] == ')'){par[i]=j,par[j]=i,i++;}
				else {st.push(j);break;}
			}
			i--;
		}
		else st.push(i);
	}
	for(int i=0;i<(int)s1.size();i++){
		merge(t1,t1,new node(i));
	}
	split(t1,t1,t3,p);
	split(t1,t1,t2,p-1);
	for(int i=0;i<s2.size();i++){
		switch(s2[i]){
		case 'R':
			t4 = t3;
			while(t4->l != NULL)t4 = t4->l;
			split(t3,t4,t3,t4->key);
			merge(t1,t1,t2);
			t2 = t4;
			break;
		case 'L':
			t4 = t1;
			while(t4->r != NULL)t4 = t4->r;
			split(t1,t1,t4,t4->key-1);
			merge(t3,t2,t3);
			t2 = t4;
			break;
		case 'D':
			if(par[t2->key] < t2->key)split(t1,t1,t4,par[t2->key]-1);
			else split(t3,t4,t3,par[t2->key]);
			if(t3 != NULL){
				t4 = t3;
				while(t4->l != NULL)t4 = t4->l;
				split(t3,t4,t3,t4->key);
				t2 = t4;
			}
			else{
				t4 = t1;
				while(t4->r != NULL)t4 = t4->r;
				split(t1,t1,t4,t4->key);
				t2 = t4;
			}
			break;
		}
	}
	merge(t1,t1,t2);
	merge(t1,t1,t3);
	output(t1);
	cout<<endl;
}


# include <iostream>
# include <sstream>
# include <cstdio>
# include <cstdlib>
# include <algorithm>
# include <string>
# include <cstring>
# include <cmath>
# include <stack>
# include <queue>
# include <vector>
# include <list>
# include <map>
# include <set>
# include <deque>
# include <iterator>
# include <functional>
# include <bitset>
# include <climits>
# include <ctime>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define odd(x) (x&1)
typedef long long ll;
typedef long double ld;
const ll oo = 2 * 1000 * 1000 * 1000;
const int _cnt = 1000 * 1000;
const int _p = 1000 * 1000 * 1000 + 7;
ll o(ll x) { return x%_p; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a*b / gcd(a, b); }
using namespace std;

void file_put() {
	freopen("filename.in", "r", stdin);
	freopen("filename.out", "w", stdout);
}

int n, m, p, l[500005], r[500005], connect[500005];
string st, opt;
stack <int> S;

void _right(int &p) {
	p = r[p];
}

void _left(int &p) {
	p = l[p];
}

void _delete(int &p) {
	int x = p;
	int y = connect[p];
	if (x > y) swap(x, y);
	r[l[x]] = r[y];
	l[r[y]] = l[x];
	p = r[y];
	if (p == n + 1) p = l[x];
}

int main() {
	//file_put();

	scanf("%d%d%d", &n, &m, &p);
	cin.ignore();
	cin >> st;
	cin.ignore();
	cin >> opt;
	st = " " + st;
	for (int i = 1; i <= n; i++) {
		if (st[i] == '(') S.push(i);
		if (st[i] == ')') {
			connect[i] = S.top();
			connect[S.top()] = i;
			S.pop();
		}
	}
	for (int i = 0; i <= n; i++) r[i] = i + 1;
	for (int i = 1; i <= n + 1; i++) l[i] = i - 1;
	for (int now = 0; now < opt.length(); now++) {
		if (opt[now] == 'R') _right(p);
		if (opt[now] == 'L') _left(p);
		if (opt[now] == 'D') _delete(p);
	}
	int now = r[0];
	while (now && now != n + 1) {
		printf("%c", st[now]);
		now = r[now];
	}
	printf("\n");

	return 0;
}


#include <stdio.h>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
using  namespace std;

int nxt[500005], prv[500005], a[500005], stack[5];

int main()
{
	int n, m, p;
	scanf("%d%d%d\n", &n, &m, &p);
	nxt[0] = 1;
	for (int i = 1; i <= n; i++)
	{
		char c;
		scanf("%c", &c);
		a[i] = (c == '(') ? 0 : 1;
		nxt[i] = i + 1;
		prv[i] = i - 1;
	}
	scanf("\n");
	for (int i = 0; i < m; i++)
	{
		char c;
		scanf("%c", &c);
		{
			if (c == 'L')
				p = prv[p];
			else if (c == 'R')
				p = nxt[p];
			else
			{
				int first = p;
				stack[0] = a[p];
				int ss = 0;
				while (true)
				{
					if (stack[0] == a[p])
						ss++;
					else
						ss--;
					if (stack[0] == 1)
					{
						p = prv[p];
					}
					else
					{
						p = nxt[p];
					}
					if (ss == 0)
						break;
				}
				if (stack[0] == 0)
				{
					first = prv[first];
				}
				else
				{
					first = nxt[first];
				}
				if (stack[0] == 0)
				{
					nxt[first] = p;
					prv[p] = first;
				}
				else
				{
					prv[first] = p;
					nxt[p] = first;
					p = first;
				}
				while (p > n)
					p = prv[p];
			}
		}
	}
	p = nxt[0];
	while (p <= n)
	{
		printf((a[p] == 0) ? "(" : ")");
		p = nxt[p];
	}
}


#include <string>
#include <iostream>
#include <stack>

using namespace std;

int paired[500000], l[500000], r[500000];
stack<int> b;

int main() {
	int n, m, p;
	cin >> n >> m >> p;
	string s, c;
	cin >> s >> c;
	for (int i = 0; i < n; ++i) {
		if (s[i] == '(') {
			b.push(i);
		} else {
			paired[i] = b.top();
			paired[b.top()] = i;
			b.pop();
		}
		l[i] = i - 1;
		r[i] = i + 1;
	}
	r[n - 1] = -1;

	--p;
	int start = 0;
	for (int i = 0; i < m; ++i) {
		if (c[i] == 'L') {
			p = l[p];
		} else if (c[i] == 'R') {
			p = r[p];
		} else {
			int minp = min(p, paired[p]);
			int maxp = max(p, paired[p]);
			if (l[minp] != -1) {
				r[l[minp]] = r[maxp];
			} else {
				start = r[maxp];
			}
			if (r[maxp] != - 1) {
				l[r[maxp]] = l[minp];
			}
			if (r[maxp] == -1) {
				p = l[minp];
			} else {
				p = r[maxp];
			}
		}
	}

	for (int i = start; i != -1; i = r[i]) {
		cout << s[i];
	}
	cout << endl;

	return 0 ;
}


#include <string>
#include <iostream>
#include <stack>

using namespace std;

int paired[500000], l[500000], r[500000];
stack<int> b;

int main() {
	int n, m, p;
	cin >> n >> m >> p;
	string s, c;
	cin >> s >> c;
	for (int i = 0; i < n; ++i) {
		if (s[i] == '(') {
			b.push(i);
		} else {
			paired[i] = b.top();
			paired[b.top()] = i;
			b.pop();
		}
		l[i] = i - 1;
		r[i] = i + 1;
	}
	r[n - 1] = -1;

	--p;
	int start = 0;
	for (int i = 0; i < m; ++i) {
		if (c[i] == 'L') {
			p = l[p];
		} else if (c[i] == 'R') {
			p = r[p];
		} else {
			int minp = min(p, paired[p]);
			int maxp = max(p, paired[p]);
			if (minp != 0) {
				r[minp - 1] = r[maxp];
			} else {
				start = r[maxp];
			}
			if (maxp != n - 1) {
				l[maxp + 1] = l[minp];
			}
			if (r[maxp] == -1) {
				p = l[minp];
			} else {
				p = r[maxp];
			}
		}
	}

	for (int i = start; i != -1; i = r[i]) {
		cout << s[i];
	}
	cout << endl;
	return 0 ;
}