s = gets.chomp q = [[s, 0]] while true t, c = q.shift unless t.include?('ccw') puts c exit end q.push([t[1..], c + 1]) q.push([t[..-2], c + 1]) end