str = gets.chomp regex = /c.*w.*w/ cwws = str.scan(regex) puts(cwws.min { |a, b| a.size <=> b.size }.size)