// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int N;
set<int> S[30];

inline int ord(char c) {
    if(c == 'A') return 0;
    if(c == 'B') return 1;
    if(c == 'C') return 2;
    return -1;
}

void swp(string &s, int idx) {
    // delete
    for(int i = idx - 2; i <= idx + 2; i++) {
        if(i < 0 or i + 2 >= N) continue;
        int num = 0;
        for(int k=0; k<3; k++) {
            num = num * 3 + ord(s[i + k]);
        }
        S[num].erase(i);
    }
    
    s[idx    ] = 'B';
    s[idx + 1] = 'C';
    s[idx + 2] = 'A';

    for(int i = idx - 2; i <= idx + 2; i++) {
        if(i < 0 or i + 2 >= N) continue;
        int num = 0;
        for(int k=0; k<3; k++) {
            num = num * 3 + ord(s[i + k]);
        }
        S[num].insert(i);
    }
}

void build(string &s) {
    for(int i=0; i<N-2; i++) {
        int num = 0;
        for(int k=0; k<3; k++) {
            num = num * 3 + ord(s[i + k]);
        }
        S[num].insert(i);
    }
}

string pat = "BC";
int solve(string s) {
    int i = 0, ans = 0;
    for(; i<N; ) {
        if(s[i] == 'A') {
            vector<int> idxes;
            
            int trig = 0, r = -1;
            while(i < N) {
                // fprintf(stderr, "i = %lld, pat = %c\n", i, pat[trig]);
                // A*BC...
                if(s[i] == 'A') {
                    if(trig == 0) {
                        idxes.push_back(i);
                        i++;
                    }
                    else {
                        break;
                    }
                }
                else if(pat[trig] == s[i]) {
                    if(trig == 1) r = i;
                    trig = 1 - trig;
                    i++;
                }
                else {
                    // A でもなくてパターンに一致しない
                    break;
                }
            }
            reverse(idxes.begin(), idxes.end());
            for(auto e : idxes) {
                if(r < e) continue;
                // fprintf(stderr, "i = %lld, r = %lld, e = %lld\n", i, r, e);
                ans += (r--) - e;
            }
        }
        else {
            i++;
        }
    }
    // cout << ans / 2 << endl;
    return ans / 2;
}
 
signed main() {
    string s; cin >> s;
    N = s.size();

    /*
    build(s);

    int target = ord('A') * 9 + ord('B') * 3 + ord('C') * 1;
    int ans = 0;
    while(S[target].size()) {
        ans++;
        swp(s, *S[target].begin());
    }
    cout << ans << endl;
    */
    cout << solve(s) << endl;
    return 0;
}


Measured memory_bytes: 2808