open System let is_kadomatsu (x, y, z) = x <> y && y <> z && (x < y || y < z) && (x > y || y > z) let rec tails = function | [] -> [] | x :: xs -> (x, xs) :: tails xs // 部分門松列の列挙 let enum_subkadomatsus xs = xs |> tails |> List.collect (fun (x, ys) -> ys |> tails |> List.collect (fun (y, zs) -> zs |> List.map (fun z -> (x, y, z)) |> List.filter is_kadomatsu )) // ある部分門松列を消して絶対に勝てるなら、それを返す let rec fr_turn ks = enum_subkadomatsus ks |> List.tryFind (fun (x, y, z) -> let ks' = ks |> List.filter (fun k -> k <> x && k <> y && k <> z) en_turn ks' ) and en_turn ks = enum_subkadomatsus ks |> List.forall (fun (x, y, z) -> let ks' = ks |> List.filter (fun k -> k <> x && k <> y && k <> z) fr_turn ks' |> Option.isSome ) [] let main _ = let _ = Console.ReadLine() |> int let ks = Console.ReadLine().Split(' ') |> Array.map int |> Array.toList match fr_turn ks with | Some (x, y, z) -> let i x = ks |> List.tryFindIndex ((=) x) |> Option.get printfn "%d %d %d" (i x) (i y) (i z) | None -> printfn "-1" //exit code 0