Problem:
 Score : 600 points    Problem Statement You are given a string s consisting of A , B and C .  Snuke wants to perform the following operation on s as many times as possible:   Choose a contiguous substring of s that reads ABC and replace it with BCA .   Find the maximum possible number of operations.      Constraints  1 \leq |s| \leq 200000  Each character of s is A , B and C .         Input Input is given from Standard Input in the following format:  s       Output Find the maximum possible number of operations.        Sample Input 1 ABCABC      Sample Output 1 3  You can perform the operations three times as follows: ABCABC → BCAABC → BCABCA → BCBCAA . This is the maximum result.       Sample Input 2 C      Sample Output 2 0       Sample Input 3 ABCACCBABCBCAABCB      Sample Output 3 6

Solution (Python):
s =input()
n = len(s)
ans  = 0
cnt = 0
pre = s[0]
for i in range(n):
    if s[i] == "A":
        if pre =="B":cnt =1
        else:cnt+=1
    elif s[i] =="C":
        if pre == "B":
            ans += cnt
        else:cnt = 0
    elif s[i] == "B":
        if pre == "B":cnt = 0
    pre = s[i]
print(ans)

Solution (Python):
s = input()
s = s.replace('BC', 'D')

ans = a = 0
for i in s:
    if i == "A":
        a += 1
    elif i == "D":
        ans += a
    else:
        a = 0
print(ans)

Solution (Python):
s = str(input())
s = s.replace('BC', 'D')
n = len(s)

ans = 0
cnt = 0
for i in range(n):
    if s[i] == 'A':
        cnt += 1
    if s[i] == 'D':
        ans += cnt
    if s[i] == 'B' or s[i] == 'C':
        cnt = 0
print(ans)

Solution (Python):
s = str(input())
s = s.replace('BC', 'D')
n = len(s)

ans = 0
cnt = 0
for i in range(n):
    if s[i] == 'A':
        cnt += 1
    if s[i] == 'D':
        ans += cnt
    if s[i] == 'B' or s[i] == 'C':
        cnt = 0
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()


def resolve():
    s = str(input())
    s = s.replace('BC', 'D')
    ans = a = 0
    for i in s:
        if i == 'A':
            a += 1
        elif i == 'D':
            ans += a
        else:
            a = 0
    print(ans)


resolve()

Solution (Python):
import re
s = input()
sub = re.sub('BC', 'X', s)

ans = 0
a = 0
for i in range(len(sub)):
    if sub[i] == 'A':
        a += 1
    elif sub[i] == 'X':
        ans += a
    else:
        a = 0

print(ans)

Solution (Python):
S = input()
S = S.replace('BC', 'D')

cnt_a = 0
ans = 0
for i in range(len(S)):
    if S[i] == 'A':
        cnt_a += 1
    elif S[i] == 'D':
        ans += cnt_a
    else:
        cnt_a = 0

print(ans)

Solution (Python):
s = input()

t = s.replace('BC', 'X')











parts = t.replace('B', 'C').split('C')

ans = 0
for part in parts:
    cnt_A = 0
    for i in range(len(part)):
        if part[i] == 'A':
            cnt_A += 1
        else:
            ans += cnt_A

print(ans)

Solution (Python):


s = input()
s = s.replace("BC", "D")

c_A = 0
ans = 0
for v in s:
  if v == "A":
    c_A += 1
  elif v == "D":
    ans += c_A
  else:
    c_A = 0
print(ans)

Solution (Python):
S = input()
S = S.replace('BC', 'D')

cnt = 0
ans = 0
for i, s in enumerate(S):
    if s == 'D':
        ans += cnt
    elif s == 'A':
        cnt += 1
    else:
        cnt = 0
print(ans)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

s = STR()
a = []
i = 0
while i < len(s):
    if s[i] == 'A':
        a.append(0)
        i += 1
    elif i < len(s) - 1 and s[i:i + 2] == 'BC':
        a.append(1)
        i += 2
    else:
        a.append(2)
        i += 1
debug(a)
arr = []
bgn = -1
end = -1
for i in range(len(a)):
    if bgn == -1 and a[i] != 2:
        bgn = i
    if a[i] == 2 and end == -1:
        end = i
        arr.append(a[bgn:end])
        bgn = -1
        end = -1
arr.append(a[bgn:len(a) + 1])
debug(arr)
ans = 0
for b in arr:
    num0 = 0
    for i in b:
        if i == 0:
            num0 += 1
        if i == 1:
            ans += num0
print(ans)

Solution (Python):
def main():
    ans = 0
    S = input()
    N = len(S)
    ans = 0
    now = 0
    skip = -1
    for i, s in enumerate(S):
        if i <= skip:
            continue
        if s == "A" and S[i+1:i+3] == "BC":
            now += 1
            ans += now
            skip = i+2
        elif s == "A":
            now += 1
        elif s == "B" and i < N-1 and S[i+1] == "C":
            ans += now
            skip = i+1
        else:
            now = 0
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
s=input()
s=s.replace("BC", "D")
ans=0
a=0
for c in s:
    if c=='A': a+=1
    elif c=='D': ans+=a
    else: a=0
print(ans)

Solution (Python):
S = input()
S = S.replace("BC", "X")

a = 0
ans = 0
for s in S:
    if s == "A":
        a += 1
    elif s == "X":
        ans += a
    else:
        a = 0
print(ans)

Solution (Python):
S = input()
S = S.replace('BC','D')
ans = a = 0
for c in S:
    if c=='A':
        a += 1
    elif c=='D':
        ans += a
    else:
        a = 0
print(ans)

Solution (Python):
s=input().replace("BC","X").replace("B","Y").replace("C","Y")
a=False
ans=0
c=0
for i in "Y"+s+"Y":
	if i=="A":
		a=True
		c+=1
	if i=="X":
		if a:
			ans+=c
	if i=="Y":
		a=False
		c=0
print(ans)

Solution (Python):




s = input()
s = s.replace('BC', 'D')


nA = 0
ans = 0

for ss in s:
    if ss == 'A':
        nA += 1
    elif ss == 'D':
        ans += nA
    else:
        nA = 0
print(ans)

Solution (Python):
S = str(input())
S = S.replace("BC","D")
A_count = 0
ans = 0

for i in range(len(S)):
  if S[i] == 'A':
    A_count += 1
  elif S[i] == 'D':
    ans += A_count
  else:
    A_count = 0
print(ans)

Solution (Python):
s=input()

s2list=list(s.replace("BC","D"))


block_list=[]
bl=[]
for s2 in s2list:
  if s2=="A" or s2=="D":
    bl.append(s2)
  else:
    if len(bl)>0:
      block_list.append("".join(bl))
      bl=[]
else:
  if len(bl)>0:
    block_list.append("".join(bl))


answer=0
for bl in block_list:
  
  cnt_a=0
  for c in bl:
    if c=="A":
      cnt_a+=1
    else:
      answer+=cnt_a
    
print(answer)

Solution (Python):
S = list(input().replace("BC", "X"))
N = len(S)
pos, ans = 0, 0
ca = 0

while pos<N:
    ca = 0
    if S[pos]=="A" or S[pos]=="X":
        while pos<N and (S[pos]=="A" or S[pos]=="X"):
            if S[pos]=="A":
                ca += 1
            else:
                ans += ca
            pos += 1
    else:
        pos += 1

print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

s = input()
s = s.replace("BC", ".")
cnt = 0
ans = 0
for x in s:
	if x == "B" or x =="C":
		cnt = 0
		continue
	if x == ".":
		ans += cnt
	if x == "A":
		cnt += 1
print(ans)

Solution (Python):
s = input()
s = s.replace("BC", "D")
result = 0
i = 0
while i < len(s)-1:
    if s[i]=="A":
        y = 1
        for j in range(i+1, len(s)):
            i += 1
            if s[j]=="A":
                y += 1
            elif s[j]=="D":
                result += y
            else:
                break
    else:
        i += 1
print(result)

Solution (Python):
def main():
    S = [s for s in input()]
    As = 0
    BCs = 0
    N = len(S)
    i = 0
    ans = 0
    while i < N - 1:
        s0, s1 = S[i], S[i + 1]
        if s0 == 'A':
            As += 1
            i += 1
            continue
        if s0 != 'B' or s1 != 'C':
            As = 0
            i += 1
            continue
        BCs = 1
        i += 2
        while i < N - 1:
            s0, s1 = S[i], S[i + 1]
            if s0 != 'B' or s1 != 'C':
                break
            BCs += 1
            i += 2
        ans += As * BCs
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10


def solve():
    s = S()
    a = 0
    ans = 0
    f = 0
    i = 0
    while i < len(s) - 1:
        if s[i] == "A":
            a += 1
            i += 1
        elif s[i: i + 2] == "BC":
            ans += a
            i += 2
        else:
            a = 0
            i += 1

    print(ans)

    return



if __name__ == '__main__':
    solve()

Solution (Python):
S = list(input())
N = len(S)
lst = []
l = []
i = 0
while i < N:
    if S[i] == 'A':
        l.append(0)
        i += 1
    elif S[i] == 'B' and i+1 < N and S[i+1] == 'C':
        l.append(1)
        i += 2
    else:
        lst.append(l)
        l = []
        i += 1
if len(l):
    lst.append(l)
ans = 0
for l in lst:
    cnt = 0
    for x in l:
        if x == 0:
            cnt += 1
        else:
            ans += cnt
print(ans)

Solution (Python):
import sys


def main():
    s = list(input().replace("BC", "D"))
    a = 1
    for i in range(len(s)-1):
        w = "".join(s[i:i+2])
        if w == "AD":
            s[i], s[i+1] = "D", "A"
            yield a
        elif w == "AA":
            a += 1
        else:
            a = 1


print(sum(main()))

Solution (Python):
def main():
    word = input().replace("BC", "X") + " "
    answer = 0
    count_a = 0
    for i in range(len(word)):
        if word[i] == "A":
            count_a += 1
        elif word[i] == "X":
            answer += count_a
        else:
            count_a = 0
    print(answer)


if __name__ == '__main__':
    main()

Solution (Python):
s = str(input())

s = s.replace('BC', 'D')

ans = 0
cnt = 0

for i in s:
	if i == 'A':
		cnt += 1
	elif i == 'D':
		ans += cnt
	else:
		cnt = 0
print(ans)

Solution (Python):
s = input()

s = s.replace('BC', 'V')

ans = 0
cnt = 0
flag = False

for i in range(len(s)):
    if s[i] == 'A':
        flag = True
        cnt += 1
    elif flag and s[i] == 'V':
        ans += cnt
    else:
        flag = False
        cnt = 0

print(ans)

Solution (Python):
S = input()
N = len(S)
X = []
x = 0
while x<N-1:
    if S[x]=="B" and S[x+1]=="C":
        X.append("D")
        x+=1
    else:
        X.append(S[x])
    x+=1
ans = 0
N = len(X)
a = 0
for i in range(N):
    if X[i]=="A":
        a+=1
    elif X[i]=="D":
        ans+=a
    else:
        a=0
print(ans)

Solution (Python):



import re

def main():
  s = input().strip()
  s = s.replace('BC', 'X')
  ans = 0
  for ax in re.split(r'[BC]+', s):
    inds = []
    for i in range(len(ax)):
      if ax[i] == 'A':
        inds.append(i)
    ans += sum([len(ax) - 1 - ind for ind in inds]) - sum(range(len(inds)))
  print(ans)

if __name__=='__main__':
  main()

Solution (Python):
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)

Solution (Python):
s = list(input())
ans = 0
cnta = 0
flagb = 0
flabc= 0
for i in range(len(s)):
  if s[i]=="A":
    if flagb==0:
      cnta+=1
    else:
      cnta=1
      flagb=0
  if s[i]=="B":
    if flagb==0 and cnta:
      flagb=1
    else:
      flagb=0
      cnta=0
  if s[i]=="C":
    if flagb and cnta:
      ans+= cnta
      flagb=0
    else:
      cnta=0
      flagb=0
print(ans)

Solution (Python):
S = input()
N = len(S)
S = S[:] + "X"
T = ""
i, j = 0, 0
X = 0
def excAB(n, lis):
  y = 0
  m = len(lis)
  for i in range(m):
    y += n - 1 - i - lis[m-1-i]
  return y

M = []
while i < N:
  if S[i] == 'A':
    T = T[:] + "A"
    i += 1
    M.append(j)
    j += 1
  elif S[i:i+2] == "BC":
    T = T[:] + "B"
    i += 2
    j += 1
  else:
    X += excAB(j, M)
    T = T[:] + "C"
    M = []
    i += 1
    j = 0
X += excAB(j, M)
print(X)

Solution (Python):
S = input()
S = S.replace('BC', 'X')

ret = 0
a_frq = 0
for s in S:
    if s == 'A':
        a_frq += 1

    elif s == 'X':
        ret += a_frq

    else:
        a_frq = 0

print(ret)

Solution (Python):
import sys
INF = 10 ** 9
MOD = 10 ** 9 + 7
from collections import deque
sys.setrecursionlimit(100000000)

def main():
    s = list(input())
    
    cnt = 0
    ans = 0
    if len(s) < 3:
        print(0)
        exit()

    i = len(s) - 1
    while i > 0:
        while i > 0 and s[i-1] == 'B' and s[i] == 'C':
            cnt += 1
            i -= 2  
            while i >= 0 and s[i] == 'A':
                ans += cnt
                i -= 1
        else:
            cnt = 0
            i -= 1

    print(ans)
if __name__=='__main__':
    main()

Solution (Python):
s = input()
ans = 0
L = []
flag = False
for i in range(len(s)):
    if not flag:
        if i != len(s)-1 and s[i] == 'B':
            flag = True
        else:
            L.append(s[i])
    else:
        if s[i] == 'C':
            L.append('D')
        else:
            L.append('B')
            L.append(s[i])
        flag = False
new = []
num = []
flag = False
L.append('B')
for i in range(len(L)):
    if L[i] == 'A' and flag == False:
        setnum = 1
        flag = True
        cur = ['A']
    else:
        if flag == False:
            None
        else:
            if L[i] == 'B' or L[i] == 'C':
                flag = False
                new.append(cur)
                num.append(setnum)
            else:
                if L[i] == 'A':
                    cur.append('A')
                    setnum += 1
                else:
                    cur.append('D')
for i in range(len(new)):
    T = new[i]
    add = num[i]
    cur = 0
    for j in range(len(T)):
        if T[len(T)-j-1] == 'D':
            cur += add
        else:
            add -= 1
    ans += cur
print(ans)

Solution (Python):
s = input()
l = len(s)
s += "0"
ans = 0
a_cnt = 0
skip = False
for i in range(l):
    if skip:
        skip = False
        continue
    if s[i] == "A":
        a_cnt += 1
    elif s[i] == "B" and s[i+1] == "C":
        ans += a_cnt
        skip = True
    else:
        a_cnt = 0

print(ans)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

s = input()
n = len(s)
res = 0
bc = 0
i = n-1
while i >= 0:
    if s[i] == 'A':
        res += bc
        i -= 1
    elif i != 0 and s[i-1] == 'B' and s[i] == 'C':
        bc += 1
        i -= 2
    else:
        bc = 0
        i -= 1
print(res)

Solution (Python):
S = input()
T = S.replace('BC', 'X')

ans = 0
cnta = 0
for ch in T:
  if ch == 'B' or ch == 'C':
    cnta = 0
  elif ch == 'A':
    cnta += 1
  else:
    ans += cnta
    
print(ans)

Solution (Python):
s=input()
A=s.replace('BC','D')
cnt=0
ans=0
for i in A:
  if i=='A':
    cnt+=1
  elif i=='D':
    ans+=cnt
  else:
    cnt=0
print(ans)

Solution (Python):
def main():
    s = list(input().rstrip())
    ans = 0
    cnt = 0
    for i in range(len(s)-2):
        if s[i] == "A":
            cnt += 1
        else:
            cnt = 0
        if s[i] == "A" and s[i+1] == "B" and s[i+2] == "C":
            ans += cnt
            if cnt == 1:
                s[i+2] = "A"
                cnt = 0
            else:
                s[i+1] = "A"
                s[i+2] = "A"
                cnt -= 2
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
s=input()
s=s.replace("BC","Z")


a=0
b=0
for i in s:
    if i=="A":a+=1
    elif i=="Z":b+=a
    else:a=0
print(b)

Solution (Python):
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7

s=input()
n=len(s)
lst=[0]*n
for i in range(n):
    lst[i]=s[i]


ans=0
cnt=0
i=0
while i<n-2:
    if lst[i]=="A":
        cnt+=1
    else:
        cnt=0
    if lst[i]=="A" and lst[i+1]=="B" and lst[i+2]=="C":
        ans+=cnt
        cnt-=1
        lst[i+2]="A"
        i+=1
    
    
    i+=1
print(ans)

Solution (Python):
s = input()
n = len(s)
s = list(s.replace('BC','D'))
a_count = 0
ans = 0
i = 0
while i < len(s) - 1 :
    if s[i:i+2] == ['A','D']:
        ans += a_count + 1
        s[i+1] = 'A'
        s[i] = 'D'
    else:
        if s[i] == 'A':
            a_count += 1
        else:
            a_count = 0
    i += 1
print(ans)

Solution (Python):
S = input()
S = S.replace("BC", "D")

S = list(S)

cnt1 = 0
cnt2 = 0
ans = 0
for i in range(len(S)):
    if S[i] == "A":
        cnt1 += 1
    elif S[i] == "D":
        cnt2 += 1
        ans += cnt1
    else:
        cnt1 = 0
        cnt2 = 0
print(ans)

Solution (Python):
s=input()
cnt=ans=0
i=0
while i<len(s)-1:
	if s[i]=="A":
		cnt+=1
		i+=1
	elif s[i]+s[i+1]=="BC":
		ans+=cnt
		i+=2
	else:
		cnt=0
		i+=1
print(ans)

Solution (Python):
"""Binary Indexed Tree (Fenwick Tree)"""
class BIT:
    def __init__(self, n):
        self.n = n
        
        
        self.data = [0]*(n+1)
        
        
        self.el = [0]*(n+1)
    
    """A1~Aiまでの累積和"""
    def Sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            
            
            i -= i & (-i) 
        return s
    
    """Ai += x"""
    def Add(self, i, x):
        self.el[i] += x
        while i <= self.n:
            self.data[i] += x
            i += i & -i
    
    """Ai ~ Ajまでの累積和"""
    def Get(self, i, j=None):
        if j is None:
            return self.el[i]
        return self.Sum(j) - self.Sum(i)
    
s = input()
s = s.replace('BC', 'D')
mode = 0
res = 0
for i in range(len(s)):
    if s[i] == 'B' or s[i]=='C':
        mode = 0
    elif s[i] == 'A':
        mode += 1
    else:
        res += mode
print(res)

Solution (Python):
s=input().replace("BC","D")+"E"

A=[]
word=""
for i in s:
    if i=="A" or i=="D":word +=i
    else:A.append(word);word=""

cnt=0
for i in A:
    a=0
    for j in i:
        if j=="A":a +=1
        else:cnt +=a

print(cnt)

Solution (Python):
S=input().replace("BC","D").split("B")
T=[]
for t in S:
    for u in t.split("C"):
        T.append(u)

ans=0
for s in T:
    n=len(s)
    k=0
    for i in range(n):
        if s[i]=="D":
            ans+=(i-k)
            k+=1
print(ans)

Solution (Python):
S=input()
ans=0
a=0
for i in range(len(S)):
    if S[i]=="A":
        if i>0 and S[i-1]=="B":
            a=0
        a+=1
    elif S[i]=="B":
        if i>0 and S[i-1]=="B":
            a=0
    elif S[i]=="C":
        if i>0 and S[i-1]=="B":
            ans+=a
        else:
            a=0
print(ans)

Solution (Python):
s = input()
s = s.replace("BC", "D")
N = len(s)

cnt = 0
ans = 0
for c in s:
    if c == "A":
        cnt += 1
    elif c == "D":
        ans += cnt
    else:
        cnt = 0
print(ans)

Solution (Python):
import sys

def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getlist():
    return list(map(int, input().split()))
import math
import heapq
from collections import defaultdict, Counter, deque
MOD = 10**9 + 7
INF = 10**15


def main():
    ans = 0
    s = input().strip()
    
    pre = ""
    state = ""
    cnta = 0
    for c in s:
        if c == "A":
            if state == "A":
                cnta += 1
            else:
                state = "A"
                cnta = 1
        if c == "B":
            if state == "A":
                state = "AB"
            else:
                state = ""
                cnta = 0
        if c == "C":
            if state == "AB":
                ans += cnta
                state = "A"
            else:
                state = ""
                cnta = 0

    print(ans)

if __name__ == '__main__':
    main()

"""
9999
3

2916
"""

Solution (Python):
s = input()
ans = 0
count = 0

for x in s.replace("BC", "Z"):
    if x == "A":
        count += 1
        continue
    elif x == "Z":
        ans += count
    else:
        count = 0
print(ans)

Solution (Python):

import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

s = input()
s = s.replace("BC", "D")
n = len(s)
for i in range (n):
  if s[i] == "A":
    count += 1
  elif s[i] == "D":
    ans += count
  else:
    count = 0
print(ans)

Solution (Python):
def main():
    S = input()
    S = S.replace("BC", "D")
    N = len(S)
    ans = 0
    a_cnt = 0
    for i in range(N):
        if S[i] == "A":
            a_cnt += 1
        elif S[i] == "D":
            ans += a_cnt
        else:
            a_cnt = 0
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
s = input().replace('BC', 'D')
cnt = 0
ans = 0
for c in s:
    if c == 'A':
        cnt += 1
    elif c == 'D':
        ans += cnt
    else:
        cnt = 0
print(ans)

Solution (Python):
s = input()
cnt = 0
ans = 0
flag = False
for i in range(len(s) - 1):
    if flag:
        flag = False
        continue
    if s[i: i + 2] == 'BC':
        ans += cnt
        flag = True
    elif s[i] == 'A':
        cnt += 1
    else:
        cnt = 0
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
S = list(input())[: -1]
t = []
res = 0
i = 1
while i < len(S):
  if S[i - 1] == "B" and (S[i] == "C"):
    t.append("X")
    i += 1
  else:
    if S[i - 1] == "A": t.append(S[i - 1])
    else: t.append("Y")
  i += 1
tt = "".join(t).split("Y")
for x in tt:
  xs = x.count("X")
  for i in range(len(x)):
    if x[i] == "A":
      res += xs
    else: xs -= 1
print(res)

Solution (Python):
s = input()
s = s.replace("BC","D")
ans = 0
a = 0
for k in range(len(s)):
    if s[k] == "A":
        a += 1
    elif s[k] == "D":
        ans += a
    else:
        a = 0
print(ans)

Solution (Python):
S = "???" + input() + "???"

a = 0

ans = 0
i = 0
while i < len(S):
    s = S[i]

    if s == "A":
        a += 1
        i += 1
        while i < len(S):
            s1 = S[i]
            s2 = S[i + 1]

            if s1 == "A":
                a += 1
                i += 1
                continue
            elif s1 + s2 == "BC":
                ans += a
                i += 2
            else:
                break

        a = 0
    else:
        i += 1
        continue

print(ans)

Solution (Python):
s=input()
n=len(s)
i,a,ans=0,0,0
while i<n:
    if s[i]=="A":
        a+=1
        i+=1
    elif i<n-1 and s[i:i+2]=="BC":
        ans+=a
        i+=2
        while i<n:
            if s[i]=="A":
                a+=1
                i+=1
            elif i<n-1 and s[i:i+2]=="BC":
                ans+=a
                i+=2
            else:
                a=0
                i+=1
                break
    else:
        i+=1
        a=0
print(ans)

Solution (Python):
S = list(input())

ans = 0
cnt = 0
i = len(S)-1
while i >= 0:
    if i > 0 and S[i] == "C" and S[i-1] == "B":
        cnt += 1
        i -= 2
    elif S[i] == "A":
        ans += cnt
        i -= 1
    else:
        cnt = 0
        i -= 1
print(ans)

Solution (Python):
s=input()
n=len(s)
i=0
a=0
ans=0
while i<n:
    if s[i]=="A":
        a+=1
        i+=1
    elif i<n-1 and s[i:i+2]=="BC":
        ans+=a
        i+=2
        while i<n:
            if s[i]=="A":
                a+=1
                i+=1
            elif i<n-1 and s[i:i+2]=="BC":
                ans+=a
                i+=2
            else:
                a=0
                i+=1
                break
    else:
        i+=1
        a=0
print(ans)

Solution (Python):
s = input()
ans = 0
Acnt = 0
cnt = 0
for c in s:
    if cnt <= 1 and c == "A":
        Acnt += 1
        cnt = 1
    elif c == "A":
        Acnt = 1
        cnt = 1
    elif cnt == 1 and c == "B":
        cnt = 2
    elif cnt == 2 and c == "C":
        ans += Acnt
        cnt = 1
    else:
        Acnt = 0
        cnt = 0
print(ans)

Solution (Python):
s = input()
N = len(s)












i = 0
a = 0
ans = 0

while i < len(s):
    if s[i] == 'A':
        a += 1
        i += 1
        continue
    if s[i] == 'B' and i + 1 < N:
        if s[i + 1] == 'C':
            ans += a
            i += 2
            continue
    a = 0
    i += 1

print(ans)

Solution (Python):
s = input()
a_cnt=0
ans=0
i=0
while i < len(s)-1:
    if s[i] == "A":
        a_cnt+=1
        i+=1
    elif s[i] == "B" and s[i+1] == "C":
        ans+=a_cnt
        i+=2
    else:
        a_cnt=0
        i+=1
print(ans)

Solution (Python):
s = input()
compress = []
i = 0
while i < len(s):
    if s[i:i+2] == 'BC':
        compress.append('D')
        i += 2
    else:
        compress.append(s[i])
        i += 1
ans = 0
count = 0
for x in compress:
    if x == 'A':
        count += 1
    elif x == 'D':
        ans += count
    else:
        count = 0
print(ans)

Solution (Python):
from sys import stdin
s = stdin.readline().rstrip()
s = s.replace("BC","D")
point = 0
count = 0
for i in s:
    if i == "A":
        count += 1
    elif i == "D":
        point += count
    else:
        count = 0
print(point)

Solution (Python):
s = list(input())
cnt = 0
stack = 0
skip = 0
for i in range(len(s)-1):
  
  if skip:
    skip -= 1
    continue
  if s[i] == "A":
    stack += 1
    continue
  if s[i:i+2] == ["B", "C"]:
    cnt += stack
    skip = 1
  else:
    stack = 0
print(cnt)

Solution (Python):
s = input()
t = s.replace('BC', 'D')
a_count = 0
ans = 0
for i in range(len(t)):
    if t[i] == 'A':
        a_count += 1
    elif t[i] == 'D':
        ans += a_count
    else:
        a_count = 0
print(ans)

Solution (Python):
S = input()
ans = 0
idx = 0
a_count = 0
while idx < len(S):
    if S[idx] == "A":
        a_count += 1
    elif S[idx:idx+2] == "BC":
        ans += a_count
        idx += 1
    else:
        a_count = 0
    idx += 1
print(ans)

Solution (Python):
s=input().replace('BC','D')
ans=0
ac=0
for c in s:
    if c=='A':
        ac+=1
    elif c=='D':
        ans+=ac
    else:
        ac=0
print(ans)

Solution (Python):
S = list(input())
N = len(S)

if S[0] == 'A':
    ac = 1
else:
    ac = 0

ans = 0
for i in range(1,N):
    if S[i] == 'A':
        if S[i-1] != 'A':
            ac = 1
        else:
            ac += 1
    elif S[i] == 'B':
        if S[i-1] != 'A':
            ac = 0
    else:
        if S[i-1] == 'B':
            ans += ac
            S[i] = 'A'
        else:
            ac = 0

print(ans)

Solution (Python):
s=str(input())
n=len(s)
z=0
ans=0
i=0
while i<=n-2:
    if s[i]=='A':
        z+=1
        i+=1
        continue
    elif s[i:i+2]=='BC' and z>0:
        ans+=z
        i+=2
    else:
        z=0
        i+=1
print(ans)

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(S):
    S = S.replace('BC', 'D')
    S = S.replace('B', ' ')
    S = S.replace('C', ' ')

    ans = 0
    for s in S.split():
        a = 0
        for c in s:
            if c == 'A':
                a += 1
            else:
                ans += a
    return ans

def main():
    S = read_str()
    print(slv(S))


if __name__ == '__main__':
    main()

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.readline
readlines = sys.stdin.buffer.readlines

S = readline().rstrip()
S = S.replace('BC', '

tmp = 0
ans = 0
for i in range(len(S)-1,-1,-1):
	if S[i] == "
		tmp += 1
	elif S[i] == "A":
		ans += tmp
	else:
		tmp = 0
print(ans)

Solution (Python):
S = input()
c = 0
i = 0
ac = 0
while i < len(S):
    if S[i] == "A":
        ac += 1
    elif S[i:i+2] == "BC":
        c += ac
        i += 1
    else:
        ac = 0
    i += 1
print(c)

Solution (Python):
S = input()
ABD = S.replace("BC","D")
a_cnt = 0
ans = 0


for s in ABD:
    if s == 'A':
        a_cnt += 1
    elif s == 'D':
        ans += a_cnt
    elif s == 'B' or s == 'C':
        a_cnt = 0
print(ans)

Solution (Python):
S=input()

i=0
T=[]
while i<len(S):

    if i+1<len(S) and S[i]+S[i+1]=="BC":
        T.append("D")
        i+=2
    else:
        T.append(S[i])
        i+=1
count=0
m=0
Acount=0

for i in range(len(T)):
    if "A"==T[i]:
        Acount+=1
    elif "D"==T[i]:
        count+=Acount
    else:
        Acount=0




print(count)

Solution (Python):
s = input()
ans = 0
a = 0
i = 0
while i < len(s):
    c = s[i]
    if c == 'A':
        a += 1
    elif c == 'B':
        i += 1
        if i >= len(s):
            break
        c = s[i]
        if c == 'C':
            ans += a
        elif c == 'A':
            a = 1
        else:
            a = 0
    elif c == 'C':
        a = 0
    i += 1
print(ans)