S = input()

rlt = 0
b = ''
tA = 0
A = 0
BC = 0
for s in S:
  if s == 'A':
    if b == 'A':
      tA += 1
    elif b == 'B':
      rlt += A*BC
      tA = 1
      A = 0
      BC = 0
    else:
      rlt += A*BC
      tA = A + 1
      A = 0
      BC = 0
  elif s == 'B':
    if b == 'B':
      rlt += A*BC
      tA = 0
      A = 0
      BC = 0
  elif s == 'C':
    if b == 'B':
      A += tA
      tA = 0
      BC += 1
    else:
      rlt += A*BC
      tA = 0
      A = 0
      BC = 0
  b = s

rlt += A*BC
  
print(rlt) S = input() S input() input rlt = 0 rlt 0 b = '' b '' tA = 0 tA 0 A = 0 A 0 BC = 0 BC 0 for s in S:
  if s == 'A':
    if b == 'A':
      tA += 1
    elif b == 'B':
      rlt += A*BC
      tA = 1
      A = 0
      BC = 0
    else:
      rlt += A*BC
      tA = A + 1
      A = 0
      BC = 0
  elif s == 'B':
    if b == 'B':
      rlt += A*BC
      tA = 0
      A = 0
      BC = 0
  elif s == 'C':
    if b == 'B':
      A += tA
      tA = 0
      BC += 1
    else:
      rlt += A*BC
      tA = 0
      A = 0
      BC = 0
  b = s s S if s == 'A':
    if b == 'A':
      tA += 1
    elif b == 'B':
      rlt += A*BC
      tA = 1
      A = 0
      BC = 0
    else:
      rlt += A*BC
      tA = A + 1
      A = 0
      BC = 0
  elif s == 'B':
    if b == 'B':
      rlt += A*BC
      tA = 0
      A = 0
      BC = 0
  elif s == 'C':
    if b == 'B':
      A += tA
      tA = 0
      BC += 1
    else:
      rlt += A*BC
      tA = 0
      A = 0
      BC = 0
   s == 'A' s 'A' if b == 'A':
      tA += 1
    elif b == 'B':
      rlt += A*BC
      tA = 1
      A = 0
      BC = 0
    else:
      rlt += A*BC
      tA = A + 1
      A = 0
      BC = 0
   b == 'A' b 'A' tA += 1 tA 1 elif b == 'B':
      rlt += A*BC
      tA = 1
      A = 0
      BC = 0
     b == 'B' b 'B' rlt += A*BC rlt A*BC A BC tA = 1 tA 1 A = 0 A 0 BC = 0 BC 0 rlt += A*BC rlt A*BC A BC tA = A + 1 tA A + 1 A 1 A = 0 A 0 BC = 0 BC 0 elif s == 'B':
    if b == 'B':
      rlt += A*BC
      tA = 0
      A = 0
      BC = 0
   s == 'B' s 'B' if b == 'B':
      rlt += A*BC
      tA = 0
      A = 0
      BC = 0
   b == 'B' b 'B' rlt += A*BC rlt A*BC A BC tA = 0 tA 0 A = 0 A 0 BC = 0 BC 0 elif s == 'C':
    if b == 'B':
      A += tA
      tA = 0
      BC += 1
    else:
      rlt += A*BC
      tA = 0
      A = 0
      BC = 0
   s == 'C' s 'C' if b == 'B':
      A += tA
      tA = 0
      BC += 1
    else:
      rlt += A*BC
      tA = 0
      A = 0
      BC = 0
   b == 'B' b 'B' A += tA A tA tA = 0 tA 0 BC += 1 BC 1 rlt += A*BC rlt A*BC A BC tA = 0 tA 0 A = 0 A 0 BC = 0 BC 0 b = s b s rlt += A*BC rlt A*BC A BC print(rlt) print rlt rlt = 0 0 rlt tA = 0 0 tA BC = 0 0 BC tA = 1 1 tA rlt += A*BC A*BC rlt A = 0 0 A A += tA tA A A = 0 0 A tA = 0 0 tA b = s s b BC = 0 0 BC S = input() input() S tA += 1 1 tA rlt += A*BC A*BC rlt BC = 0 0 BC tA = 0 0 tA rlt += A*BC A*BC rlt BC += 1 1 BC b = '' '' b A = 0 0 A A = 0 0 A tA = 0 0 tA rlt += A*BC A*BC rlt rlt += A*BC A*BC rlt tA = A + 1 A + 1 tA A = 0 0 A BC = 0 0 BC BC = 0 0 BC
S = input()

rlt = 0
b = ''
tA = 0
A = 0
BC = 0
for s in S:
  if s == 'A':
    if b == 'A':
      tA += 1
    elif b == 'B':
      rlt += A*BC
      tA = 1
      A = 0
      BC = 0
    else:
      rlt += A*BC
      tA = A + 1
      A = 0
      BC = 0
  elif s == 'B':
    if b == 'B':
      rlt += A*BC
      tA = 0
      A = 0
      BC = 0
  elif s == 'C':
    if b == 'B':
      A += tA
      tA = 0
      BC += 1
    else:
      rlt += A*BC
      tA = 0
      A = 0
      BC = 0
  b = s

rlt += A*BC
  
print(rlt)