s=input()
t=''
i=0
while i<len(s):
  if s[i]=='A':
    t+='A'
    i+=1
  elif s[i]=='B':
    if i!=len(s)-1:
      if s[i+1]=='C':
        t+='B'
        i+=2
      else:
        t+='X'
        i+=1
    else:
      i+=1
  else:
    t+='X'
    i+=1
b=0
x=0
for i in range(len(t))[::-1]:
  if t[i]=='B':
    b+=1
  elif t[i]=='A':
    x+=b
  else:
    b=0
print(x) s=input() s input() input t='' t '' i=0 i 0 while i<len(s):
  if s[i]=='A':
    t+='A'
    i+=1
  elif s[i]=='B':
    if i!=len(s)-1:
      if s[i+1]=='C':
        t+='B'
        i+=2
      else:
        t+='X'
        i+=1
    else:
      i+=1
  else:
    t+='X'
    i+=1 i<len(s) i len(s) len s if s[i]=='A':
    t+='A'
    i+=1
  elif s[i]=='B':
    if i!=len(s)-1:
      if s[i+1]=='C':
        t+='B'
        i+=2
      else:
        t+='X'
        i+=1
    else:
      i+=1
  else:
    t+='X'
    i+=1 s[i]=='A' s[i] s i 'A' t+='A' t 'A' i+=1 i 1 elif s[i]=='B':
    if i!=len(s)-1:
      if s[i+1]=='C':
        t+='B'
        i+=2
      else:
        t+='X'
        i+=1
    else:
      i+=1
   s[i]=='B' s[i] s i 'B' if i!=len(s)-1:
      if s[i+1]=='C':
        t+='B'
        i+=2
      else:
        t+='X'
        i+=1
    else:
      i+=1
   i!=len(s)-1 i len(s)-1 len(s) len s 1 if s[i+1]=='C':
        t+='B'
        i+=2
      else:
        t+='X'
        i+=1
     s[i+1]=='C' s[i+1] s i+1 i 1 'C' t+='B' t 'B' i+=2 i 2 t+='X' t 'X' i+=1 i 1 i+=1 i 1 t+='X' t 'X' i+=1 i 1 b=0 b 0 x=0 x 0 for i in range(len(t))[::-1]:
  if t[i]=='B':
    b+=1
  elif t[i]=='A':
    x+=b
  else:
    b=0 i range(len(t))[::-1] (len(t)) range len(t) len t ::-1 -1 if t[i]=='B':
    b+=1
  elif t[i]=='A':
    x+=b
  else:
    b=0 t[i]=='B' t[i] t i 'B' b+=1 b 1 elif t[i]=='A':
    x+=b
   t[i]=='A' t[i] t i 'A' x+=b x b b=0 b 0 print(x) print x x+=b b x t+='B' 'B' t i+=1 1 i s=input() input() s t+='A' 'A' t i+=1 1 i b=0 0 b i+=2 2 i x=0 0 x t='' '' t t+='X' 'X' t b=0 0 b i+=1 1 i t+='X' 'X' t i=0 0 i i+=1 1 i b+=1 1 b
s=input()
t=''
i=0
while i<len(s):
  if s[i]=='A':
    t+='A'
    i+=1
  elif s[i]=='B':
    if i!=len(s)-1:
      if s[i+1]=='C':
        t+='B'
        i+=2
      else:
        t+='X'
        i+=1
    else:
      i+=1
  else:
    t+='X'
    i+=1
b=0
x=0
for i in range(len(t))[::-1]:
  if t[i]=='B':
    b+=1
  elif t[i]=='A':
    x+=b
  else:
    b=0
print(x)