#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef double db;
const int N = 5047;
const int mod = 998244353;
int add(int a, int b)
{
return a + b < mod ? a + b : a + b - mod;
}
void updAdd(int& a, int b)
{
a += b;
if (a >= mod)
a -= mod;
}
int sub(int a, int b)
{
return a - b >= 0 ? a - b : a - b + mod;
}
void updSub(int& a, int b)
{
a -= b;
if (a < 0)
a += mod;
}
int mult(int a, int b)
{
return (LL)a * b % mod;
}
int binpow(int a, LL n)
{
int res = 1;
while (n)
{
if (n & 1)
res = mult(res, a);
a = mult(a, a);
n /= 2;
}
return res;
}
int inv[N], fact[N], ifact[N];
void init()
{
inv[1] = 1;
FOR(i, 2, N)
{
inv[i] = mult(mod - mod / i, inv[mod % i]);
}
fact[0] = ifact[0] = 1;
FOR(i, 1, N)
{
fact[i] = mult(fact[i - 1], i);
ifact[i] = mult(ifact[i - 1], inv[i]);
}
}
int C(int n, int k)
{
if (k < 0 || k > n)
return 0;
return mult(fact[n], mult(ifact[n - k], ifact[k]));
}
const int mod1 = 1e9 + 7;
const int mod2 = 1e9 + 9;
const int P = 4747;
const LL modH = (LL)mod1 * mod2;
LL pwH[N];
LL addH(LL a, LL b)
{
return a + b < modH ? a + b : a + b - modH;
}
LL multH(LL a, LL b)
{
return (__int128)a * b % modH;
}
VI poses[N];
int mn[N][N];
LL h1[N][N], h2[N][N];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
init();
pwH[0] = 1;
FOR(i, 1, P)
{
pwH[i] = multH(pwH[i - 1], P);
}
int n;
string s;
cin >> n >> s;
VI a(n + 1);
FOR(i, 0, n)
{
if (s[i] == '(')
a[i + 1] = a[i] + 1;
else
a[i + 1] = a[i] - 1;
}
FOR(i, 0, n + 1)
{
assert(a[i] >= 0);
poses[a[i]].PB(i);
}
RFOR(i, n + 1, 0)
{
FOR(j, i, n + 1)
{
if (i == j)
{
mn[i][i] = a[i];
}
else
{
mn[i][j] = min(mn[i][j - 1], a[j]);
h1[i][j] = addH(s[i], multH(P, h1[i + 1][j]));
h2[i][j] = addH(multH(P, h2[i][j - 1]), s[j - 1] ^ 1);
}
}
}
unordered_map<LL, int> cntHashes;
int ans = 1;
FOR(bal, 0, n + 1)
{
int j;
for (int i = 0; i < SZ(poses[bal]); i = j)
{
cntHashes.clear();
j = i + 1;
while (j < SZ(poses[bal]) && mn[poses[bal][i]][poses[bal][j]] == bal)
{
int p1 = poses[bal][j - 1], p2 = poses[bal][j];
LL hDir = h1[p1][p2], hRev = h2[p1][p2];
if (hDir != hRev)
{
ans = mult(2, ans);
if (hDir > hRev)
{
swap(hDir, hRev);
}
}
cntHashes[hDir]++;
j++;
}
ans = mult(ans, fact[j - i - 1]);
for (auto [hsh, cnt] : cntHashes)
{
ans = mult(ans, ifact[cnt]);
}
}
}
cout << ans << "\n";
return 0;
}