a = gets.chomp.split(//) b = [] a.each_with_index do |c, i| b << i if c == 'B' end n = a.size - 1 b = b.map{|i| n - i} m = b.size p b.sum - (m-1)*m/2