#C9452. Check Height-Balanced Binary Tree

    ID: 53547 Type: Default 1000ms 256MiB

Check Height-Balanced Binary Tree

Check Height-Balanced Binary Tree

Given a string representation of a binary tree, determine whether the tree is height-balanced. A binary tree is said to be height-balanced if, for every node, the absolute difference between the heights of its left and right subtrees is at most 1. The tree is represented in the following format:

( node(left_subtree)(right_subtree) )

An empty subtree is represented by an empty pair of parentheses. If the input string is empty, consider it as an empty tree which is balanced. You need to read the input from standard input (stdin) and display the result to standard output (stdout).

inputFormat

A single line containing the string representation of the binary tree. The input is provided via standard input (stdin).

outputFormat

Print "Yes" if the binary tree is height-balanced, otherwise print "No". The output should be written to standard output (stdout).## sample

1(2(4)(5))(3)
Yes