#include #include using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); ++i) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; --i) #define ALL(a) a.begin(), a.end() #define Sort(a) sort(a.begin(), a.end()) #define RSort(a) sort(a.rbegin(), a.rend()) #define out(a) cout << a << "\n" typedef long long int ll; typedef long double ld; typedef vector vi; typedef vector vll; typedef vector vc; typedef vector vst; typedef vector vd; typedef pair P; const long long INF = 0x1fffffffffffffff; const long long MOD = 998244353; const double PI = acos(-1); template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template inline T vin(T& vec, U n) { vec.resize(n); for(int i = 0; i < (int) n; ++i) cin >> vec[i]; return vec; } template inline void vout(T vec, string s = "\n"){ for(auto x : vec) cout << x << s; } ll n; string s; void input(){ cin >> n >> s; } void solve(){ vector> dp(n / 2 + 1, vector(n / 2 + 1)); vector> tmp(n / 2 + 1, vector(n / 2 + 1)); ll l = 0, r = 0, currdiff = 0, prevdiff = 0; dp[0][0] = 1; rep(i, n){ if(s[i] == '('){ l++; }else{ r++; } currdiff = l - r; vector

p; for(int j = 0; j <= n / 2; j++){ ll jj = j; if(s[i] == '('){ jj++; }else{ jj--; } if(jj < 0) continue; ll k1 = currdiff - jj, k2 = prevdiff - j; if(k1 < 0 || k2 < 0) continue; tmp[jj][k1] += dp[j][k2]; tmp[jj][k1] %= MOD; tmp[k1][jj] += dp[k2][j]; tmp[k1][jj] %= MOD; p.push_back({jj, k1}); } prevdiff = currdiff; dp = tmp; for(auto x : p){ tmp[x.first][x.second] = 0; tmp[x.second][x.first] = 0; } } out(dp[0][0]); } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); input(); solve(); }