main = interact $ unlines . map (ball 0 0 . map read . words) . read' . lines
 where read' (n:xs) = take (read n) xs

ball :: Int -> Int -> [Int] -> String
ball l r bs
??| null bs = "YES"
??| l < head bs = ball (head bs) r (tail bs)
??| r < head bs = ball l (head bs) (tail bs)
??| otherwise = "NO"