fun readStr () = let fun scan reader stream = SOME (StringCvt.splitl (not o Char.isSpace) reader (StringCvt.skipWS reader stream)) in valOf (TextIO.scanStream scan TextIO.stdIn) end fun intString n = if 0 <= n then Int.toString n else "-" ^ Int.toString (abs n) fun findAnsAux _ [] _ = NONE | findAnsAux i (#"c"::tl) acc = if acc = [] then findAnsAux (i + 1) tl [i] else findAnsAux (i + 1) tl acc | findAnsAux i (#"w"::tl) acc = if acc = [] then findAnsAux (i + 1) tl [] else if List.length acc = 1 then findAnsAux (i + 1) tl (i::acc) else if List.length acc = 2 then SOME (i - List.last acc + 1) else findAnsAux (i + 1) tl acc | findAnsAux i (_::tl) acc = findAnsAux (i + 1) tl acc fun findAns [] NONE = ~1 | findAns [] (SOME x) = x | findAns (h::tl) acc = let val chiwawa = findAnsAux 0 (h::tl) [] in case acc of NONE => findAns tl chiwawa | SOME accV => case chiwawa of NONE => findAns tl acc | SOME chiwawaV => findAns tl (SOME (Int.min (accV, chiwawaV))) end val () = let val s = readStr () val ans = findAns (String.explode s) NONE in print (intString ans ^ "\n") end