#include #include #include #include #include #include using namespace std; using i32 = int32_t; using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; #define rep(i,n) for(int i=0; i<(int)(n); i++) const i64 INF = 1001001001001001001; using Modint = atcoder::static_modint<998244353>; int main(){ string S; cin >> S; int N = S.size(); vector dp0(N+1, 0); vector dp1(N+1, 0); dp0[0] = 1; vector tmp0(N+1, 0); vector tmp1(N+1, 0); auto goL = [&](){ for(int i=N; i>=1; i--) tmp0[i] += dp0[i-1]; for(int i=N; i>=1; i--) tmp1[i] += dp1[i-1]; }; auto goR = [&](){ for(int i=N; i>=1; i--) tmp0[i-1] += dp0[i]; for(int i=N; i>=1; i--) tmp1[i-1] += dp1[i]; }; auto goQ = [&](){ for(int i=N; i>=1; i--) tmp0[i] += dp0[i-1]; for(int i=N; i>=1; i--) tmp1[i-1] += dp1[i]; for(int i=N; i>=1; i--) tmp1[i-1] += dp0[i]; }; for(char c : S){ if(c == '('){ goL(); } if(c == ')'){ goR(); } if(c == '?'){ goQ(); } if(c == '.'){ goL(); goR(); goQ(); } swap(dp0, tmp0); swap(dp1, tmp1); for(auto& a : tmp0) a = 0; for(auto& a : tmp1) a = 0; } Modint ans = dp0[0] + dp1[0]; cout << ans.val() << '\n'; return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } } ios_do_not_sync_instance;