/**
 *Code Author: codeknight13
 *Institution: IIT(ISM)
**/

#include <bits/stdc++.h>
using namespace std;

/*
use these format of input when number of inputs not provided
while(scanf("%lld",&n)!=EOF)
*/

#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long int
#define vi vector< ll >
#define vii vector< vi >
#define viii vector< vii >
#define pii pair< int , int >
#define vpii vector< pii >
#define mii unordered_map< int , int >
#define mci map< char , int >
#define pq priority_queue
#define str string
#define len length()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define nl cout <<  endl
#define sp " "
#define all(ar) ar.begin(), ar.end()
#define rall(ar) ar.rbegin(), ar.rend()
#define itern(n) for (int i=0; i<n; i++)
#define iterni(n) for (int i=0; i<n; i++)
#define iternj(n) for (int j=0; j<n; j++)
#define iternk(n) for (int k=0; k<n; k++)
#define iterng(n) for (int g=0; g<n; g++)
#define riterni(n) for (int i=n-1; i>=0; i--)
#define riternj(n) for (int j=n-1; j>=0; j--)
#define riternk(n) for (int k=n-1; k>=0; k--)
#define riterng(n) for (int g=n-1; g>=0; g--)
#define sz(x) ((int)(x).size())
#define pi acos(1);                   /* pi */
#define inf (int)(1e9+7)
#define fl(x) int(x)
#define mod %(inf)
#define yes "YES"
#define no "NO"
#define null NULL
#define mac (int)(1e7)
//debugger
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
/*-----functions-----*/
//gcd
/*int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}

//disjoint set union functions
int volume[mac];
int parent[mac];

void initialise_dsu() {
	for (int i=0; i<mac; i++)volume[i]=1;
	for (int i=0; i<mac; i++)parent[i]=i;
}

int find_set(int v) {
    return (v==parent[v]?v:parent[v]=find_set(parent[v]));
}

void union_sets(int a,int b) {
	a=find_set(a);
	b=find_set(b);
	if (a!=b) {
		if (volume[a]<volume[b])swap(a,b);
		parent[b]=a;
		volume[a]+=volume[b];
	}
}
*/
//#------------------------------complete template------------------------------#//
/*int main () {
	int n,a,b,c,d;
	cin >> n >> a >> b >> c >> d;
	string s;
	cin >> s;
	for (int i=min(a,c); i<max(a,c); i++) {
		if (s[i]=='#' and s[i+1]=='#') {
			cout << no;
			return 0;
		}
	}
	for (int i=min(b,d); i<max(b,d); i++) {
		if (s[i]=='#' and s[i+1]=='#') {
			cout << no;
			return 0;
		}
	}
	if (c>a and c>b and b>a and d>c) {
		int flag=1;
		for (int i=a; i<d; i++) {
			if (s[i]=='.' and s[i+1]=='.') {
				flag=0;
			}
		}
		if (flag) {
			cout << no;
			return 0;
		}
	}
	if ()
	cout << yes;
	return 0;
}*/

int main() {
	string s;
	cin >> s;
	int n=s.length();
	vi b(n,0);
	int cnt=0,con_k=0;
	for (int i=n-1; i>=0; i--) {
		if (s[i]=='A') {
			int cnt_k=0;
			for (int j=i+1; j<n; j+=2){
				if (j+1<n and s[j]=='B' and s[j+1]=='C') {
					cnt_k++;
				} else {
					cnt_k+=b[j];
					break;
				}
			}
			cnt+=cnt_k+(i+1<n?b[i+1]:0);
			b[i]=cnt_k;
		}
	}
	ll sum=0;
	for (int i=0; i<n; i++) {
		sum+= b[i];
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 2180