Problem A
Delimiter Soup
![/problems/delimitersoup/file/statement/en/img-0001.jpg](/problems/delimitersoup/file/statement/en/img-0001.jpg)
Whenever a programmer starts to learn a Lisp, they think that there are too many parentheses in it. Sophia thinks there are too few, so she is making a programming language with only parentheses. To spice it up a bit, she is also adding square brackets (‘[]’) and curly braces (‘{}’) to the language.
Right now, she is struggling to make people use it for production code. Obviously, it has to be because of the bad error messages you get when you mess up the delimiters! Right now, you only get the error message ‘syntax error’ when you mess them up.
Any opening delimiter must be closed by the same type of delimiter: ‘(’ is closed with ‘)’, ‘[’ is closed by ‘]’, etc.
Sophia wants to improve the error message so that you at least get some help finding out where it all went wrong.
Input
The input consists of two lines. The first line contains an integer $|L|$, the length of the next line. The next line contains $L$, the program you want to validate.
Output
Output the character and the $0$-indexed location of the first closing delimiter that does not match with the opening delimiter.
If there are no errors, or there are more opening delimiters than closing delimiters, print ‘ok so far’ instead.
Limits
-
$1 \leq |L| \leq 200$
-
$L$ contains only the characters ‘()[]{}’ and spaces
-
$L$ does not start with a space character
Sample Input 1 | Sample Output 1 |
---|---|
8 ([] [] ] |
] 7 |
Sample Input 2 | Sample Output 2 |
---|---|
13 (([] [[]] ()) |
ok so far |
Sample Input 3 | Sample Output 3 |
---|---|
21 [ { { () () () () } ] |
] 20 |
Sample Input 4 | Sample Output 4 |
---|---|
27 [ { [[()]] (({})) } ] () {} |
ok so far |
Sample Input 5 | Sample Output 5 |
---|---|
19 [[]] () ) [] {{}} { |
) 8 |