open System open System.Text.RegularExpressions let pattern = new Regex(@"c.*?w.*?w") let searchCww str = pattern.Matches(str) |> function m when m.Count = 0 -> -1 | m -> seq { 0..(str.Length - 3) } |> Seq.map (fun i -> pattern.Match(str, i)) |> Seq.choose (function m when m.Success -> Some m.Length | _ -> None) |> Seq.min Console.ReadLine () |> searchCww |> printfn "%d"