import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(string s) {
    auto a = s.map!(e => e - 'A').array;

    int ans = 0;
    int i = 0;
    while (i < a.length) {
        // writeln(ans, " | ", i, " : ", a.map!(text).join(" "));

        if (i + 2 >= a.length) break;

        if (a[i] == 1 || a[i] == 2) {
            i++;
            continue;
        }

        if (i + 3 < a.length) { // 0, 0, 1, 2
            if (a[i+1] == 0 && a[i+2] == 1 && a[i+3] == 2) {
                a[i+1] = 1;
                a[i+2] = 2;
                a[i+3] = 0;
                ans++;

                int j = i;
                while (j >= 0 && a[j] == 0) {
                    ans++;
                    j--;
                }
                i += 2;
                // if (i - 1 >= 0 && a[i - 1] == 0) i--;
                continue;
            }
        }

        if (a[i] == 0 && a[i+1] == 1 && a[i+2] == 2) {
            a[i] = 1;
            a[i+1] = 2;
            a[i+2] = 0;
            i++;
            ans++;
            continue;
        }

        i++;
    }

    return ans;
}

void main() {
    string s = read!string;
    writeln(calc(s));
}
