Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n = int(input())
- open_brackets = 0
- for i in range(n):
- bracket = input()
- if bracket == ")":
- open_brackets -= 1
- if open_brackets < 0:
- break
- elif bracket == "(":
- open_brackets += 1
- if open_brackets > 1:
- break
- if open_brackets == 0:
- print("BALANCED")
- else:
- print("UNBALANCED")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement