n = int(input()) s = input() def is_correct(s): stack = [] for v in s: stack.append(v) if len(stack) >= 2 and stack[-2] == '(' and stack[-1] == ')': stack.pop() stack.pop() if not stack: return True else: return False def solve(n, s): mod = 998244353 if not is_correct(s): return 0 open = [0] * n close = [0] * n for i in range(n): if s[i] == '(': open[i] += 1 else: close[i] += 1 open[i] += open[i - 1] close[i] += close[i - 1] dp = [[[0] * (n + 1) for _ in range(n + 1)] for _ in range(n + 1)] dp[0][0][0] = 1 for i in range(n): if s[i] == '(': for j in range(i + 1): for k in range(j + 1): dp[i + 1][j + 1][k] += dp[i][j][k] dp[i + 1][j + 1][k] %= mod dp[i + 1][j][k] += dp[i][j][k] dp[i + 1][j][k] %= mod else: for j in range(i + 1): for k in range(j + 1): if j >= k + 1: dp[i + 1][j][k + 1] += dp[i][j][k] dp[i + 1][j][k + 1] %= mod if open[i] - j >= close[i] - k: dp[i + 1][j][k] += dp[i][j][k] dp[i + 1][j][k] %= mod ans = 0 for i in range(n): ans += dp[n][i][i] ans %= mod return ans print(solve(n, s))