#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template <class T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
	for (const auto& e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T&& h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head&& h, Tail&&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	string s;
	cin >> s;

	Int len = s.size();
	reverse(s.begin(), s.end());

	//ABCの累積和
	vector<Int> sum(200001);
	for (Int i = 1; i <= 200000; i++) {
		sum[i] = sum[i-1] + i;
	}


	vector<vector<Int>> cnt;
	Int temp;
	vector<Int> temp1;
	Int ans = 0;
	for (Int i = 0; i < len; i++) {
		//ABCABC....ABCのセット数 ABCがややこしいので一番最初に片づけたい
		if (i+2<len && s[i] == 'C' && s[i + 1] == 'B' && s[i + 2] == 'A') {
			temp = 1;

			i += 3;
			while (i + 2 < len) {
				if (s[i] == 'C' && s[i + 1] == 'B' && s[i + 2] == 'A') {
					temp++;
					i += 3;
				}
				else {
					i--;
					break;
				}
			}
			
			ans += sum[temp];

			temp1 = { temp,0 };
			cnt.push_back(temp1);//AAAA...AAAの数
			
			temp1 = { temp,1 };
			cnt.push_back(temp1);//BCBC....BCの数
						
		}
		
		//AAA...Aの数
		else if (s[i] == 'A') {
			temp = 1;

			i++;
			while (i < len) {
				if (s[i] == 'A') {
					temp++;
					i++;
				}
				else {
					i--;
					break;
				}
			}
			temp1 = { temp,0 };
			cnt.push_back(temp1);
		}

		//BCBCBC...BCの数
		else if (i+1<len && s[i] == 'C'&&s[i+1]=='B') {
			temp = 1;

			i+=2;
			while (i+1 < len) {
				if (i + 2 < len && s[i + 2] == 'A') {
					i--;
					break;
				}
				else if (s[i] == 'C'&&s[i+1]=='B') {
					temp++;
					i+=2;
				}
				else {
					i--;
					break;
				}
			}
			temp1 = { temp,1 };
			cnt.push_back(temp1);
		}

		else {
			temp1 = { 1,2 };
			cnt.push_back(temp1);
		}
	}

	reverse(cnt.begin(), cnt.end());
	DMP(cnt);

	Int len1 = cnt.size();
	vector<vector<Int>> cnt2;
	for (Int i = 0; i < len1; i++) {
		if (i+1<len1 && cnt[i][1] == 1 && cnt[i + 1][1] == 1) {
			temp1 = { cnt[i][0] + cnt[i + 1][0],1 };
			cnt2.push_back(temp1);
			i++;
		}
		else if (i+1<len1 && cnt[i][1] == 0 && cnt[i + 1][1] == 0) {
			temp1 = { cnt[i][0] + cnt[i + 1][0],0 };
			cnt2.push_back(temp1);
			i++;
		}
		else {
			temp1 = { cnt[i][0],cnt[i][1] };
			cnt2.push_back(temp1);
		}
	}

	DMP(cnt2);

	
	Int len2 = cnt2.size();
	Int tempA;
	Int temp3;
	for (Int i = 0; i < len2; i++) {
		if (cnt2[i][1] == 0) {
			tempA = cnt2[i][0];//累積A

			temp3 = 1;//Aが見つかってから何個目か
			while (i+temp3<len2 && cnt2[i + temp3][1] != 2) {
				if (temp3 % 2) {
					ans += tempA * cnt2[i + temp3][0];
					temp3++;
				}
				else {
					tempA += cnt2[i + temp3][0];
					temp3++;
				}
			}
			i += temp3-1;
		}
	}

	cout << ans << "\n";
}


Measured memory_bytes: 26944