S = gets.chomp N = S.size dp = Array.new(N + 1, 0) (N - 1).downto(0) do |i| dp[i] = if S[i] == 'w' dp[i + 1] + 1 else dp[i + 1] end end ans = (0...N).map {|i| if S[i] == 'c' m = dp[i] m * (m - 1) / 2 else 0 end }.inject(:+) puts ans