open System let rec insertions x = function | [] -> [[x]] | (y :: ys) as l -> (x::l)::(List.map (fun x -> y::x) (insertions x ys)) let rec permutations = function | [] -> seq [ [] ] | x :: xs -> Seq.concat (Seq.map (insertions x) (permutations xs)) let ri () = stdin.ReadLine() |> int let ria () = stdin.ReadLine().Split() |> Array.map int let zip3 a b c = Seq.zip a b |> Seq.zip c |> Seq.map (fun (z,(x,y)) -> (x,y,z) ) let isKadmatsu (x,y,z) = ( x <> y ) && ( y <> z) && (x <> z) && ( ((x < y) && (y > z)) || ((x > y) && (y < z))) let isAscendingKadomatsu ((x:int),(y:int),(z:int)) = ( isKadmatsu (x,y,z) ) && (x < z) let isAscendingKadomatsuSeq (a:int list) = let a3 = zip3 a (Seq.skip 1 a) (Seq.skip 2 a) a3 |> Seq.map isAscendingKadomatsu |> Seq.reduce (fun x s -> x && s) type Sol() = member this.Solve() = let D = ria() |> Array.toList let permu = permutations D let ret = Seq.tryFind (fun ar -> isAscendingKadomatsuSeq ar ) permu if (Option.isSome ret) then "YES" else "NO" |> printfn "%s" let mySol = new Sol() mySol.Solve()