#include <bits/stdc++.h>
#define int long long
using namespace std;
template <typename T>
inline bool maxi(T &x, const T &val)
{
if (x < val)
return x = val, true;
return false;
}
template <typename T>
inline bool mini(T &x, const T &val)
{
if (x > val)
return x = val, true;
return false;
}
const int maxn = 3010, maxk = maxn / 2, mod = 1e9 + 7;
int n, k;
string s;
int dp[maxn][2][maxk];
inline void add(int &x, const int &val)
{
if ((x += val) >= mod) x -= mod;
}
int cal(int x, int type, int cur)
{
if (x == n)
{
return cur == 0;
}
int &d = dp[x][type][cur];
if (d != -1)
return d;
d = 0;
if (cur < k)
{
add(d, 3ll * cal(x + 1, 0, cur + 1) % mod);
}
if (cur > 0)
{
add(d, cal(x + 1, 1, cur - 1));
}
return d;
}
int calsub1(int x, int type, int cur)
{
if (x == n)
{
return cur == 0;
}
int &d = dp[x][type][cur];
if (d != -1)
return d;
d = 0;
if (cur < k)
{
add(d, calsub1(x + 1, 0, cur + 1) % mod);
}
if (cur > 0)
{
add(d, cal(x + 1, 1, cur - 1));
}
return d;
}
void solvesub1()
{
memset(dp, -1, sizeof dp);
int res = 1;
int cur = 0;
vector<char> dak;
for (int i = 0; i < n; i++)
{
if (cur < k) {
if ('(' < s[i])
{
add(res, calsub1(i + 1, 0, cur + 1));
}
}
if (s[i] == '(')
{
dak.push_back(s[i]);
cur++;
}
else
{
dak.pop_back();
cur--;
}
}
cout << res << '\n';
}
void solve()
{
int T;
cin >> T;
cin >> n >> k;
cin >> s;
if (T == 1) {
solvesub1();
return;
}
memset(dp, -1, sizeof dp);
int res = 1;
int cur = 0;
vector<char> dak;
for (int i = 0; i < n; i++)
{
if (cur < k) {
if ('(' < s[i])
{
add(res, cal(i + 1, 0, cur + 1));
}
if ('[' < s[i])
{
add(res, cal(i + 1, 0, cur + 1));
}
if ('{' < s[i])
{
add(res, cal(i + 1, 0, cur + 1));
}
}
if (cur > 0) {
char c = dak.back();
if ((c == '(' && ')' < s[i])
|| (c == '[' && ']' < s[i])
|| (c == '{' && '}' < s[i])) {
add(res, cal(i + 1, 1, cur - 1));
}
}
if (s[i] == '(' || s[i] == '[' || s[i] == '{')
{
dak.push_back(s[i]);
cur++;
}
else
{
dak.pop_back();
cur--;
}
}
cout << res << '\n';
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("test.inp","r",stdin);
freopen("test.out","w",stdout);
#endif
solve();
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgaW50IGxvbmcgbG9uZwoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnRlbXBsYXRlIDx0eXBlbmFtZSBUPgppbmxpbmUgYm9vbCBtYXhpKFQgJngsIGNvbnN0IFQgJnZhbCkKewogICAgaWYgKHggPCB2YWwpCiAgICAgICAgcmV0dXJuIHggPSB2YWwsIHRydWU7CiAgICByZXR1cm4gZmFsc2U7Cn0KCnRlbXBsYXRlIDx0eXBlbmFtZSBUPgppbmxpbmUgYm9vbCBtaW5pKFQgJngsIGNvbnN0IFQgJnZhbCkKewogICAgaWYgKHggPiB2YWwpCiAgICAgICAgcmV0dXJuIHggPSB2YWwsIHRydWU7CiAgICByZXR1cm4gZmFsc2U7Cn0KCmNvbnN0IGludCBtYXhuID0gMzAxMCwgbWF4ayA9IG1heG4gLyAyLCBtb2QgPSAxZTkgKyA3OwppbnQgbiwgazsKc3RyaW5nIHM7CmludCBkcFttYXhuXVsyXVttYXhrXTsKCmlubGluZSB2b2lkIGFkZChpbnQgJngsIGNvbnN0IGludCAmdmFsKQp7CiAgICBpZiAoKHggKz0gdmFsKSA+PSBtb2QpIHggLT0gbW9kOwp9CgppbnQgY2FsKGludCB4LCBpbnQgdHlwZSwgaW50IGN1cikKewogICAgaWYgKHggPT0gbikKICAgIHsKICAgICAgICByZXR1cm4gY3VyID09IDA7CiAgICB9CiAgICBpbnQgJmQgPSBkcFt4XVt0eXBlXVtjdXJdOwogICAgaWYgKGQgIT0gLTEpCiAgICAgICAgcmV0dXJuIGQ7CiAgICBkID0gMDsKICAgIGlmIChjdXIgPCBrKQogICAgewogICAgICAgIGFkZChkLCAzbGwgKiBjYWwoeCArIDEsIDAsIGN1ciArIDEpICUgbW9kKTsKICAgIH0KICAgIGlmIChjdXIgPiAwKQogICAgewogICAgICAgIGFkZChkLCBjYWwoeCArIDEsIDEsIGN1ciAtIDEpKTsKICAgIH0KICAgIHJldHVybiBkOwp9CgppbnQgY2Fsc3ViMShpbnQgeCwgaW50IHR5cGUsIGludCBjdXIpCnsKICAgIGlmICh4ID09IG4pCiAgICB7CiAgICAgICAgcmV0dXJuIGN1ciA9PSAwOwogICAgfQogICAgaW50ICZkID0gZHBbeF1bdHlwZV1bY3VyXTsKICAgIGlmIChkICE9IC0xKQogICAgICAgIHJldHVybiBkOwogICAgZCA9IDA7CiAgICBpZiAoY3VyIDwgaykKICAgIHsKICAgICAgICBhZGQoZCwgY2Fsc3ViMSh4ICsgMSwgMCwgY3VyICsgMSkgJSBtb2QpOwogICAgfQogICAgaWYgKGN1ciA+IDApCiAgICB7CiAgICAgICAgYWRkKGQsIGNhbCh4ICsgMSwgMSwgY3VyIC0gMSkpOwogICAgfQogICAgcmV0dXJuIGQ7Cn0KCnZvaWQgc29sdmVzdWIxKCkKewogICAgbWVtc2V0KGRwLCAtMSwgc2l6ZW9mIGRwKTsKICAgIGludCByZXMgPSAxOwogICAgaW50IGN1ciA9IDA7CiAgICB2ZWN0b3I8Y2hhcj4gZGFrOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspCiAgICB7CiAgICAgICAgaWYgKGN1ciA8IGspIHsKICAgICAgICAgICAgaWYgKCcoJyA8IHNbaV0pCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGFkZChyZXMsIGNhbHN1YjEoaSArIDEsIDAsIGN1ciArIDEpKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAoc1tpXSA9PSAnKCcpCiAgICAgICAgewogICAgICAgICAgICBkYWsucHVzaF9iYWNrKHNbaV0pOwogICAgICAgICAgICBjdXIrKzsKICAgICAgICB9CiAgICAgICAgZWxzZQogICAgICAgIHsKICAgICAgICAgICAgZGFrLnBvcF9iYWNrKCk7CiAgICAgICAgICAgIGN1ci0tOwogICAgICAgIH0KICAgIH0KICAgIGNvdXQgPDwgcmVzIDw8ICdcbic7Cn0KCnZvaWQgc29sdmUoKQp7CiAgICBpbnQgVDsKICAgIGNpbiA+PiBUOwogICAgY2luID4+IG4gPj4gazsKICAgIGNpbiA+PiBzOwogICAgaWYgKFQgPT0gMSkgewogICAgICAgIHNvbHZlc3ViMSgpOwogICAgICAgIHJldHVybjsKICAgIH0KICAgIG1lbXNldChkcCwgLTEsIHNpemVvZiBkcCk7CiAgICBpbnQgcmVzID0gMTsKICAgIGludCBjdXIgPSAwOwogICAgdmVjdG9yPGNoYXI+IGRhazsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKQogICAgewogICAgICAgIGlmIChjdXIgPCBrKSB7CiAgICAgICAgICAgIGlmICgnKCcgPCBzW2ldKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBhZGQocmVzLCBjYWwoaSArIDEsIDAsIGN1ciArIDEpKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoJ1snIDwgc1tpXSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgYWRkKHJlcywgY2FsKGkgKyAxLCAwLCBjdXIgKyAxKSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKCd7JyA8IHNbaV0pCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGFkZChyZXMsIGNhbChpICsgMSwgMCwgY3VyICsgMSkpOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChjdXIgPiAwKSB7CiAgICAgICAgICAgIGNoYXIgYyA9IGRhay5iYWNrKCk7CiAgICAgICAgICAgIGlmICgoYyA9PSAnKCcgJiYgJyknIDwgc1tpXSkKICAgICAgICAgICAgIHx8IChjID09ICdbJyAmJiAnXScgPCBzW2ldKQogICAgICAgICAgICAgfHwgKGMgPT0gJ3snICYmICd9JyA8IHNbaV0pKSB7CiAgICAgICAgICAgICAgICBhZGQocmVzLCBjYWwoaSArIDEsIDEsIGN1ciAtIDEpKTsKICAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHNbaV0gPT0gJygnIHx8IHNbaV0gPT0gJ1snIHx8IHNbaV0gPT0gJ3snKQogICAgICAgIHsKICAgICAgICAgICAgZGFrLnB1c2hfYmFjayhzW2ldKTsKICAgICAgICAgICAgY3VyKys7CiAgICAgICAgfQogICAgICAgIGVsc2UKICAgICAgICB7CiAgICAgICAgICAgIGRhay5wb3BfYmFjaygpOwogICAgICAgICAgICBjdXItLTsKICAgICAgICB9CiAgICB9CiAgICBjb3V0IDw8IHJlcyA8PCAnXG4nOwp9CgpzaWduZWQgbWFpbigpCnsKCSNpZm5kZWYgT05MSU5FX0pVREdFCglmcmVvcGVuKCJ0ZXN0LmlucCIsInIiLHN0ZGluKTsKCWZyZW9wZW4oInRlc3Qub3V0IiwidyIsc3Rkb3V0KTsKCSNlbmRpZgoJc29sdmUoKTsKfQo=