Swapping Brackets
Time limit1.5sMemory limit1024 MB
Count the nonempty position sets S where rearranging the brackets inside S can turn the sequence into a proper bracket sequence, modulo 998244353.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Combinatorics, String
- Solved
- No attempts yet
Problem
You are given a bracket sequence with open brackets and closed brackets. Let be a nonempty set of integers from to , inclusive. You can choose two indices in , not necessarily adjacent, and swap the brackets at those two positions.
Find the number of sets for which repeatedly applying this operation any number of times turns the sequence into a proper bracket sequence.
Input
The first line contains one integer .
The second line contains a string of brackets, each either ( or ).
Output
Print the number of possible sets modulo . The number is prime.
Constraints
- The given bracket sequence contains open brackets and closed brackets.