package net.ipipip0129.yukicoder.no559; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String line = scan.nextLine(); scan.close(); int acnt = 0; int swapcnt = 0; for (int i = line.length() - 1; 0 <= i; i--) { switch (line.charAt(i)) { case 'A': acnt++; break; case 'B': swapcnt += acnt; break; } } System.out.println(swapcnt); } }