s = input() s_list = list(s) num_a = s_list.count('A') border = num_a count = 0 while 'B' in s_list[ : border] and 'A' in s_list[border : ]: index_b = s_list[ : border].index('B') s_list[index_b] = 'X' count += (border - 1 - index_b + 1) s_list[border - 1] = s_list[border] s_list[border] = 'B' if s_list[border - 1] == s_list[border]: count -= 1 if 'B' not in s_list[ : border] or 'A' not in s_list[border : ]: break index_a = s_list[border : ].index('A') s_list[border + index_a] = 'X' count += (index_a + 1) s_list[border] = s_list[border - 1] s_list[border - 1] = 'A' if s_list[border - 1] == s_list[border]: count -= 1 print(count)