Fix the bracket sequence
Given a string
sof opening and closing brackets, you are allowed to change some opening brackets to closing ones and some closing to opening ones. At least how many operations are necessary to obtain a valid sequence of brackets?
The only line of the input contains the string
s(1 ≤ |s| ≤ ). It’s guaranteed that the length of
The program should print the least amount of modifications needed to make the sequence valid.
- ()(( → ()() ⇒ 1 modification
- )( → () ⇒ 2 modifications
- ()() ⇒ no modifications needed
- ((() → ()() ⇒ 2 modifications
Time limit: 1 seconds
Memory limit: 512 MB
Output limit: 1 MB