#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repb(i, n) for (int i = (n-1); i >= 0; i--)
#define rea(i, a, b) for (int i = (a); i < (b); i++)
#define reab(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
const ll MOD = 1000000007;
const ll INF = 100000000000000000;
/* END OF TEMPLATE */

ll ans = 0;
vp abc;

void score(){
    ll sza = SZ(abc);
    rep(i, sza){
        rea(j, i, sza){
            ans += abc[i].first * abc[j].second;
            // dump2(abc[i].first, abc[j].second);
        }
    }
    abc.clear();
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int szs = SZ(s);
    
    ll cnta = 0;
    ll cntb = 0;
    bool aflag = 0;
    bool bflag = 0;
    rep(i, szs){
        switch(s[i]){
        case 'A':
            if(aflag && bflag){
                abc.emplace_back(cnta, cntb);
                cnta = 0;
                cntb = 0;
            }
            cnta++;
            aflag = 1;
            break;
        case 'B':
            if(aflag && s[i+1] == 'C'){
                bflag = 1;
                cntb++;
                i++;
                if(i == szs-1){
                    abc.emplace_back(cnta, cntb);
                    cnta = 0;
                    cntb = 0;
                    score();
                }
            }else{
                if(aflag && bflag){
                    abc.emplace_back(cnta, cntb);
                    cnta = 0;
                    cntb = 0;
                    score();
                }
                aflag = 0;
                bflag = 0;
            }
            break;
        case 'C':
            if(aflag && bflag){
                abc.emplace_back(cnta, cntb);
                score();
            }
            aflag = 0;
            bflag = 0;
            break;
        }
        if(!aflag) cnta = 0;
        if(!bflag) cntb = 0;
        /*
        switch(s[i]){
        case 'A':
            cnta++;
            switch(s[i]+1){
            case 'A':
                break;
            case 'B':
                break;
            case 'C':
                cnta = 0;
                break;
            }
            break;
        case 'B':
            switch(s[i]+1){
            case 'A':
                break;
            case 'B':
                break;
            case 'C':
                cntb++;
                i++;
                break;
            }
            break;
        case 'C':
            switch(s[i]+1){
            case 'A':
                break;
            case 'B':
                break;
            case 'C':
                break;
            }
            break;
        }
        */
        // dump2(i, ans);
    }
    score();
    cout << ans << endl;
}

Measured memory_bytes: 788