#include #include #include using namespace std; using namespace atcoder; struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; #define FOR(i, begin, end) for(int i=(begin);i<(end);i++) #define REP(i, n) FOR(i,0,n) using mint = modint998244353; int main(){ string s; cin >> s; if(s.size() % 2 != 0){ cout << 0 << endl; return 0; } int n = s.size() / 2; vector>> dp(n + 1, vector>(n + 1, vector(2, 0))); dp[0][0][0] = 1; REP(i, n + 1) REP(j, i + 1){ int pos = i + j; if(pos == 2 * n) continue; const char c = s[pos]; REP(k, 2){ // '(' if((c == '(' || c == '.') && i + 1 <= n){ dp[i + 1][j][k] += dp[i][j][k]; } // ')' if((c == ')' || c == '.') && j + 1 <= i){ dp[i][j + 1][k] += dp[i][j][k]; } // '{' if((c == '?' || c == '.') && i + 1 <= n){ if(k == 0) dp[i + 1][j][k] += dp[i][j][k]; } // '}' if((c == '?' || c == '.') && j + 1 <= i){ dp[i][j + 1][1] += dp[i][j][k]; } } } mint ans = dp[n][n][0] + dp[n][n][1]; cout << ans.val() << endl; return 0; }