# frozen_string_literal: true S = gets.chomp result = S.size exist = false S.scan(/(c[^cw]*?w[^w]*?w)/).each do |m| result = [result, m[0].to_s.size].min exist = true end RESULT = exist ? result : -1 puts RESULT