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