unittest
{
	assert( [ "ABCABC" ].parse.expand.solve == 3 );
	assert( [ "C" ].parse.expand.solve == 0 );
	assert( [ "ABCACCBABCBCAABCB" ].parse.expand.solve == 6 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto s = input.front.to!( dchar[] );
	return tuple( s );
}

auto solve( dchar[] s )
{
	s = ' ' ~ s;
	
	auto ans = 0L;
	auto bc = 0L;
	for( auto i = s.length.signed - 1; 0 < i; i-- )
	{
		if( s[ i - 1 ] == 'B' && s[ i ] == 'C' )
		{
			bc++;
			i--;
		}
		else if( s[ i ] == 'A' )
		{
			ans += bc;
		}
		else
		{
			bc = 0;
		}
	}
	return ans;
}
