// Validator #include #include #include using namespace std; #include "testlib.h" #include using mint = atcoder::modint998244353; #define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++) #define REP(i, n) FOR(i, 0, n) int main(int argc, char *argv[]) { registerValidation(argc, argv); string S = inf.readString(); cerr << S << ' ' << S.size() << endl; inf.readEof(); assert(1 <= S.size() and S.size() <= 4000); for (char c : S) { assert(c == '(' or c == ')' or c == '?' or c == '.'); } const int N = S.size(); vector dp(2, vector(N + 1)); dp[0][0] = dp[1][0] = 1; for (auto c : S) { vector dpnxt(2, vector(N + 1)); if (c != ')' and c != '?') { // Insert ( REP(b, 2) REP(i, dp[b].size()) { if (dp[b][i].val()) { dpnxt[b][i + 1] += dp[b][i]; } } } if (c != '(' and c != '?') { // Insert ) REP(b, 2) REP(i, dp[b].size()) { if (dp[b][i].val() and i) { dpnxt[b][i - 1] += dp[b][i]; } } } if (c == '.' or c == '?') { // Insert ? REP(b, 2) REP(i, dp[b].size()) { if (dp[b][i].val()) { if (b == 0) { dpnxt[0][i + 1] += dp[b][i]; dpnxt[1][i + 1] += dp[b][i]; } else { if (i) { dpnxt[1][i - 1] += dp[b][i]; } } } } } dp = dpnxt; } cout << dp.at(1).at(0).val() << endl; }