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=list(input())

nS=[]
i=0
while i<len(S)-1:
  if S[i]=="B" and S[i+1]=="C":
    nS.append("D")
    i+=1
  else:
    nS.append(S[i])
  i+=1
    
t=[]
nl=[]
for i in nS:
  if i=="A" or i=="D":
    nl.append(i)
  else:
    if nl:
      t.append(nl)
      nl=[]
if nl:
  t.append(nl)


ans=0
for i in t:
  dn=0
  for j in range(len(i)):
    if i[j]=="D":
      ans+=j-dn
      dn+=1

print(ans)

Submission status: Accepted

Solution code:
s_ = input().lower()

L_s = []
i=0
while i<len(s_):
    if s_[i]=="a":
        L_s.append("a")
        i+=1
    elif s_[i]=="b":        
        if i<len(s_)-1 and s_[i+1]=="c":
            L_s.append("x")
            i+=2
        else:
            L_s.append("y")
            i+=1
    else:
        L_s.append("y")
        i+=1
        
L_s.append("a")
#xの次に何かの文字が来ることでansに加算されるため

s = ''.join(L_s)

if s[0]=="a":
    cnt_a = 1
else:
    cnt_a = 0
    
cnt_x = 0

ans = 0

for i in range(1,len(s)):
    if s[i]=="a":
        if s[i-1]=="a":
            cnt_a+=1
        elif s[i-1]=="x":
            ans += cnt_a*cnt_x
            cnt_x=0
            cnt_a+=1
        else:
            cnt_x = 0
            cnt_a = 1
    elif s[i]=="x":
        if s[i-1]=="x":
            cnt_x+=1
        elif s[i-1]=="a":
            ans += cnt_a*cnt_x
            cnt_x+=1
        else:
            cnt_x=1
            cnt_a=0
    else:
        if s[i-1]!="a":
            ans += cnt_a*cnt_x
        cnt_a=0
        cnt_x=0

        
print(ans)

Submission status: Accepted

Solution code:
s = input()
l = []
i = 0
while i < len(s):
    if s[i] == "A":
        l.append(0)
    elif s[i] == "B":
        if i < len(s)-1 and s[i+1] == "C":
            l.append(1)
            i += 1
        else: l.append(-1)
    else: l.append(-1)
    i += 1

cnt, ans = 0, 0
for x in l:
    if x == 0: cnt += 1
    elif x == 1: ans += cnt
    else: cnt = 0

print(ans)

Submission status: Accepted

Solution code:
s=list(input())
count=0
count1=0
for i in range(len(s)-2):
    if s[i:i+3]==['A','B','C']:
        count+=1
        s[i]='B'
        s[i+1]='C'
        s[i+2]='A'

            
        for j in range(1,len(s)):
            if i-j<0:
                count+=count1
                break
            if s[i-j]=='A':
                count1+=1
            else:
                count+=count1
                break
            
    if s[i:i+3]==['A','A','A'] or s[i:i+3]==['A','A','B'] or s[i:i+3]==['C','A','A'] or s[i:i+3]==['C','A','B'] or s[i:i+3]==['B','C','A']:
        continue
    else:
        count1=0


print(count)

Submission status: Accepted

Solution code:
# 2019/10/24
# 解答かんにんぐ

s=input().replace('BC','X')
n=len(s)
cnt=0
ans=0
for i in range(1,n):
    tmp=s[i-1]+s[i]
    if s[i-1]=='A':
        cnt+=1
    if tmp[1]=='X':
        ans+=cnt
    if tmp not in ['AX','AA','XX','XA']:
        cnt=0
print(ans)

Submission status: Accepted

Solution code:
s=input()
ans=0
check=1
while s:
    if s[:3]=='ABC':
        ans+=check
        s='A'+s[3:]
    else:
        if s[0]=='A':
            check+=1
            s=s[1:]
        else:
            check=1
            s=s[1:]
print(ans)

Submission status: Accepted

Solution code:
s = input()
a = 0
count = 0

i = 0
while i < len(s)-1:
  if s[i]=='A':
    a += 1
    i += 1
  elif s[i]=='B' and s[i+1]=='C':
    count += a
    i += 2
  else:
    a = 0
    i += 1
print(count)

Submission status: Accepted

Solution code:
s=input()

ans=0
a=0

i=0
while i<=len(s)-1:
    if s[i]=='A':
        a+=1
        i+=1
    elif i<=len(s)-2 and s[i]+s[i+1]=='BC':
        ans+=a
        i+=2
    else:
        a=0
        i+=1

print(ans)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
A = []

i = 0
while i < n-1:
    if s[i:i+2] == "BC":
        A.append("D")
        i += 2
    else:
        A.append(s[i])
        i += 1

t = "".join(A)
# print(t)

m = len(t)
i = 0
p = 0
ans = 0
while i < m:
    while i < m and (t[i] == "A" or t[i] == "D"):
        if t[i] == "A":
            p += 1
        else:
            ans += p
        i += 1
    p = 0
    i += 1

print(ans)

Submission status: Accepted

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

def main():
    s = input().strip()

    ans = 0
    count_a = 0
    if s[0] == "A":
        count_a += 1
    for i in range(len(s)-1):
        tmp = s[i:i+2]
        if tmp == "AA":
            count_a += 1
        elif tmp == "AB":
            pass
        elif tmp == "BC":
            ans += count_a
        elif tmp == "CB":
            pass
        elif tmp == "CA":
            count_a += 1
        elif tmp == "BA":
            count_a = 1
        else:
            count_a = 0
        # print(i, count_a)
    print(ans)
        

        


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s = input()
n = len(s)
li = [[] for i in range(n)]
ind = 0
i = 0
while True:
    if i >= n:
        break
    if s[i] == "A":
        li[ind].append("A")
        i += 1
        continue
    if i+1 >= n:
        break
    elif s[i] == "B" and s[i+1] == "C":
        li[ind].append("D")
        i += 2
    else:
        i += 1
        ind += 1

ans = 0
for arr in li:
    cnt = 0
    tmp = arr[::-1]
    for j in tmp:
        if j == "D":
            cnt += 1
        else:
            ans += cnt
print(ans)

Submission status: Accepted

Solution code:
def solve():
  s = input()
  news = ""
  n = len(s)
  pas = False
  for i in range(n-1):
    if pas:
      pas = False
      continue
    if s[i] == 'B' and s[i+1] == "C":
      news += "T"
      pas = True
    else:
      news += s[i]
  ans = 0
  beforea = 0

  n = len(news)
  for i in range(n):
    if news[i] == "A":
      beforea += 1
    elif news[i] == "B" or news[i] == "C":
      beforea = 0
    if news[i] == "T":
      ans += beforea 
  print(ans)
solve()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


def main():
    s = input()
    # 判定をシンプルにするため，'BC'を'D'と置き換える
    # ループを扱いやすくするため，リストを反転させる
    mod_s = list(s.replace('BC', 'D'))[::-1]
    d_count = 0
    ans = 0

    # 文字列にBCが存在する必要がある
    # 操作をよく見ると，BCの左側にあるAを右側に移動させていることと同じ
    # BCが出現してから，
    #   1. Aが現れたときはBCを飛び越えた回数を答えに加算
    #   2. BCが現れたら，BCを管理する変数のカウントを1増やす
    #   3. BかCが単独で現れたら，BCを管理する変数のカウントをリセット
    for si in mod_s:
        if si == 'D':
            d_count += 1
        elif si == 'A':
            ans += d_count
        else:
            d_count = 0

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

s = list(input())
ls = len(s)
p = 0
status = 0
a = 0
ans = 0
while p < ls:
    if status == 0:
        if s[p] == "A":
            status = 1
            a = 1

    elif status == 1:
        if s[p] == "A":
            a += 1
        elif s[p] == "B":
            status = 2
        else:
            status = 0
            a = 0

    elif status == 2:
        if s[p] == "C":
            ans += a
            status = 1

        elif s[p] == "A":
            status = 1
            a = 1
        elif s[p] == "B":
            status = 0
    p += 1

print(ans)

Submission status: Accepted

Solution code:
s=input().replace("BC","X").replace("B","Y").replace("C","Y")
ans=0
for t in s.split("Y"):
	cnt=t.count("X")
	for c in t:
		if c=="A":
			ans+=cnt
		else:
			cnt-=1
print(ans)

Submission status: Accepted

Solution code:
import re
s = input()
s_ = s.replace("BC", "D")
group = re.findall(r"[AD]+", s_)
ans = 0
for grp in group:
    a = 0
    for g in grp:
        if g=="A":
            a += 1
        if g=="D":
            ans += a
print(ans)

Submission status: Accepted

Solution code:
s = input().rstrip()
n = len(s)
count_a = 0
count_bc = 0
res = 0
i = 0
while i < n:
    if s[i] == 'A':
        count_a += 1
        i += 1
    elif s[i] == 'B':
        if count_a == 0:
            i += 1
            continue
        if i + 1 == n:
            break
        if i + 1 < n and s[i + 1] != 'C':
            count_a = 0
            i += 1
            continue
        while i + 1 < n and s[i:i + 2] == 'BC':
            count_bc += 1
            i += 2
        res += count_a * count_bc
        count_bc = 0
    else:
        count_a = 0
        i += 1
print(res)

Submission status: Accepted

Solution code:
s=input()
s=s+"D"+"D"
i=0
lists=[]
add=""
while i<len(s):
    if s[i]=="A":
        add+="A"
        i+=1
    elif s[i]=="B"and s[i+1]=="C":
        i+=2
        add+="X"
    else:
        i+=1
        if add: 
            lists.append(add)
            add=""
        else:
            continue
cnt=0
for some in lists:
    somes=list(some)
    nums=len(some)
    if nums==1:
        continue
    elif nums>=2:
        emp=0
        point=0
        for k in range(nums):
            if somes[k]=="A":
                point+=1
            elif somes[k]=="X":
                emp+=point
        cnt+=emp
print(cnt)

Submission status: Accepted

Solution code:
# AGC034B - ABC
def main():
    # "X" ("BC") comes on left in a section separated by "B" or "C"
    # -> each "X" need to pass through all "A" on the left (cur)
    S = input().rstrip().replace("BC", "X")
    ans, cur = 0, 0
    for i in S:
        if i == "A":
            cur += 1
        elif i == "X":
            ans += cur
        else:  # end of subsequence
            cur = 0
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#%%
s = list(input())
i = 0
ss = ''

while True:
    if i <= len(s) - 2:
        if s[i] == 'B' and s[i+1] == 'C':
            ss += 'D'
            i += 2
        else:
            ss += s[i]
            i += 1          
    else:
        ss += s[i]
        i += 1
    if i >= len(s):
        break
#print(ss)

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

#%%

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
s=list(input().replace("BC","Z"))[::-1]
ans=0

def seisan(list):
    count=0
    N=len(list)-1
    for index,content in enumerate(list):
        if content=="A":
            count+=(N-index)
            N-=1
    return count

temp=[]
while s:
    this=s.pop(-1)
    if this=="B" or this=="C":
        ans+=seisan(temp)
        temp.clear()
    else:
        temp.append(this)

print(ans+seisan(temp))
#ちょくだいさん連投ゆるして

Submission status: Accepted

Solution code:
S = list(input().replace("BC", "D"))
l = []
ans = 0
a_cnt = 1
d_cnt = 1
for i in range(len(S)-1):
    if (S[i] == "A" and S[i + 1] == "D"):
        ans += a_cnt
        S[i] = "D"
        S[i + 1] = "A"
    else:
        if(S[i] == "A" and S[i+1] == "A"):
            a_cnt += 1
        else:
            a_cnt = 1

print(ans)

Submission status: Accepted

Solution code:
si = list(input())
s = []
for i in range(len(si)):
    if si[i] == 'A':
        s.append('A')
    elif si[i] == 'B':
        if i < len(si) - 1 and si[i+1] == 'C':
            s.append('B')
        else:
            s.append('X')
    elif si[i] == 'C':
        if i > 0 and si[i-1] == 'B':
            pass
        else:
            s.append('X')

result = 0
ac = 0
for i in range(len(s)):
    if s[i] == 'A':
        if i < len(s) - 1 and s[i+1] == 'B':
            result += ac + 1
            s[i+1] = 'A'
        else:
            ac += 1
    else:
        ac = 0

print(result)

Submission status: Accepted

Solution code:
S=input()

S=S.replace("BC","D")
T=[0]*len(S)
#print(S)

for i in range(len(S)):
  if S[i]=="A":
    T[i]=T[i-1]+1
  elif S[i]=="D":
    T[i]=T[i-1]
  else:
    T[i]=0
#print(T)

ans=0
for i in range(len(S)):
  if S[i]=="D":
    ans+=T[i]
print(ans)

Submission status: Accepted

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

def main():
    S = input().strip()
    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)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import re
s = input()
s2 = s.replace("BC", "D")
ss = re.split("B|C", s2)
#print(ss)
r = 0
for s in ss:
  n = 0
  for c in s:
    if c == "A":
      n += 1
    if c == "D":
      r += n
print(r)

Submission status: Accepted

Solution code:
S = input()

S = S.replace("BC", "D")

cnt_A = 0
ans = 0

"""
ABC -> BCA の処理は、BCとAwo入れ替えてAを右に送ると考えると理解しやすかった
ans = Aを何回右に送ることができるか
BCがあると、今あるAをそのBCの右に送ることができる
"""
for c in S:
    if c == "A":
        cnt_A += 1
    elif c == "D":
        ans += cnt_A
    else:
        # BBとかCBとかでAのカウントをリセット
        cnt_A = 0
        
print(ans)

Submission status: Accepted

Solution code:
S = input()
T = ""
N = len(S)
flag = 0
for i in range(N):
  if flag == 1:
    flag = 0
    continue
  elif S[i:i+2] == "BC":
    T += "D"
    flag = 1
  else:
    T += S[i]

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

Submission status: Accepted

Solution code:
import sys
import heapq
import bisect

mod = 10**9+7
dd = ((-1,0),(1,0),(0,-1),(0,1))

def I(): return(int(sys.stdin.readline()))
def LI(): return([int(x) for x in sys.stdin.readline().split()])
def S(): return(sys.stdin.readline()[:-1])
def IR(n): return([I() for _ in range(n)])

def GCD(a,b):
    while b!=0:
        a,b = b,a%b
    return a

def LCM(a,b):
    return a * b // GCD(a,b)

def Eratosthenes(N):
    r = [True]*(N+1)
    r[0] = False
    r[1] = False
    i = 2
    while i*i<=N:
        if r[i]: 
            j = i
            while i*j<=N:
                prime[i*j]=False
                j+=1
        i+=1
    return(r)

def main():
    s = S()
    N = len(s)
    
    ca = 0
    ans = 0
    i = 0
    while i<N:
        if s[i] == "A":
            ca += 1
            i += 1
        elif i<N-1 and s[i:i+2] == "BC":
            ans += ca
            i += 2
        else:
            ca = 0
            i += 1
    return(ans)
    





if __name__ == "__main__":
    print(main())

Submission status: Accepted

Solution code:
S = input()
N = len(S)
T = ""
flag = 0
ans = 0
for i in range(N-1):
  if flag == 1:
    flag = 0
    continue
  if S[i:i+2] == "BC":
    T += "D"
    flag = 1
  else:
    T += S[i]
M = len(T)
count = 0
for i in range(M):
  if T[i] == "A":
    count += 1
  elif T[i] == "D":
    ans += count
  else:
    count = 0
print(ans)

Submission status: Accepted

Solution code:
s = input()
s = s.replace("BC", "D")
ans = 0
a = 0
d = 0
a_bool = False
for i in range(len(s)):
    if not a_bool:
        if s[i] == "A":
            a += 1
            a_bool = True
        else:
            continue
    elif a_bool:
        if s[i] == "D":
            ans += a
        elif s[i] == "A":
            a += 1
        else:
            a_bool = False
            a = 0
            d = 0
print(ans)

Submission status: Accepted

Solution code:
#https://atcoder.jp/contests/agc034/submissions/5781329
S = input()
ans = 0
a = 0
i = 0
while (i < len(S)):
  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)

Submission status: Accepted

Solution code:
s=input()
t=""
i=0
while i<len(s):
    if s[i:i+2]=="BC":
        t+="T"
        i+=2
    else:
        t+=s[i]
        i+=1
ans=0
Acnt=0
for i in t:
    if i=="A":
        Acnt+=1
    elif i=="T":
        ans+=Acnt
    else:
        Acnt=0
print(ans)

Submission status: Accepted

Solution code:
s = input()[::-1].replace('CB', 'x')
# print(s)

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


print(ans)

Submission status: Accepted

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

ans = 0
for s in S:
    leftA = 0
    for i, t in enumerate(s[:: -1]):
        if t == 'A':
            ans += max(0, i - leftA)
            leftA += 1

print(ans)

Submission status: Accepted

Solution code:
def main():
    S = input().replace("BC","D")
    ans = count = 0
    for i in S:
        if i == "A":
            count += 1
        elif i == "D":
            ans += count
        else:
            count = 0

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



s = S()
ans = 0
i = len(s) - 1
a_cnt = 0
bc_cnt = 0
while i >= 0:
    if s[i-1:i+1] == 'BC':
        i -= 2
        bc_cnt += 1
    elif s[i] == 'A':
        i -= 1
        a_cnt += 1
        ans += bc_cnt
    else:
        a_cnt = bc_cnt = 0
        i -= 1




print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#AGC34 B

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
n = len(s)
t = ''
i = 0
while i < n-1:
    if s[i:i+2] == 'BC':
        t += 'D'
        i += 2
    else:
        t += s[i]
        i += 1
m = len(t)
ans = 0
a,d = 0,0
for i in range(m):
    if t[i] == 'A':
        a += 1
    elif t[i] == 'D':
        ans += a
    else:
        a,d = 0,0
print(ans)

Submission status: Accepted

Solution code:
s = input()

count = 0
block = 0
i = len(s) - 1
while i >= 0 :
    if s[i-1] == "B" and s[i] == "C":
        block += 1
        i -= 1
    elif s[i] == "A":
        count += block
    else:
        block = 0
    i -= 1
    
print(count)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
def count_inv(arr):
    left = 0
    ans = 0
    for i in range(len(arr)):
        if arr[i] == 1:
            left += 1
        else:
            ans += left
    return ans

temp = []
ind = 0
ans = 0
while True:
    if ind == n:
        ans += count_inv(temp)
        break
    c = s[ind]
    if c == "A":
        temp.append(1)
        ind += 1
        continue
    elif c == "B":
        if ind == n-1:
            ans += count_inv(temp)
            break
        if s[ind+1] == "C":
            temp.append(0)
            ind += 2
            continue
        else:
            ans += count_inv(temp)
            temp = []
            ind += 1
            continue
    else:
        ind += 1
        ans += count_inv(temp)
        temp = []
        continue


print(ans)

Submission status: Accepted

Solution code:
S = input()
idx = 0
a_cnt = 0
cnt = 0
len_s = len(S)
while idx < len_s:
  if S[idx:idx+3] == 'ABC':
    cnt += 1 + a_cnt
    idx += 3
    a_cnt += 1
    bc_cnt = 0
    while idx < len(S):
      if S[idx:idx+2] == 'BC':
        cnt += a_cnt
        idx += 2
      else:
        break
  else:
    if S[idx] == 'A':
      a_cnt += 1
    else:
      a_cnt = 0
    idx += 1
print(cnt)

Submission status: Accepted

Solution code:
def main():
    S = input()
    li = []
    li_append = li.append
    is_A = False
    now_state = 0
    for ind,s in enumerate(S):
        if(is_A):
            if(now_state==1):
                now_state = 0
                continue
            else:
                if(s=='A'):
                    li[-1].append(0)
                elif(S[ind:ind+2]=='BC'):
                    li[-1][-1] += 1
                    now_state = 1
                else:
                    is_A = False
        elif(s=='A'):
            is_A = True
            now_state = 0
            li_append([0])
    cnt = 0
    for i in li:
        cnt_b = sum(i)
        for j in i:
            cnt += cnt_b
            cnt_b -= j
            
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    S = input().replace("BC", "D")

    ans = a = 0
    for s in S:
        if s == "A":
            a += 1
        elif s == "D":
            ans += a
        else:
            a = 0

    print(ans)

main()

Submission status: Accepted

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

ans = a = 0
for s in S:
    if s == "A":
        a += 1
    elif s == "D":
        ans += a
    else:
        a = 0

print(ans)

Submission status: Accepted

Solution code:
# AGC034B - ABC
def main():
    S = input().rstrip().replace("BC", "X")
    ans, cur = 0, 0
    for i in S:
        if i == "A":
            cur += 1
        elif i == "X":
            ans += cur
        else:
            cur = 0
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
S = input()
N = len(S)
i = 0
T = []
while i <= N-2:
    if S[i] == 'B' and S[i+1] == 'C':
        T.append('D')
        i += 1
    else:
        T.append(S[i])
    i += 1

N = len(T)
ans = 0
l = 0
while l < N:

    if T[l] == 'B' or T[l] == 'C':
        l += 1
        continue
    
    r = l
    tmp = []
    while r < N and (T[r] == 'A' or T[r] == 'D'):
        tmp.append(T[r])
        r += 1
    
    M = len(tmp)
    D_count = [0]*(M+1)
    for i in range(M-1, -1, -1):
        D_count[i] = D_count[i+1]
        if tmp[i] == 'D':
            D_count[i] += 1
    
    for i in range(M):
        if tmp[i] == 'A':
            ans += D_count[i]
    
    if r == N:
        break
    else:
        l = r+1

print(ans)

Submission status: Accepted

Solution code:
S = input()
N = len(S)
i = 0
T = []
while i <= N-2:
    if S[i] == 'B' and S[i+1] == 'C':
        T.append('D')
        i += 1
    else:
        T.append(S[i])
    i += 1

T = "".join(T)

N = len(T)
ans = 0
l = 0
while l < N:

    if T[l] == 'B' or T[l] == 'C':
        l += 1
        continue
    
    r = l
    tmp = []
    while r < N and (T[r] == 'A' or T[r] == 'D'):
        tmp.append(T[r])
        r += 1
    
    M = len(tmp)
    D_count = [0]*(M+1)
    for i in range(M-1, -1, -1):
        D_count[i] = D_count[i+1]
        if tmp[i] == 'D':
            D_count[i] += 1
    
    for i in range(M):
        if tmp[i] == 'A':
            ans += D_count[i]
    
    if r == N:
        break
    else:
        l = r+1

print(ans)

Submission status: Accepted

Solution code:
s = input().replace("BC", "D")
n = len(s)
ans = 0
l = r = 0
while l < n:
    if s[l] != 'A':
        l += 1
        continue
    r = l + 1
    a = 1
    while r < n:
        if s[r] == 'A':
            a += 1
            r += 1
        elif s[r] == 'D':
            ans += a
            r += 1
        else:
            break
    l = r
print(ans)

Submission status: Accepted

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

i = N-1
ret = 0
BC_count = 0
while i >= 0:
    prev = i-1
    if prev < 0:
        if s[i] == 'A':
            ret += BC_count
            
        break
        
    
    if s[i] == 'A':
        ret += BC_count
        if s[prev] == 'B':
            BC_count = 0
    elif s[i]=='C':
        if s[prev]=='B':
            BC_count += 1
        else:
            BC_count = 0
    elif s[i]=='B':
        if s[prev]=='B':
            BC_count = 0

    i-= 1


print(ret)

Submission status: Accepted

Solution code:
s = input()
arr = list()

i = 0
buf = ''
while i < len(s):
    if s[i] == 'A':
        if buf:
            arr.append(buf)
            buf = ''
        arr.append('A')
        i += 1
    elif s[i: i + 2] == 'BC':
        if buf:
            arr.append(buf)
            buf = ''
        arr.append('BC')
        i += 2
    else:
        buf += s[i]
        i += 1
if buf:
    arr.append(buf)

cnt = 0
stack = 0
for e in reversed(arr):
    if e == 'BC':
        stack += 1
    elif e == 'A':
        cnt += stack
    else:
        stack = 0
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

cnt = 0

S = S.replace("BC", "X")
S = S.replace("B", " ")
S = S.replace("C", " ")

arr = S.split()

for elem in arr:
    i = 0

    for char in elem:
        if char == "A":
            i += 1
        else:
            cnt += i

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = str(input())
d = s.replace("BC", "D")

count = 0
count_a = 0
for i,c in enumerate(d):
    if c == "A":
        count_a += 1
    elif c == "D":
        count += count_a
    else:
        count_a = 0
print(count)

Submission status: Accepted

Solution code:
sentence = input()
slist = sentence.split("BC")
res = 0
a = 0
for l in slist:
  if ("B" in l) or ("C" in l) :
    l = l.replace("C", "B")
    al = l.split("B")
    a = len(al[-1])
    res += a
  else:
    a += len(l)
    res += a
else:
  res -= a
print(res)

Submission status: Accepted

Solution code:
s=input()+"v"
n=len(s)
p=0
r=0
c=0
while(1):
    if c>=n:
        break
    if s[0]=="A":
        p+=1
        s=s[1:]
        c+=1
    elif s[:2]=="BC":
        s=s[2:]
        c+=2
        r+=p
    else:
        s=s[1:]
        c+=1
        p=0
print(r)

Submission status: Accepted

Solution code:
s = input()
ss = s.split("BC")
ans = 0
a = 0
for abaca in ss:
    if ("B" in abaca) or ("C" in abaca) :
        ababa = abaca.replace("C", "B")
        a_a_a = ababa.split("B")
        a = len(a_a_a[-1])
        ans += a
    else :
        a += len(abaca)
        ans += a
else :
    ans -= a
print(ans)

Submission status: Accepted

Solution code:
S = input()
N = len(S)

a = 0
ans = 0
nowB = False
for i in range(N):
    if S[i] == 'A':
        if nowB:
            a = 0
        a += 1
        nowB = False
    elif S[i] == 'B':
        if nowB:
            a = 0
        nowB = True
    else:
        if nowB:
            ans += a
            nowB = False
        else:
            a = 0
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
#kenken

import sys
tmp = input()
limit = len(tmp)

i=0
numa=0
total=0
while(i<limit):
	if(tmp[i]=="A"):
		numa+=1
		i+=1
	elif(i+1==limit):
		break
	elif(tmp[i]=="B")and(tmp[i+1]=="C"):
		total+=numa
		i+=2
	else:
		numa=0
		i+=1

#print(tmp)
#print(limit)
print(total)

Submission status: Accepted

Solution code:
s = input()
s = s.replace('BC', 'D')
ans = 0
x = 0

#AとDだけでできた部分を考える(B,Cを挟む場合x=0とすることでreset)
#Aが出てくるたび、そのAより右にあるDは、Aを超える操作を挟むので、試行回数が増える。
for i in range(len(s)):
  if s[i] == 'A': 
    x +=1
  elif s[i] == 'D':
    ans += x
  else:
    x =0
    
print(ans)

Submission status: Accepted

Solution code:
s = input()
s = s.replace("BC", "D")


temp = 0
ans = 0
for i in s:
    if i == "A":
        temp += 1
    elif i == "D":
        ans += temp
    elif i == "B" or i == "C":
        temp = 0
        
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
s = input()

ans = 0
x = 0
index = 0

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

print(ans)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

S = input()
sum = 0
sum_a = 0
expect = 'B'
for i in range(len(S)):
    #print(i, S[i], expect, sum)
    if S[i] == 'A':
        if expect == 'C':
            sum_a = 0
        sum_a += 1
        expect = 'B'
    elif S[i] == expect and expect == 'C':
        sum += sum_a
        expect = 'B'
    elif S[i] == expect and expect == 'B':
        expect = 'C'
    else:
        sum_a = 0
        expect = 'B'

print(sum)

Submission status: Accepted

Solution code:
s=input()
l=[]
i=0
while i < len(s):
    if i<len(s)-1:
        if s[i]=='B' and s[i+1]=='C':
            l.append('D')
            i+=2
        else:
            l.append(s[i])
            i+=1
    else:
        l.append(s[i])
        i+=1
n=len(l)
ca=0
count=0
for i in range(n):
    if l[i]=='A':
        ca+=1
    elif l[i]=='D':
        count+=ca
    else:
        ca=0
print(count)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
A_cnt = 0
for s in S:
    if s == 'A':
        A_cnt += 1
    elif s == 'X':
        ans += A_cnt
    else:
        A_cnt = 0

print(ans)

Submission status: Accepted

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

count = 0
ans = 0

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:
S = input()
S = S.replace("BC","X")
count = 0
cntA = 0
for c in S:
    if c == "A":
        cntA += 1
    elif c == "X":
        count += cntA
    else:
        cntA = 0
print(count)