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



Sample input:
ABCABC


Sample output:
3

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
def solve():
    s = input()
    ans = 0
    x = 0 #どこまで完成しているか
    a = 0 #連続するAの数
    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())

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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 # and False
def ddprint(x):
  if DBG:
    print(x)

s = input()
n = len(s)
bcs = 0  # bc: 1  bcbc: 2
cbcs = 0  # c: 1  cbc: 2
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
import sys
# gcd
from fractions import gcd
from bisect import bisect_right
# 切り上げ，切り捨て
# from math import ceil, floor
# リストの真のコピー（変更が伝播しない）
# from copy import deepcopy
# 累積和。list(accumulate(A))としてAの累積和
from itertools import accumulate
# l = ['a', 'b', 'b', 'c', 'b', 'a', 'c', 'c', 'b', 'c', 'b', 'a']
# S = Counter(l)  # カウンタークラスが作られる。S=Counter({'b': 5, 'c': 4, 'a': 3})
# print(S.most_common(2))  # [('b', 5), ('c', 4)]
# print(S.keys())  # dict_keys(['a', 'b', 'c'])
# print(S.values())  # dict_values([3, 5, 4])
# print(S.items())  # dict_items([('a', 3), ('b', 5), ('c', 4)])
# from collections import Counter
# import math
# from functools import reduce
#
# input関係の定義
# fin = open('in_2.txt', 'r')
# sys.stdin = fin
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())
# template


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))  # type: str
    n = len(s)
    cnt = 0
    lastfin = -1
    # write code
    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
            # print(tmpa, tmpcnt, num)
            # print(len(tmpcnt))
            for t in tmpa:
                cnt += len(tmpcnt)-bisect_right(tmpcnt,t)
            # cnt.append(tmpcnt)
        else:
            num += 1
            continue
    print(cnt)

Submission status: Accepted

Solution code:
s = input()

ans = 0
A_count = 0

pass_flag = 0

for i in range(len(s) - 1):
    # print(ans,A_count)
    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)

Submission status: Accepted

Solution code:
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:
        # B or C
        ans += buf
        y = 0
        buf = 0
ans += buf
print(ans)

Submission status: Accepted

Solution code:
def abc(s: str)->int:
    count = 0  # 操作回数
    countA = 0  # 現在連続している 'A' の数

    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:  # s[i] == 'C'
            countA = 0
            i += 1

    return count


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

    ans = abc(s)
    print(ans)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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"):
        #BCよりも前にあるAの分だけ答えをたす
        ans+=numA
        counter+=1
    else:
        numA=0
    counter+=1
print(ans)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
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
#    print(i,S[i],T)

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
import sys
#import numpy as np

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
                #na = 0
                ba = True
                bb = False
            else:
                na = 0
                ba = False
                bb = False
    print(n)

main()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
#import numpy as np
# n = int(input())
# a, b = map(int, input().split())
# int_list = list(map(int, input().split()))
# l = list(input().split())

def solve():
    s = input()

    # A と BC と それ以外に分ける
    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:
        # subs は 12111212122 のような0を含まない文字列
        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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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())

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

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

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

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

def main():
    s = input()

    # BC->dに置き換え
    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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

#BCをDに変換
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

#ADをDAに
anum = 0
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:

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
                B_appeared = False
                A_count = 0
        else: # S[pointer] == 'C'
            if not B_appeared:
                A_count = 0
            else:
                op_count += A_count
                B_appeared = False
    print(op_count)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
import sys
#input = sys.stdin.readline
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq as hq
import itertools as its
import operator as op


# globals
inf = float('inf')
N = 0


def set_inputs():
    global N
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    # ----------MAIN----------
    s = get_str()
    a = 0
    i = 0
    ans = 0
    while i < len(s):
        if s[i] == 'A':
            a += 1
            i += 1
            continue
        if a > 0 and i < len(s) - 1 and s[i:i+2] == 'BC':
            ans += a
            i += 2
            continue
        a = 0
        i += 1
    print(ans)
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


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


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input().strip()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().strip().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import re
s = input()
s = s.replace('BC', 'x')
sl = re.findall(r'[^BC]+', s)
n = 0
for s in sl:
    xs = 0
    for c in reversed(s):
        if c == 'x':
            xs += 1
        else:
            n += xs
print(n)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
  text = input().strip()
  text = text.replace('BC', 'X')
  base = 0
  count = 0

  for i in range(len(text)):
    if text[i] == 'A':
      base += 1
    elif text[i] == 'X':
      count += base
    else:
      base = 0

  print(count)


if __name__ == '__main__':
  main()