local b = string.byte("B")

local s = io.read()
local s_len = s:len()
local count = 0
local last_b_pos = 0
for i = 1, s_len do
	if s:byte(i) == b then
		count = count + i - last_b_pos
		last_b_pos = last_b_pos + 1
	end
end

print(count)
