eolymp
bolt
Try our new interface for solving problems

Tree

One of the well-known data structures to represent sets is a binary search tree. Each node v of this tree contains a single element of the set, all elements in the left subtree of v must be less than the element in v, and the elements in the right subtree of v must be greater than the element v. Example of a binary search tree is shown in the figure. Node called the root, if it has no parent (node 5 in the figure). The node is called a leaf, if it has no children (nodes 2, 4 and 8 in the figure). By the tree is called a sequence of numbers of nodes, such that each next node is a direct descendant of the previous one.

prb468

You are given a sequence of unique integers. Required to determine whether there is a binary search tree, in which this sequence is a path from the root to any leaf. For example, a search tree path 5-1-3-2 exist, and with the path 5-2-3-1 - no.

Input

Given a sequence of numbers separated by spaces and/or translated strings. Prior to the first and after the last number can be spaces and line breaks. All numbers are different. The number of integers from 1 to 50 000. The values of numbers from -2 147 483 648 to 2 147 483 647 inclusive.

Output

Remove the word "YES", if the tree corresponding to the specified path exists, and "NO" otherwise.

Time limit 1 second
Memory limit 128 MiB
Input example #1
5 1 3 2
Output example #1
YES
Input example #2
5 2 3 1
Output example #2
NO
Author Igor Andrianov