import sys from collections import defaultdict MOD = 998244353 def main(): s = sys.stdin.readline().strip() dp = defaultdict(int) dp[(0, 0)] = 1 for c in s: next_dp = defaultdict(int) for (min_prev, max_prev), count in dp.items(): if c == '(': new_min = min_prev + 1 new_max = max_prev + 1 if new_max < 0: continue new_min = max(new_min, 0) if new_min <= new_max: next_dp[(new_min, new_max)] = (next_dp[(new_min, new_max)] + count) % MOD elif c == ')': new_min = min_prev - 1 new_max = max_prev - 1 if new_max < 0: continue new_min = max(new_min, 0) if new_min <= new_max: next_dp[(new_min, new_max)] = (next_dp[(new_min, new_max)] + count) % MOD elif c == '?': new_min = min_prev - 1 new_max = max_prev + 1 if new_max < 0: continue new_min = max(new_min, 0) if new_min <= new_max: next_dp[(new_min, new_max)] = (next_dp[(new_min, new_max)] + count) % MOD else: # c is '.' for option in ['(', ')', '?']: if option == '(': nmin = min_prev + 1 nmax = max_prev + 1 elif option == ')': nmin = min_prev - 1 nmax = max_prev - 1 else: # '?' nmin = min_prev - 1 nmax = max_prev + 1 if nmax < 0: continue nmin = max(nmin, 0) if nmin > nmax: continue next_dp[(nmin, nmax)] = (next_dp[(nmin, nmax)] + count) % MOD dp = next_dp total = 0 for (min_val, max_val), count in dp.items(): if min_val <= 0 <= max_val: total = (total + count) % MOD print(total % MOD) if __name__ == '__main__': main()