A binary tree is a valid binary search tree if, for every node, all values in its entire left subtree are strictly less than the node's value, and all values in its entire right subtree are strictly greater. (Duplicate values make the tree invalid.) Decide whether the given tree is a valid BST.
Input format
One line: the binary tree as a level-order array.
The tree is encoded on ONE line as a space-separated level-order (breadth-first) array. The token null marks a missing child; the children of a null are omitted from the array. An empty tree is written as the single token null.
Output format
Print YES if the tree is a valid binary search tree, otherwise NO. An empty tree and a single node are valid.
Constraints
- The tree has between 0 and 1000 nodes.
- Each node value is an integer with absolute value at most 1000000.