main = interact $ unlines . map (ball . map (read::String->Int) . words) . read' . lines
 where read (n:xs) = take (read n) xs
??
ball bs = case ball' 0 0 bs of {True -> "YES"; False -> "NO"}
 where
  ball' l r bs
   | null bs = True
   | l < head bs && r < head bs = ball' (head bs) r (tail bs) || ball' l (head bs) (tail bs)
   | l < head bs = ball' (head bs) r (tail bs)
   | r < head bs = ball' l (head bs) (tail bs)
   | otherwise = False