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 isAscending (a:int list) = a |> List.pairwise |> List.map (fun (x,y) -> x List.reduce (fun s x -> s && x) type Sol() = member this.Solve() = let D = ria() |> Array.toList let permu = permutations D let ret = Seq.tryFind (fun ar -> ((isAscending (List.take 4 ar ) && (isAscending (List.skip 4 ar ))) = true )) permu if (Option.isSome ret) then "YES" else "NO" |> printfn "%s" let mySol = new Sol() mySol.Solve()