MOD = 998244353 s = input().strip() n = len(s) if n % 2 != 0: print(0) exit() from collections import defaultdict dp = defaultdict(int) dp[(0, 0)] = 1 for c in s: new_dp = defaultdict(int) for (min_prev, max_prev), cnt in dp.items(): possible_chars = [] if c == '.': possible_chars = ['(', ')', '?'] else: possible_chars = [c] for char in possible_chars: if char == '(': new_min = min_prev + 1 new_max = max_prev + 1 elif char == ')': new_min = max(min_prev - 1, 0) new_max = max_prev - 1 if new_max < 0: continue elif char == '?': new_min = max(min_prev - 1, 0) new_max = max_prev + 1 else: assert False, "Invalid character" if new_min > new_max: continue new_dp[(new_min, new_max)] = (new_dp[(new_min, new_max)] + cnt) % MOD dp = new_dp if not dp: break result = 0 for (min_b, max_b), cnt in dp.items(): if min_b <= 0 <= max_b: result = (result + cnt) % MOD print(result % MOD)