// author : Nguyễn Trọng Nguyễn - ITK22 NBK
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair <int, int>
#define fi first
#define sc second
const int maxn = 3000;
const int inf = (int)1e9;
const int mod = (int)1e9 + 7;
int t, n, k;
char a[maxn + 5];
ll dp[maxn + 5][2][maxn / 2 + 5];
char s[6] = {'(', ')', '[', ']', '{', '}'};
ll rnk = 1;
stack <char> st;
void add (ll &a, ll b) {
a += b;
if (a >= mod) a -= mod;
}
void init () {
cin >> t >> n >> k;
for (int i = 0; i < n; i++)
cin >> a[i];
}
ll calc (int id, bool f, int len, bool ok) {
if (len < 0 or len > k) return 0;
if (id == n) return len == 0;
if (dp[id][f][len] != -1) return dp[id][f][len];
ll res = 0;
int mx = ok == 1 ? 6 : 2;
for (int i = 0; i < mx; i++) {
if (i & 1) {
if (len == 0 or st.top() != s[i - 1]) continue;
st.pop();
add(res, calc(id + 1, 1, len - 1, 1));
st.push(s[i - 1]);
}
else {
st.push(s[i]);
add(res, calc(id + 1, 0, len + 1, ok));
st.pop();
}
}
return dp[id][f][len] = res;
}
void getrank (int id = 0, int len = 0) {
if (id == n or len < 0 or len > k) return ;
int mx = t == 1 ? 2 : 6;
for (int i = 0; i < mx; i++) {
if (i & 1) {
if (len == 0 or st.top() != s[i - 1]) continue;
st.pop();
if (a[id] != s[i]) add(rnk, calc(id + 1, 1, len - 1, 1));
else {
getrank(id + 1, len - 1);
return ;
}
st.push(s[i - 1]);
}
else {
st.push(s[i]);
if (a[id] != s[i]) add(rnk, calc(id + 1, 0, len + 1, t == 2));
else {
getrank(id + 1, len + 1);
return ;
}
st.pop();
}
}
}
void process () {
memset(dp, -1, sizeof dp);
getrank();
cout << rnk;
}
signed main () {
cin.tie(0)->sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("test.inp","r",stdin);
freopen("test.out","w",stdout);
#endif
init();
process();
return 0;
}
Ly8gYXV0aG9yIDogTmd1eeG7hW4gVHLhu41uZyBOZ3V54buFbiAtIElUS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