using System; using System.Collections.Generic; class Program { static string InputPattern = "InputX"; static List GetInputList() { var WillReturn = new List(); if (InputPattern == "Input1") { WillReturn.Add("ilovechiwawa"); //6 } else if (InputPattern == "Input2") { WillReturn.Add("wachiwachi"); //-1 } else if (InputPattern == "Input3") { WillReturn.Add("chiwaaaaaaamikawayadeeeeesu"); //16 } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List InputList = GetInputList(); string S = InputList[0]; bool FoundAnswer = false; int MinLength = int.MaxValue; for (int I = 0; I <= S.Length - 1; I++) { if (S[I] != 'c') continue; for (int J = I + 1; J <= S.Length - 1; J++) { if (S[J] != 'w') continue; for (int K = J + 1; K <= S.Length - 1; K++) { if (S[K] != 'w') continue; FoundAnswer = true; if (K - I + 1 < MinLength) { MinLength = K - I + 1; break; } } } } Console.WriteLine(FoundAnswer ? MinLength : -1); } }