S = gets.chomp ans = 0 a_cnt = 0 S.chars.each_with_index do |s, idx| next if s != 'A' ans += idx - a_cnt a_cnt += 1 end puts ans