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

#define NDEBUG
#include <cassert>


typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

#define PQ(T) priority_queue<T>
#define RPQ(T) priority_queue<T,vector<T>,greater<T>>

template<class T> inline void amin(T & a, T const & b) { a = min(a, b); }
template<class T> inline void amax(T & a, T const & b) { a = max(a, b); }

inline ll square(ll x) { return x * x; }
inline ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }
template <typename T>
inline T mod(T a, T b) { return ((a % b) + b) % b; }



template <typename T, int base=0>
class fenwick_tree_0 {
 public:
    vector<T> x;
 public:
    fenwick_tree_0(int n) : x(n+base,0) { }
    void add(int k, T a=1) { for (; k<x.size(); k|=k+1) x[k] += a; }
    T sum(int i, int j) {
        if (i == base) {
            T S = 0; for (; j>=0; j=(j&(j+1))-1) S += x[j]; return S;
        } else {
            return sum(base, j) - sum(base, i-1);
        }
    }
};

int zaatsu(int N, vi& src, vi &dest, int offset=0) {
    set<int> uniq(ALL(src));
    map<int,int> mp;
    int ix = 0;
    for (int x : uniq) mp[x] = ix++;

    dest.resize(N);
    for (int i=0; i<N; ++i) {
        dest[i] = offset + mp[src[i]];
    }
    return ix;
}

ll count_inversion(vector<int>& a) {
    int N=a.size();
    vi b(N);
    int num_indices = zaatsu(N, a, b, 1);

    int _N = 1; while (_N < N+1) _N *= 2;
    fenwick_tree_0<int> ft(_N);

    ll cnt = 0;
    for (int i=N-1; i>=0; --i) {
        cnt += ft.sum(1, b[i]-1);
        ft.add(b[i]);
    }
    return cnt;
}

ll f(vi& w){
    return count_inversion(w);
}

ll solve(string& s){
    int L = s.size();

    ll ans = 0;
    vi w;
    for (int i=0; i<L; ++i){
        if (s[i] == 'A') {
            w.pb(1);
            continue;
        }
        else if (s[i] == 'B') {
            if (i+1 < L && s[i+1] == 'C') {
                w.pb(0);
                ++i;
                continue;
            } else {
                if (!w.empty()) ans += f(w);
                w.clear();
            }
        }
        else {
            if (!w.empty()) ans += f(w);
            w.clear();
        }
    }
    if (!w.empty()) ans += f(w);

    return ans;
}

int main() {
    string s; cin >> s;
    cout << solve(s) << endl;
    return 0;
}


Measured memory_bytes: 3192