open System let is_kadomatsu (x, y, z) = x <> y && y <> z && (x < y || y < z) && (x > y || y > z) let erase_all_at is xs = [| for i in 0..(Array.length xs - 1) do if is |> Set.contains i |> not then yield xs.[i] |] // 部分門松列の列挙 let enum_subkadomatsus (xs: _ []) = let n = xs.Length [ for i in 0..(n - 1) do for j in (i + 1)..(n - 1) do for k in (j + 1)..(n - 1) do if (xs.[i], xs.[j], xs.[k]) |> is_kadomatsu then let ys = xs |> erase_all_at (Set.ofList [i; j; k]) yield ((i, j, k), ys) ] // ある部分門松列を消して絶対に勝てるなら、それを返す let rec fr_turn ks = enum_subkadomatsus ks |> List.tryFind (fun (i3, ks') -> en_turn ks' ) and en_turn ks = enum_subkadomatsus ks |> List.forall (fun ((x, y, z), ks') -> fr_turn ks' |> Option.isSome ) [] let main _ = let _ = Console.ReadLine() |> int let ks = Console.ReadLine().Split(' ') |> Array.map int match fr_turn ks with | Some ((i, j, k), _) -> printfn "%d %d %d" i j k | None -> printfn "-1" //exit code 0