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 char in s: new_dp = defaultdict(int) for (min_prev, max_prev), cnt in dp.items(): chars = [] if char == '.': chars = ['(', ')', '?'] else: chars = [char] for c in chars: if c == '(': new_min = min_prev + 1 new_max = max_prev + 1 elif c == ')': new_min = min_prev - 1 new_max = max_prev - 1 else: # '?' new_min = min_prev - 1 new_max = max_prev + 1 new_min = max(new_min, 0) if new_max < 0: continue new_dp[(new_min, new_max)] = (new_dp[(new_min, new_max)] + cnt) % MOD dp = new_dp total = 0 for (min_bal, max_bal), cnt in dp.items(): if min_bal <= 0 <= max_bal: total = (total + cnt) % MOD print(total % MOD)