def isBalanced(s):
    left_symbol = ['{', '[', '(']
    right_symbol = ['}', ']', ')']
    for i in range(3):
        left_count = s.count(left_symbol[i])
        right_count = s.count(right_symbol[i])
        if (left_count != right_count):
            return 'NO'
    _stack = []
    for i in range(len(s)):
        char = s[i]
        if (char in {'{', '[', '('}):
            _stack.append(char)
        if (char in {'}', ']', ')'}):
            index_of_right = right_symbol.index(char)
            index_of_left = left_symbol.index(_stack.pop((- 1)))
            if (index_of_left == index_of_right):
                pass
            else:
                return 'NO'
    if (len(_stack) == 0):
        return 'YES'
    else:
        return 'NO'
def isBalanced(s):
    left_symbol = ['{', '[', '(']
    right_symbol = ['}', ']', ')']
    for i in range(3):
        left_count = s.count(left_symbol[i])
        right_count = s.count(right_symbol[i])
        if (left_count != right_count):
            return 'NO'
    _stack = []
    for i in range(len(s)):
        char = s[i]
        if (char in {'{', '[', '('}):
            _stack.append(char)
        if (char in {'}', ']', ')'}):
            index_of_right = right_symbol.index(char)
            index_of_left = left_symbol.index(_stack.pop((- 1)))
            if (index_of_left == index_of_right):
                pass
            else:
                return 'NO'
    if (len(_stack) == 0):
        return 'YES'
    else:
        return 'NO'