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

cb_cnt = 0
state = 0

for i in range(n)[::-1]:
    
    if state == 0:
        if s[i] == "C":
            cb_cnt = 1
            state = 1
            continue
    
    elif state == 1:
        if s[i] == "B":
            state = 2
            continue
        elif s[i] == "C":
            cb_cnt = 1
            continue
    
    elif state == 2:
        if s[i] == "C":
            cb_cnt += 1
            state = 1
            continue
        elif s[i] == "A":
            ans += cb_cnt
            state = 3
            continue
    
    elif state == 3:
        if s[i] == "C":
            state = 1
            cb_cnt += 1
            continue
        elif s[i] == "A":
            ans += cb_cnt
            continue
    cb_cnt = 0
    state = 0
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**8)

s = input()
n = len(s)
dp = [-1 for i in range(n)]
def count(i):
    if dp[i] != -1:
        return dp[i]
    elif i+2 >= n:
        dp[i] = 0
    elif s[i+1] == 'B' and s[i+2] == 'C':
        dp[i] = count(i+2)+1
    elif s[i+1] == 'A':
        dp[i] = count(i+1)
    else:
        dp[i] = 0
    return dp[i]
ans = 0
for i in range(n):
    if s[i] == 'A':
        ans += count(i)

print(ans)

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

def calculate(d_position):
    result = sum(d_position)
    result -= (len(d_position) * (len(d_position) - 1)) // 2
    return result


d_position = []
counter = 0
prev = ''
is_candidate = False
for s in S:
    if not is_candidate and s == 'A':
        
        is_candidate = True
        prev = 'A'
    elif is_candidate:
        if s == 'B' or s == 'C':
            
            counter += calculate(d_position)
            is_candidate = False
            d_position = []
            prev = ''
        else:
            prev += s
            if s == 'D':
                d_position.append(len(prev)-1)
if is_candidate:
    counter += calculate(d_position)
print(counter)

Solution (Python):
S = input()
N = len(S)
if N < 3:
    print("0")
else:
    cnt = 0
    row_A = 0 
    target = "BC"
    index = 0
    lim = N-2
    while index <= lim:
        if S[index] == "A":
            row_A += 1
            index += 1
        elif S[index:index+2] == target: 
            index += 2
            cnt += row_A 
        elif S[index+1] == "A": 
            row_A = 1
            index += 2
        else: 
            row_A = 0
            index += 2
    print(str(cnt))

Solution (Python):
s = input()

seq = 0
i = 0
sum_count = 0
while i < len(s):
    if s[i] == 'A':
        seq += 1
        i += 1
    elif s[i] == 'B' and i+1 < len(s) and s[i+1] == 'C':
        sum_count += seq
        i += 2
    else:
        seq = 0
        i += 1

print(sum_count)

Solution (Python):
s = input()

count = 0
ac = 0
abc = 0
carry = 0
for c in s:
    if c == 'A':
        ac += 1
        abc = 1
    elif c == 'B':
        if abc == 1:
            carry = ac
            abc = 2
        else:
            abc = 0
        ac = 0
    elif c == 'C':
        if abc == 2:
            count += carry
            ac = carry
            abc = 1
        else:
            ac = 0
            abc = 0
print(count)

Solution (Python):
s = input()
ans = 0
i = 0
prev_c = None
for c in s:
    if prev_c == 'B':
        if c == 'C':
            ans += i
        elif c == 'A':
            i = 1
        else: 
            i = 0
    else: 
        if c == 'A':
            i += 1
        elif c == 'C':
            i = 0
        else: 
            pass
    prev_c = c
print(ans)

Solution (Python):
s=input()
n=len(s)
a_seq=0
last='x'
ans=0
count=10*6
for i in s:
    if i=='A':
        if last=='A':
            a_seq=a_seq+1
        else:
            a_seq=1
        count=2
        last=i
    elif i=='B':
        count=count-1
        last=i
    else:
        if count==1 and last=='B':
            ans=ans+a_seq
            count=2
            last='A'
        else:
            a_seq=0
            count=count-1
            last='C'
print(ans)

Solution (Python):
ans = 0
s = input().replace("BC","D")
l1 = list(s.split("B"))
l2 = []
for x in l1:
  l2 += list(x.split("C"))
for x in l2:
  if x == "":
    continue
  d = 0
  t = 0
  for i in range(len(x)):
    if x[i] == "D":
      d += 1
      t += i
  ans += t - d*(d-1)//2
print(ans)

Solution (Python):
s = input().replace('BC', 'P').replace('C', 'X').replace('B', 'X')
n = len(s)

answer = 0
a = 0
for i in range(n):
    if s[i] == 'A':
        a += 1
    elif s[i] == 'P':
        answer += a
    else:
        a = 0

print(answer)

Solution (Python):
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
Max = sys.maxsize
def l():
	return list(map(int,input().split()))
def m():
	return map(int,input().split())
def s(x):
	a = []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa != x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x):
	return " ".join(map(str,x))

l = list(input())
k = s(l)
co = 0
a = 0
b = 0
if k[0][0] == "A":
	a = k[0][1]
for i in range(1,len(k)):
	if k[i][0] == "A":
		if b == 0:
			a += k[i][1]
		else:
			a = k[i][1]
			b = 0
	elif k[i][0] == "B":
		if k[i][1] == 1:
			b = 1
		else:
			b = 0
			a = 0
	else:
		if b == 1:
			if k[i][1] == 1:
				co += a
				b = 0
			else:
				co += a
				a = 0
				b = 0
		else:
			a = 0

print(co)

Solution (Python):
S=input()
S=S.replace('BC','X')
S=S.replace('B','Y')
S=S.replace('C','Y')
S=S.split('Y')

ans=0
for s in S:
    if not s:
        continue
    l=len(s)
    C=[0]*l
    cnt=0
    for i in reversed(range(l)):
        if s[i]=='X':
            cnt+=1
        C[i]=cnt
    
    for i in range(l):
        if s[i]=='A':
            ans+=C[i]
print(ans)

Solution (Python):
S = input()
ans = 0
a = 0
bc = 0
now = 0
for s in S:
    if s == "A":
        if now == 1:
            a = 1
            bc = 0
            now = 0
        else:
            a += 1
    elif s == "B":
        if now == 0:
            now = 1
        else:
            a = 0
            bc = 0
            now = 0
    else:
        if now == 1:
            ans += a
            now = 0
        else:
            a = 0
            bc = 0
print(ans)

Solution (Python):
def solve():
    s = input()
    ans = 0
    x = 0 
    a = 0 
    n = len(s)
    for i in range(n):
        c = s[i]
        if x == 0:
            if c == 'A':
                x = 1
                a = 1
            continue
        if x == 1:
            if c == 'A':
                a += 1
            if c == 'B':
                x = 2
            if c == 'C':
                x = 0
                a = 0
            continue
        if x == 2:
            if c == 'A':
                x = 1
                a = 1
            if c == 'B':
                x = 0
                a = 0
            if c == 'C':
                x = 1
                ans += a
    return ans
print(solve())

Solution (Python):
S = input()

WALL = 0
ACTIVATE = 1
CHANCE, BINGO = 2, 3

nBC = 0
score = 0
state = WALL
for c in reversed(S):
	if c == 'A' and (state == BINGO or state == ACTIVATE):
		state = ACTIVATE
	elif c == 'B' and state == CHANCE:
		state = BINGO
	elif c == 'C':
		if state == CHANCE:
			nBC = 0
		state = CHANCE
	else:
		state = WALL
	
	if state == WALL:
		nBC = 0
	elif state == ACTIVATE:
		score += nBC
	elif state == BINGO:
		nBC += 1

print(score)

Solution (Python):
inp = input()
changed_input = inp.replace('BC', 'D')
A_count = 0
total_ans = 0
for st in changed_input:
    if st == 'A':
        A_count += 1
    elif st == 'D':
        total_ans += A_count
    else:
        A_count = 0
print(total_ans)

Solution (Python):
S = input()
cnt = 0
a = 0
mode = '*'
for s in S:
  if mode == 'A':
    if s == 'A':
      a += 1
    elif s == 'B':
      mode = 'B'
    else:
      a = 0
      mode = '*'
  elif mode == 'B':
    if s == 'A':
      a = 1
      mode = 'A'
    elif s == 'B':
      a = 0
      mode = '*'
    else:
      cnt += a
      mode = 'C'
  elif mode == 'C':
    if s == 'A':
      a += 1
      mode = 'A'
    elif s == 'B':
      mode = 'B'
    else:
      a = 0
      mode = '*'
  else:
    if s == 'A':
      a = 1
      mode = 'A'
print(cnt)

Solution (Python):
import sys
range = xrange
input = raw_input

S = list(input())

n = len(S)

counter = 0
prefixA = 0
for i in range(n-1):
    if S[i] == 'A':
        prefixA += 1
    elif prefixA and S[i:i+2] == ['B','C']:
        counter += prefixA
        prefixA -= 1
        S[i+1] = 'A'
    else:
        prefixA = 0
print counter

Solution (Python):
import sys,heapq
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True 
def ddprint(x):
  if DBG:
    print(x)

s = input()
n = len(s)
bcs = 0  
cbcs = 0  
sum = 0
for i in range(n-1,-1,-1):
    if s[i]=='C':
        cbcs = bcs+1
        bcs = 0
    elif s[i]=='B':
        if i<n-1 and s[i+1]=='C':
            bcs = cbcs
        else:
            bcs = 0
        cbcs = 0
    else:
        sum += bcs
        cbcs = 0

print(sum)

Solution (Python):
s = input()

cnt = 0
if s[0] == "A":
  a = 1
  f = 1
else:
  f = 0
  a = 0

for i in s[1:]:
  if i == "A":
    if f == 1:
      a += 1
    else:
      a = 1
    f = 1
  elif i == "B":
    if f == 1:
      f = 2
    else:
      f = 0
      a = 0
  else:
    if f == 2:
      cnt += a
      f = 1
    else:
      a = 0
      f = 0

print(cnt)

Solution (Python):
s = input()
stock_bc = 0
state = 0
ans = 0

for i in range(len(s)):

    if s[-1-i] == "C":
        if state == 1:
            stock_bc = 0
        state = 1

    elif s[-1-i] == "B":
        if state == 0:
            stock_bc = 0
        elif state == 1:
            stock_bc += 1
        state = 0

    elif s[-1-i] == "A":
        if state == 0:
            ans += stock_bc
        else:
            stock_bc = 0
            state = 2

print(ans)

Solution (Python):
s=input()
c=0
d=0
i=0
while i<len(s):
    if s[i]=="A":
        c+=1
    else:
        if s[i]=="B" and c>0:
            if i<len(s)-1:
                if s[i+1]=="C":
                        d+=c
                        i+=1
                else:
                    c=0
        else:
            c=0
    i+=1
print(d)

Solution (Python):
S = input()

ans = 0
w = -1
for i, s in enumerate(S.replace("A", "0").replace("BC", "1")):
    if "01".find(s) >= 0:
        if w < 0:
            w = i
    else:
        w = -1

    if w >= 0:
        if s == "1":
            ans += i - w
            w += 1
print(ans)

Solution (Python):
s = input()
N = len(s)
s = s + 'D'

cnt = 0
ans = 0
A_num = 0
plus1 = 0
while cnt < N:
    if s[cnt] == 'A':
        A_num += 1
    elif s[cnt] == 'B':
        if s[cnt + 1] == 'C':
            ans += A_num
            plus1 = 1
        else:
            A_num = 0
    else:
        A_num = 0
    cnt += 1
    if plus1:
        cnt += 1
        plus1 = 0
print(ans)

Solution (Python):
s = list(input())
N = len(s)
s.append("x")

L = []
i = 0
l = []
while i < N:
	if s[i] == "A":
		l.append("a")
		i += 1
	elif s[i] == "B" and s[i + 1] == "C":
		l.append("b")
		i += 2
	else:
		if l != []:
			L.append(l)
		l = []
		i += 1

if l != []:
	L.append(l)

n = len(L)
ans = 0

for i in range(n):
	bcnt = 0
	bshift = 0
	nn = len(L[i])
	for j in range(nn):
		if L[i][j] == "b":
			bcnt += 1
			bshift += j
	ans += bshift - int(bcnt * (bcnt - 1) // 2)

print(ans)

Solution (Python):
s = raw_input()
countA = 0
flag = 0
count = 0
for c in s:
	if c == 'A':
		if(flag == 2):
			countA = 1
			flag = 1
		else:
			countA += 1
			flag = 1
	else:
		if(flag == 1 and c =='B'):
			flag = 2
		elif(flag == 2 and c == 'C'):
			count += countA
			flag = 1
		else:
			flag = 0
			countA = 0
print(count)

Solution (Python):
import sys

from fractions import gcd
from bisect import bisect_right





from itertools import accumulate













input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())



def iterate_tokens():
    for line in sys.stdin:
        for word in line.split():
            yield word


if __name__ == '__main__':

    tokens = iterate_tokens()
    s = list(next(tokens))  
    n = len(s)
    cnt = 0
    lastfin = -1
    
    num = 0
    while(num<n):
        if s[num] == 'A':
            j = num
            tmpcnt = []
            tmpa = []
            while (j < n-1):
                if s[j] == 'A':
                    tmpa.append(j)
                    j += 1
                elif s[j] == 'B' and s[j + 1] == 'C':
                    tmpcnt.append(j)
                    j += 2
                else:
                    break
            num = j+1
            
            
            for t in tmpa:
                cnt += len(tmpcnt)-bisect_right(tmpcnt,t)
            
        else:
            num += 1
            continue
    print(cnt)

Solution (Python):
s = input()

ans = 0
A_count = 0

pass_flag = 0

for i in range(len(s) - 1):
    
    if pass_flag:
        pass_flag = 0
        continue
    if s[i] == "B" and s[i + 1] == "C":
        ans += A_count
        pass_flag = 1
    elif s[i] == "A":
        A_count += 1
    else:
        A_count = 0

print(ans)

Solution (Python):
s = input()

'''
X:=A
Y:=BC
'''

s = s.replace('A', 'X').replace('BC', 'Y')

y = 0
buf = 0
ans = 0
for ss in reversed(s):
    if ss == 'Y':
        y += 1
    elif ss == 'X':
        buf += y
    else:
        
        ans += buf
        y = 0
        buf = 0
ans += buf
print(ans)

Solution (Python):
def abc(s: str)->int:
    count = 0  
    countA = 0  

    i, N = 0, len(s)
    while i < N:
        if s[i] == 'A':
            countA += 1
            i += 1
        elif s[i] == 'B':
            if countA > 0 and i+1 < N and s[i+1] == 'C':
                count += countA
                i += 2
            else:
                countA = 0
                i += 1
        else:  
            countA = 0
            i += 1

    return count


if __name__ == "__main__":
    s = input()

    ans = abc(s)
    print(ans)

Solution (Python):
s = input()
ans = 0
Anum = 0
tmp = 0

while tmp < len(s):
    if s[tmp] == 'A':
        Anum += 1
        tmp += 1
    elif s[tmp:tmp+2] == 'BC':
        ans += Anum
        tmp += 2
    else:
        Anum = 0
        tmp += 1

print(ans)

Solution (Python):
S = input()
BLOCK = S.replace('BC', 'D').replace('B', ' ').replace('C', ' ').split()

ans = 0
for block in BLOCK:
    d_index = [i for i, s in enumerate(block) if s == 'D']
    ans += sum(r - i for (i, r) in enumerate(d_index))

print(ans)

Solution (Python):
S=str(input())
N=len(S)
numA=0
numBC=0
ans=0
counter=0
while counter<N-1:
    if(S[counter]=="A"):
        numA+=1
    elif(S[counter]=="B" and S[counter+1]=="C"):
        
        ans+=numA
        counter+=1
    else:
        numA=0
    counter+=1
print(ans)

Solution (Python):
s = list(input())[::-1] + [0,0]
N,i,ans = len(s),0,0

while i < N:
    if s[i] == 'C' and s[i+1] == 'B':
            temp = 1
            i += 2
            while i < N:
                if s[i] == 'A':
                    ans += temp
                    i += 1
                elif s[i] == 'C' and s[i+1] == 'B':
                    temp += 1
                    i += 2
                else:
                    break
    else:   i += 1

print(ans)

Solution (Python):
import re
s = list(input())
n = len(s)

cnt = 0
a_cnt = 0
i = 0

while True:
  if i >= n-1:
    break
  if s[i] == 'A':
    a_cnt += 1
    i += 1
  elif s[i] == 'B':
    if s[i+1] == 'C':
      cnt += a_cnt
      i += 2
    else:
      a_cnt = 0
      i += 1
  elif s[i] == 'C':
    a_cnt = 0
    i += 1

print(cnt)

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

Solution (Python):
s=str(input())
arr=[]
for i in range(len(s)):
	arr.append(s[i])
ans=0
n=len(arr)
count=0
i=0
while(i<n-2):
	if(arr[i]+arr[i+1]+arr[i+2]=="ABC"):
		ans+=1
		arr[i]="B"
		arr[i+1]="C"
		arr[i+2]="A"
		j=i-1
		i+=2
		ans+=count
	else:
		if(arr[i]=="A"):
			count+=1
		else:
			count=0
		i+=1
print(ans)

Solution (Python):
ss = input() + '

ss = ss.replace('BC', 'Z')

def func(ts):
    n = len(ts)
    nums = [0]*n
    num = 0
    for i in reversed(range(n)):
        if ts[i] == 'Z':
            num += 1
        nums[i] = num
    ans = 0
    for i, (t, num) in enumerate(zip(ts, nums)):
        if t == 'A':
            ans += num
    return ans

ans = 0
iFr = -1
for i, s in enumerate(ss):
    if s == 'A' or s == 'Z':
        if iFr == -1:
            iFr = i
    else:
        if iFr != -1:
            ans += func(ss[iFr:i])
            iFr = -1

print(ans)

Solution (Python):

"""
Created on Sun Jun  2 20:33:28 2019

@author: Yamazaki Kenichi
"""

S = input()

T = []

i = 0
while i < len(S):
    if S[i] == 'A':
        T += [1]
        i += 1
    elif i < len(S) - 1 and S[i] == 'B' and S[i+1] == 'C':
        T += [2]
        i += 2
    else:
        T += [0]
        i += 1


ans = 0
countA = 0
for c in T:
    if c == 1:
        countA += 1
    elif c == 2:
        ans += countA
    else:
        countA = 0
print(ans)

Solution (Python):
s = list(input())
n = len(s)
news = []
i = 0
while i < n:
    if i != n-1:
        if s[i] == "B" and s[i+1] == "C":
            news.append("X")
            i += 2
        else:
            news.append(s[i])
            i += 1
    else:
        news.append(s[i])
        i += 1

ans = 0
n = len(news)
xcounter = 0
for i in range(n):
    if news[-i-1] == "X":
        xcounter += 1
    elif news[-i-1] == "A":
        if xcounter > 0:
            ans += xcounter
    else:
        xcounter = 0
print(ans)

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

Solution (Python):
s = input().rstrip()

ans = 0
anum = 0
prev = "x"
for c in s:
    if c == "A":
        if prev != "B":
            anum += 1
        else:
            anum = 1
    elif c == "B":
        if prev == "B":
            anum = 0
    elif c == "C":
        if prev == "B":
            ans += anum
        else:
            anum = 0
    prev = c
print(ans)

Solution (Python):
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    s = input()
    slen = len(s)
    cnt_a = 0

    idx = 0
    ans = 0
    while idx<slen:
        while idx < slen and s[idx] == 'A':
            cnt_a += 1
            idx += 1
        
        if idx<slen and idx+1 < slen:
            if s[idx] == 'B' and s[idx+1] == 'C':
                ans += cnt_a
                idx += 2
            else:
                idx += 1
                cnt_a = 0
        else:
            break
    
    print(ans)



solve()

Solution (Python):
from collections import deque
st = deque()
s = input()
ans = 0
for i in range(len(s)-1):
    if s[i:i+2] != 'BC' and s[i] != 'A' and (i>0 and s[i-1:i+1] != 'BC'):
        st.clear()
        continue
    if s[i] == 'A':
        st.append(0)
    elif s[i:i+2] == 'BC':
        ans += len(st)
print(ans)

Solution (Python):
import sys


s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    S = i2s()
    n = 0
    na = 0
    ba = False
    bb = False
    for s in S:
        if s == 'A':
            if ba:
                na += 1
                ba = True
                bb = False
            elif bb:
                na = 1
                ba = True
                bb = False
            else:
                na = 1
                ba = True
                bb = False
        elif s == 'B':
            if ba:
                ba = False
                bb = True
            elif bb:
                na = 0
                ba = False
                bb = False
            else:
                na = 0
                ba = False
                bb = False
        else:
            if ba:
                na = 0
                ba = False
                bb = False
            if bb:
                n += na
                
                ba = True
                bb = False
            else:
                na = 0
                ba = False
                bb = False
    print(n)

main()

Solution (Python):
def count(s):
    if not s:
        return 0
    c1 = sum(s)
    return sum(i for i,v in enumerate(s) if v) - c1*(c1-1)//2


S = list(input())
S.reverse()
score = 0

tmp = []
while S:
    a = S.pop()
    if a == 'A':
        tmp.append(0)
    elif a == 'B' and S and S[-1] == 'C':
        S.pop()
        tmp.append(1)
    else:
        score += count(tmp)
        tmp = []

score += count(tmp)
print(score)

Solution (Python):
import sys
sys.setrecursionlimit(10**7)






def solve():
    s = input()

    
    s = s.replace("A", "1")
    s = s.replace("BC", "2")
    s = s.replace("B", "0")
    s = s.replace("C", "0")
    s_split = s.split("0")

    total_count = 0
    for subs in s_split:
        
        count_1 = 0

        for i in range(len(subs)):
            if subs[i] == "1":
                count_1 += 1
            elif subs[i] == "2":
                total_count += count_1

    print(total_count)

solve()

Solution (Python):
s = input()
s = s.replace("BC", "O")
s = s.replace("B", "X")
s = s.replace("C", "X")
a = 0
res = 0
for ch in s:
    if ch == "A":
        a += 1
    elif ch == "X":
        a = 0
    else:
        res += a

print(res)

Solution (Python):

def solve(): 
    S = input()
    count = 0
    count_a = 0
    s_ = ''

    for s in S:
        if s == 'A':
            if s_ == 'B':
                count_a = 0
            count_a += 1 
        elif s == 'B' and s_ == 'B':
            count_a = 0
        elif s == 'C':
            if s_ =='B':
                count += count_a
            else:
                count_a = 0
        s_ = s

    res = count
    return str(res)

if __name__ == '__main__':
    print(solve())

Solution (Python):



def readInt():
    return int(input())

def readList():
    return list(input().split())

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

def main():
    s = input()

    
    s2 = ""
    i = 0
    while i < len(s)-1:
        if s[i] == 'B' and s[i+1] == 'C':
            s2 += 'd'
            i += 1
        elif s[i] == 'A':
            s2 += 'a'
        else:
            s2 += s[i]
        i += 1
    ans = 0
    na = 0
    for c in s2:
        if c != 'a' and c != 'd':
            na = 0
            continue
        if c == 'a':
            na += 1
            continue
        ans += na
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
s = ['C']+list(input())
n = len(s)
res = 0
p = []

def f(p):
    if len(p) == 0:
        return 0
    cnt = 0
    ans = 0
    for e in p:
        if e == 'A':
            cnt += 1
        else:
            ans += cnt
    return ans

for i in range(1,n):
    if s[i] == 'A':
        p.append('A')
    elif s[i] == 'B':
        if s[i-1] == 'B' or (i+1<=n-1 and s[i+1] != 'C'):
            res += f(p)
            p = []
    else:
        if s[i-1] == 'B':
            p.append('B')
        else:
            res += f(p)
            p = []
res += f(p)
print(res)

Solution (Python):
S=input()

stock=0

L=len(S)
ANS=0
i=0
while i<L:
    if S[i]=="A":
        stock+=1
        i+=1

    elif i<L-1 and S[i]=="B" and S[i+1]=="C":
        ANS+=stock
        i+=2

    else:
        stock=0
        i+=1

print(ANS)

Solution (Python):
s = input()

S = []

A = 'A'
BC = 'BC'
X = 'X'

cursor = 0
while cursor < len(s):
    if s[cursor] == 'A':
        S.append(A)
        cursor += 1
        continue
    if cursor < len(s) - 1 and s[cursor] == 'B' and s[cursor+1] == 'C':
        S.append(BC)
        cursor += 2
    else:
        if len(S) > 0 and S[-1] == X:
            pass
        else:
            S.append(X)
        cursor += 1


score = 0
a_count = 0
for elm in S:
    if elm == A:
        a_count += 1
    elif elm == BC:
        score += a_count
    else:
        a_count = 0
print(score)

Solution (Python):
s = input()
s2 = ""
flag=0


for i in range(len(s)-1):
    if(flag==0):
        if(s[i]=="B" and s[i+1]=="C"):
            s2 += "D"
            flag = 1
        else:
            s2 += s[i]
    else:
        flag=0
    if(len(s)<=i+2):
        break


anum = 0
ans = 0

for i in s2:
    if i=="A":
        anum += 1
    elif i=="D":
        ans += anum
    else:
        anum = 0

print(ans)

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

ans = 0
T = []

def solve(S):
    f = -1
    res = 0
    for i, s in enumerate(S):
        if f != -1 and s == 'S':
            res += i - f
            f += 1
        elif f == -1 and s == 'A':
            f = i

    return res

for s in S:
    if s == 'B' or s == 'C':
        ans += solve(T)
        T = []
    else:
        T.append(s)

ans += solve(T)

print(ans)

Solution (Python):
s = input()

ans = 0
a = 0
b = 0
for i in range(len(s)):
    if s[i] == 'A':
        if b > 0:
            a = 1
            b = 0
        elif b == 0:
            a += 1
            b = 0
    if s[i] == 'B':
        if a > 0 and b == 0:
            b += 1
        elif b > 0:
            a = 0
            b = 0
    if s[i] == 'C':
        if b > 0:
            ans += a
            b = 0
        elif b == 0:
            a = 0
            b = 0
print(ans)

Solution (Python):
worda=input()
nagasa=len(worda)
word=""
for i in range(nagasa):
    word+=worda[nagasa-i-1]


status=0
renzoku=0
kazu=0

for i in range(nagasa):
    if word[i]=='C':
        if status==3:
            pass
        if status==2:
            pass
        if status==1:
            renzoku=0
        if status==0:
            renzoku=0
        status=1
    elif word[i]=='B':
        if status==3:
            renzoku=0
        if status==1:
            status=2
            renzoku+=1
        else:
            status=0
            renzoku=0
    else:
        if status==1:
            status=0
        elif status==2:
            kazu+=renzoku
            status=3
        elif status==3:
            kazu+=renzoku

print(kazu)

Solution (Python):
S=input()

ans = 0
temp_a = 0
prev_b = False
  
for s in S:
  if prev_b and s !='C' or prev_b==False and s=='C':
    temp_a = 0
    
  if s=='A' or s=='C':
    prev_b = False
  else:
    prev_b = True

  if s=='A':
    temp_a += 1
  elif s=='B':
    pass
  elif s=='C':
    ans += temp_a
      
print(ans)

Solution (Python):

def main():
    buf = input()
    S = list(buf)
    A_count = 0
    B_appeared = False
    op_count = 0
    for pointer, _ in enumerate(S):
        if S[pointer] == 'A':
            if B_appeared:
                B_appeared = False
                A_count = 0
            A_count += 1
        elif S[pointer] == 'B':
            if A_count == 0:
                pass
            elif not B_appeared:
                B_appeared = True
            else: 
                B_appeared = False
                A_count = 0
        else: 
            if not B_appeared:
                A_count = 0
            else:
                op_count += A_count
                B_appeared = False
    print(op_count)

if __name__ == '__main__':
    main()

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

Solution (Python):
S = list(input())
a = 0
sum_A = 0

if S[0] == 'A':
    a = 1

for i in range(1, len(S)-1):
    if S[i] == 'A':
        a += 1 
    elif S[i] == 'B' and S[i + 1] == 'C':
        sum_A += a
    elif S[i] == 'C' and S[i - 1] == 'B':
        continue
    else:
        a = 0

print(sum_A)

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

Solution (Python):
import sys

from sys import setrecursionlimit
setrecursionlimit(10**9)

def inpl(): return list(map(int, input().split()))
S = input()
T = S.replace("BC", "X")
U = T.replace("B", "_").replace("C", "_")

ans = 0
cnt = 0
for i in range(len(U)):
    if U[i] == "A":
        cnt += 1
    elif U[i] == "X":
        ans += cnt
    else:
        cnt = 0

print(ans)

Solution (Python):
S = input()

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

Solution (Python):
s = input()

A_acc = 0
cnt = 0


i = 0
while i<len(s):
    if s[i] == 'A':
        A_acc += 1
    else:
        if s[i:i+2] == 'BC':
            cnt += A_acc
            i += 2
            continue
        else:
            A_acc = 0
    i += 1
print(cnt)

Solution (Python):
S = input().strip()

def solve(S):
    a = 0
    move = 0
    i = 0
    while i < len(S)-1:
        if S[i] == 'A':
            a += 1
            i+=1
            continue
        if S[i] == 'B' and S[i+1] == 'C':
            move += a
            i+=2
            continue
        else:
            a = 0
            i+=1
    return move

print(solve(S))

Solution (Python):
S = input()

ans = 0
tmp = 0
l = len(S) - 1
i = 0
while i < l:
  x = S[i]
  y = S[i:i+2]
  if x == 'A':
    tmp += 1
  elif y == 'BC':
    ans += tmp
    i += 1
  else:
    tmp = 0
  i += 1

print(ans)