s = gets.chomp ans = 0 f = 0 s.reverse.each_char.with_index do |c,i| if(c == "A") f += 1 else ans += f end end p ans