Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- number_of_lines = int(input())
- is_balanced = True
- pattern = ''
- for each_line in range(number_of_lines):
- command = input()
- if command == ')' and pattern == '':
- is_balanced = False
- break
- else:
- if command in '()':
- pattern += command
- if pattern == '()':
- is_balanced = True
- pattern = ''
- elif pattern == '((':
- is_balanced = False
- break
- if is_balanced:
- print('BALANCED')
- else:
- print('UNBALANCED')
Add Comment
Please, Sign In to add comment