Construct Cartesian Tree from Sequence

hard