import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); char[] arr = sc.next().toCharArray(); long total = 0; int bCount = 0; for (char c : arr) { if (c == 'A') { total += bCount; } else { bCount++; } } System.out.println(total); } }