Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n = int(input())
- found_open = False
- balanced = True
- for i in range(n):
- symbol_ = input()
- if symbol_ == '(':
- if not found_open:
- found_open = True
- else:
- balanced = False
- if symbol_ == ')':
- if found_open:
- found_open = False
- else:
- balanced = False
- if not found_open and balanced:
- print('BALANCED')
- else:
- print('UNBALANCED')
Advertisement
Add Comment
Please, Sign In to add comment