using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApplication6 { class Program { static void Main(string[] args) { var s = Console.ReadLine(); var cww = s.Aggregate(new { Cwws = new List(), Index = 0 }, (l, x) => { foreach (var item in l.Cwws) { item.Push(l.Index, x); } if (x == 'c') { l.Cwws.Add(new Cww(l.Index)); } return new { Cwws = l.Cwws, Index = l.Index + 1 }; }) .Cwws .Where(x => x.IsFinish) .OrderBy(x => x.Length) .FirstOrDefault(); Console.WriteLine(cww?.Length ?? -1); } } class Cww { private bool FindFirstW { get; set; } public int StartIndex { get; } public int? Length { get; private set; } public bool IsFinish => this.Length != null; public Cww(int startIndex) { this.StartIndex = startIndex; } public void Push(int index, char w) { if (this.IsFinish) { return; } if (w != 'w') { return; } if (this.FindFirstW) { this.Length = index - this.StartIndex + 1; } else { this.FindFirstW = true; } } } }