Valid Brackets

View as PDF

Submit solution

Points: 5
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type

Given a sequence of brackets, determine whether or not it is balanced. A sequence of brackets is balanced if each opening bracket has a corresponding closing bracket in the correct location. For example ()[{}] is balanced but ([]} and ([]([]{} are not. Here are some more unbalanced bracket sequences:

([)]
))((
{{))

Input

The first line of input is an even number, n 2 \le n \le 100, representing the number of bracket characters that must be processed.
The next line of input is n bracket characters consisting only of ()[]{}.

Output

If the bracket sequence is valid, output YES. Otherwise output NO.

Sample Input

4
(){}

Sample Output

YES

Comments

There are no comments at the moment.