Problem H
Bracket Matching
Given a bracket sequence
A valid bracket sequence is defined recursively as:
-
“”
-
where is a valid bracket sequence -
where is a valid bracket sequence -
where is a valid bracket sequence -
, where and are valid bracket sequences
Input
The first line of each contains one integer
The second line of each test case contains a string
Output
Output Valid if the sequence is a valid bracket sequence, otherwise output Invalid.
Sample Input 1 | Sample Output 1 |
---|---|
6 ([]{}) |
Valid |
Sample Input 2 | Sample Output 2 |
---|---|
8 (())((() |
Invalid |
Sample Input 3 | Sample Output 3 |
---|---|
6 ([}{]) |
Invalid |