# https://www.hackerrank.com/challenges/balanced-brackets/problem?h_l=interview&playlist_slugs%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D=stacks-queues
def is_balanced(s):
	if len(s)%2!=0:
		return 'NO'

	paren = {'(':')', '[':']', '{':'}'}
	opener = paren.keys()
	closer = paren.values()
	stack = []

	for i in range(len(s)):
		if s[i] in opener: 
			stack.append(s[i])
		elif (s[i] in closer) and stack:
			if paren[stack[-1]] == s[i]:
				stack.pop()
			else: 
				return 'NO'
		else:
			return 'NO'
	if not stack:
		return 'YES'

# print(is_balanced("{[()]}"))
# print(is_balanced('{[(])}'))
# print(is_balanced('{{[[(())]]}}'))
print(is_balanced('{(([])[])[]]}'))#no