readlines.each { |s| ans, cnt = 0,0 s.chomp.reverse.each_char { |c| cnt += 1 if c == 'w' ans += cnt*(cnt-1)/2 if c == 'c' } p ans }