Problem C
Bracket Pairing

There are four types of brackets: round (), square [], curly {}, and angle <>. A bracket sequence is defined to be valid as follows:
-
An empty sequence is valid.
-
If
is a valid bracket sequence, then is a valid bracket sequence, where is an open bracket, is a close bracket, and are of the same type. -
If
and are valid bracket sequences, then the concatenation of and , , is a valid bracket sequence.
You have a bracket sequence in which some brackets are given, but the others are unknown and represented by question marks (‘?’). You shall fill in each unknown bracket using the four types of brackets described above and obtain a valid bracket sequence. How many different valid bracket sequences can you obtain?
Input
The input has a single line giving a non-empty bracket
sequence. The length of the sequence is even and no larger than
Output
Output the number of different valid bracket sequences you can obtain.
Sample Input 1 | Sample Output 1 |
---|---|
(??) |
5 |
Sample Input 2 | Sample Output 2 |
---|---|
(<{}>??] |
1 |
Sample Input 3 | Sample Output 3 |
---|---|
(?]] |
0 |