cww = Hash.new(0) cww[[-1, ""]] = 1 s = gets.strip s.length.times do |i| cww[[i, ""]] = cww[[i - 1, ""]] cww[[i, "c"]] = cww[[i - 1, "c"]] cww[[i, "cw"]] = cww[[i - 1, "cw"]] cww[[i, "cww"]] = cww[[i - 1, "cww"]] if s[i] == "w" cww[[i, "cww"]] += cww[[i, "cw"]] cww[[i, "cw"]] += cww[[i, "c"]] elsif s[i] == "c" cww[[i, "c"]] += cww[[i, ""]] end end p cww[[s.length - 1, "cww"]]