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:
def main():
    import sys
    input = sys.stdin.readline
    S = input().strip()
    a_cnt = 0
    state = 0
    ans = 0
    for s in S:
        if s == 'A':
            if state == 0:
                a_cnt += 1
            else:
                a_cnt = 1
                state = 0
        elif s == 'B':
            if state == 0:
                state = 1
            else:
                a_cnt = 0
        elif s == 'C':
            if state == 1:
                ans += a_cnt
                state = 0
            else:
                a_cnt = 0

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    S = input().strip()
    a_cnt = 0
    state = 0
    ans = 0
    for s in S:
        if s == 'A':
            if state == 0:
                a_cnt += 1
            else:
                a_cnt = 1
                state = 0
        elif s == 'B':
            if state == 0:
                state = 1
            else:
                a_cnt = 0
        elif s == 'C':
            if state == 1:
                ans += a_cnt
                state = 0
            else:
                a_cnt = 0

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
s = sys.stdin.readline().rstrip()
N = len(s)

def next_abc(ac, start):
    for i in range(start, N):
        if ac and i < N-1 and s[i] == 'B' and s[i+1] == 'C':
            return ac, i+2
        elif s[i] == 'A':
            ac += 1
        else:
            ac = 0
    return 0, N

ans = ac = i = 0
while i < N:
    ac, i = next_abc(ac, i)
    ans += ac
print(ans)

Submission status: Accepted

Solution code:
import re
s=input()
ans=0

s=re.sub('BC', 'D', s)

re_ad=re.compile(r'[AD]+')
ad=re.findall(re_ad,s)
#print(s)
#print(ad)
for adi in ad:
    adi_a=0
    for adij in adi:
        if(adij=='A'):
            adi_a+=1
        else:
            ans+=adi_a

print(ans)

Submission status: Accepted

Solution code:
s = input()
s = s.replace("BC","Z")
cnt = 0
c = 0
for i in s:
	if i == "A":
		c += 1
	elif i == "Z":
		cnt += c
	else:
		c = 0
print (cnt)

Submission status: Accepted

Solution code:
s = str(input())
lis = []
cnt = 0

while cnt < len(s):
    if cnt+1 < len(s) and (s[cnt] == "B" and s[cnt+1] == "C"):
        lis.append("D")
        cnt += 1
    else:
        lis.append(s[cnt])
    cnt += 1
  #    print(lis)

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

Submission status: Accepted

Solution code:
s=input()
N=len(s)
ans=0
data=[]
i=0
while N>i:
    if s[i]=='A':
        data.append('X')
        i+=1
    elif s[i]=='B' and i<len(s)-1 and s[i+1]=='C':
        data.append('A')
        i+=2
    else:
        index=[]
        count=0
        for j in range(0,len(data)):
            if data[j]=='A':
                index.append(j)
                count+=1

        for j in range(count):
            ans+=index[j]-j
        data=[]
        i+=1
else:
    if data:
        index=[]
        count=0
        for j in range(0,len(data)):
            if data[j]=='A':
                index.append(j)
                count+=1

        s=0
        for j in range(count):
            s+=index[j]-j

        ans+=s

print(ans)

Submission status: Accepted

Solution code:
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    S = input()
    S = S.replace("BC", "X")
    cnt_a = 0
    answer = 0
    for s in S:
        if s == "A":
            cnt_a += 1
        elif s == "X":
            answer += cnt_a
        else:
            cnt_a = 0
    print(answer)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    S = input()
    S = S.replace("BC", "X")
    S = S.replace("C", "B")
    S = S.split("B")
    answer = 0
    for s in S:
        place = []
        c = 0
        n = len(s)
        for i in range(n):
            if s[i] == "A":
                c += 1
                place.append(i + 1)
        for p in place:
            c -= 1
            answer += n - c - p
    print(answer)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
S = input()
S = S.replace("BC", "X")
n = len(S)
ans = 0
cnt_a = 0

for s in S:
    if s == "X":
        ans += cnt_a
    elif s == "A":
        cnt_a += 1
    else:
        cnt_a = 0

print(ans)

Submission status: Accepted

Solution code:
S = input()
S = S.replace("BC", "X")
ans = 0
lo = 0
while True:
    while lo < len(S) and (S[lo] == "B" or S[lo] == "C"): lo += 1
    if lo == len(S): break
    hi = lo
    X = 0
    while hi < len(S) and S[hi] != "B" and S[hi] != "C":
        if S[hi] == "X": 
            ans += hi - lo
            lo += 1 
        hi += 1
    lo = hi
print(ans)

Submission status: Accepted

Solution code:
s=input()

while 'BC' in s:
    s=s.replace('BC','D')
ans=0
a=0
for i in range (len(s)):
    if s[i]!='A' and s[i]!='D':
        a=0
        continue
    elif s[i]=='A':
        a+=1
    elif s[i]=='D':
        ans+=a
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=list(input())
x=[]
for i in range(len(s)):
    if s[i]=='A':
        x.append(0)
    elif s[i]=='B':
        x.append(1)
    elif i>0 and s[i]=='C' and s[i-1]=='B':
        x[-1]=3
    else:
        x.append(2)
ans=0
tmp0=0
for i in range(len(x)):
    if x[i]==0:
        tmp0+=1
    if x[i]==3:
        ans+=tmp0
    if x[i]!=0 and x[i]!=3:
        tmp0=0
print(ans)

Submission status: Accepted

Solution code:
s = input()
s = s.replace("BC","D")
a,ans = 0,0
#Dより前にあるB,C意外でつながったAの数をカウント
for i in s:
    if i == "A":
        a += 1
    elif i == "D":
        ans += a
    else:
        a = 0
print(ans)

Submission status: Accepted

Solution code:
s=input()
s=s.replace("BC","D")
s=s.replace("B","E")
s=s.replace("C","E")
s=s.split("E")

t=[]
for ss in s:
  if len(ss)!=0:
    t.append(ss)
ans=0

for tt in t:
  d_cnt=0
  for i,ttt in enumerate(tt):
    if ttt=="D":
      ans+=i-d_cnt
      d_cnt+=1
print(ans)

Submission status: Accepted

Solution code:
s = input()
#Aの海をかき分けてBCが進む

r = list(reversed(list(s)))
r = ['X'] + r + ['X']
#print(r)
BC_cnt = 0
A_cnt = 0
cnt = 0
for i in range(1, len(s) + 1):
    if r[i] == 'A':
        cnt += BC_cnt
        #print(BC_cnt, A_cnt)
    elif r[i] == 'C' and r[i + 1] == 'B':
        BC_cnt += 1
    elif r[i - 1] == 'C' and r[i] == 'B':
        pass
    else:
        BC_cnt = 0
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

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

# parts = []
# i_prev = 0
# for i in range(1, len(t) + 1):
#     if t[i] in 'BC':
#         parts.append(t[i_prev : i])
#         i_prev = i + 1
#     else:
#         continue
# else:
#     if i_prev < N: parts.append(t[i_prev : N])
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)

Submission status: Accepted

Solution code:
#ABCがBCAになる
#ADがDAになる
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/agc034/tasks/agc034_b

# BCをDに置換すればあとは簡単。いくつのAがDを超えるのかをカウントするだけ
# ADとなる
s = input()
s = s.replace('BC', 'D')
# print(s)

nA = 0
ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()

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

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))
#print(block_list)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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

#solve
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


#main
if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
# input = sys.stdin.readline

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()))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
s=s.replace("BC","Z")
#print(s)

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

Submission status: Accepted

Solution code:
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
    # print(lst)
    # print(i,ans,cnt)
    i+=1
print(ans)
# print(lst)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
"""Binary Indexed Tree (Fenwick Tree)"""
class BIT:
    def __init__(self, n):
        self.n = n
        
        #BIT木データ
        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]
            
            #LSB(Least Significant Bit)の獲得:i&(-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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input().replace("BC","D").split("B")
T=[]
for t in S:
    for u in t.split("C"):
        T.append(u)
#print(T)
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
s = s.replace("BC", "D")
N = len(s)
# print(s)
cnt = 0
ans = 0
for c in s:
    if c == "A":
        cnt += 1
    elif c == "D":
        ans += cnt
    else:
        cnt = 0
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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)

Submission status: Accepted

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