MOD = 998244353 s = input().strip() n = len(s) if n % 2 != 0: print(0) exit() current_dp = {(0, 0): 1} for i in range(n): next_dp = {} char = s[i] possible_chars = ['(', ')', '?'] if char == '.' else [char] for (min_b, max_b), cnt in current_dp.items(): for c in possible_chars: if c == '(': new_min_p = min_b + 1 new_max_p = max_b + 1 elif c == ')': new_min_p = min_b - 1 new_max_p = max_b - 1 else: # '?' new_min_p = min_b - 1 new_max_p = max_b + 1 new_min = max(new_min_p, 0) new_max = new_max_p if new_max < 0 or new_min > new_max: continue key = (new_min, new_max) next_dp[key] = (next_dp.get(key, 0) + cnt) % MOD current_dp = next_dp if not current_dp: break # No possible ways left ans = 0 for (min_b, max_b), cnt in current_dp.items(): if min_b <= 0 <= max_b: ans = (ans + cnt) % MOD print(ans)