s = input() s_list = list(s) insert_index = 0 res = 0 for i in range(len(s)): if s[i] == 'A': res += (i - insert_index) insert_index += 1 print(res)