var S = stdin.readLine i, cnt = 0 while i < S.len: let j = i + 1 if S[i .. j] == "BA": swap S[i], S[j] cnt += 1 i = 0 else: i += 1 echo cnt