Given a word made up of only opening and closing parentheses and square brackets, we can do two kind of operations:
What is the minimum cost of converting a given word into a correct parenthesization? For instance, if the word is “](”, then we can get the correct parenthesization “[]” by two turns and one transformation, with total cost 4.
Input
Input consists of several cases. Every case consists of one word with opening and closing parentheses and square brackets. All the words have even sizes between 2 and 100.
Output
For every case, print the minimum cost of parenthesizing correctly.
Hint
The expected solution has time cost Θ(n3 ) and space cost Θ(n2 ).
Input
() ()[] ([]( )]]) ])[( ]( )((]([(]
Output
0 0 1 2 6 4 9