package yukicoder; import java.util.Arrays; import java.util.Scanner; public class No559 { public static void main(String[] args) { String str = new Scanner(System.in).next(); String[] splited = str.split(""); String tmp; int cnt = 0, eachCnt = 0; do { eachCnt = 0; for(int i = 0; i < splited.length - 1; i++) { if(splited[i].equals("B") && splited[i + 1].equals("A")) { tmp = splited[i + 1]; splited[i + 1] = splited[i]; splited[i] = tmp; eachCnt++; cnt++; } } } while(eachCnt != 0); System.out.println(cnt); } }