import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.container; // SList, DList, BinaryHeap
import std.typecons;  // Tuple, Nullable, BigFlags
import std.math;      // math functions
import std.numeric;   // gcd, fft
import std.bigint;    // BigInt
import std.random;    // random
import std.bitmanip;  // BitArray
import core.bitop;    // bit operation
import std.regex;     // RegEx
import std.uni;       // unicode

void main()
{
  auto s = readln.chomp.dup;

  auto r = 0;
  while (s.canFind("BA")) {
    auto i = s.countUntil("BA");
    if (i == -1) break;
    swap(s[i], s[i+1]);
    ++r;
  }

  writeln(r);
}