06. Balanced Brackets
Здравейте банда! Може ли някой да ми помогне да разбера къде греша. Judge ми дава 85/100
6. Balanced Brackets
You will receive n lines. On those lines, you will receive one of the following:
- Opening bracket – “(“,
- Closing bracket – “)” or
- Random string
Your task is to find out if the brackets are balanced. That means after every closing bracket should follow an opening one. Nested parentheses are not valid, and if two consecutive opening brackets exist, the expression should be marked as unbalanced.
Input
- On the first line, you will receive n – the number of lines, which will follow
- On the next n lines, you will receive “(”, “)” or another string
Output
You have to print “BALANCED”, if the parentheses are balanced and “UNBALANCED” otherwise.
Constraints
- n will be in the interval [1…20]
- The length of the stings will be between [1…100] characters
Examples
Input |
Output |
|
Input |
Output |
8 ( 5 + 10 ) * 2 + ( 5 ) -12 |
BALANCED |
|
6 12 * ) 10 + 2 - ( 5 + 10 )
|
UNBALANCED |