strs = gets.chomp.scan(/c.*w.*w/) if strs.length == 0 puts "-1" else c,w1,w2 = false, false, false count = 0 strs[0].chars do |s| count += 1 if s == "c" c = true elsif s == "w" and not w1 w1 = true elsif s == "w" and w1 w2 = true end if c and w1 and w2 puts count break end end end