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: Wrong Answer

Solution code:
S=input()
s=[0]*len(S)
c=0
abc=0
ans=0
for i in range(len(S)):
    if S[i]=='A':
        if abc==2:
            c=0
            abc=0
        else:
            c+=1
            abc=1
    elif S[i]=='B':
        if abc==1:
            abc=2
        else:
            c=0
            abc=0
    else:
        if abc==2:
            ans+=c
            abc=1
        else:
            c=0
            abc=0
print(ans)

Submission status: Wrong Answer

Solution code:
import copy
S = input()
#print(S)
S2 = S.replace("BC", "D")
#print(S2)
flag = 0
countnum = 0
start = -1
count = 0
for i in range(len(S2)):
    #print(S2[i])
    if S2[i] == "A" or S2[i] == "D":
        if flag == 0:
            start = i
        countnum += 1
        flag = 1
    elif flag == 1:
        for j in range(start + countnum - 1, start - 1, -1):
            #print(S2[j], j)
            if S2[j] == "D":
                for k in range(j, start - 1, -1):
                    if S2[k] == "A":
                        count += 1
        flag = 0
        countnum = 0
    #print(S3)
    #print(s4)
if countnum != 0:
    for i in range(start + countnum - 1, start - 1, -1):
        print(S2[i], i)
        if S2[i] == "D":
            for j in range(i, start - 1, -1):
                if S2[j] == "A":
                    count += 1
#print(S3)

print(count)

Submission status: Wrong Answer

Solution code:

s = input()
#print(s)
#print(s.count("ABC"))
cnt = 0

s = s.replace("ABC", "E")
s = s.replace("BC", "D")

d_cnt = 0
cnt = 0

for i in reversed(s):
    if i == 'E':
        cnt += d_cnt+1
    elif i == 'D':
        d_cnt += 1
    else:
        d_cnt =0

print(cnt)

Submission status: Wrong Answer

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

s = input()
s = s.replace('BC', 'D')
s = re.split('[BC]', s)
res = 0

print(s)


for kk in s:
  if not kk:
    continue
  while 'AD' in kk:
    res += kk.count('AD')
    kk = kk.replace('AD', 'DA')
    
print(res)

Submission status: Wrong Answer

Solution code:
text = list(input())

count = 0

for j in range(30):
    i = 0
    while len(text) > i+2:
        if text[i] == "A" and text[i+1] == "B" and text[i+2] == "C":
            text[i],text[i+1],text[i+2] = text[i+1],text[i+2],text[i]
            count += 1
        i += 1
    
print(count)

Submission status: Wrong Answer

Solution code:
text = list(input())

count = 0

for j in range(10):
    i = 0
    while len(text) > i+2:
        if text[i] == "A" and text[i+1] == "B" and text[i+2] == "C":
            text[i],text[i+1],text[i+2] = text[i+1],text[i+2],text[i]
            count += 1
        i += 1
    
print(count)

Submission status: Wrong Answer

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

ans = 0

for i in range(len(s)-2):
    if s[i] == "A" and s[i+1] == "B" and s[i+2] == "C":
        s[i] = "B"
        s[i+1] = "C"
        s[i+2] = "A"
        ans = ans+1
        j=i-1
        while(s[j] == "A"):
            s[j+2] = "A"
            ans = ans+1
            j=j-1
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
ans = 0
pre_chance = 0
pos_chance = 0

for i in range(len(s)-1):
    if s[i] == "A":
        if s[i:i+2] == "AA":
            pre_chance += 1
            pos_chance = 0
        elif s[i:i+3] == "ABC":
            ans += pre_chance + 1
            pre_chance = 0
        else:
            pre_chance = 0
            pos_chance = 0
    elif s[i] == "B":
        if s[i:i+2] == "BC" and pos_chance == 1:
            ans += 1
            pre_chance = 0
        else:
            pre_chance = 0
            pos_chance = 0
    elif s[i] == "C":
        if s[i-1:i+2] == "BCA" and pos_chance == 1:
            pre_chance += 1
            pos_chance = 1
        elif s[i-1:i+1] == "BC" and pos_chance == 1:
            pos_chance = 1
        elif s[i-2:i+2] == "ABCB" or s[i-2:i+4] == "ABCABC":
            pos_chance = 1
        else:
            pre_chance = 0
            pos_chance = 0

print(ans)

Submission status: Wrong Answer

Solution code:
s=raw_input()
l=len(s)

str=""
i=0
while i<l:
	if s[i]=="A":
		str+="A"
		i+=1
	elif i+1<l and s[i]=="B" and s[i+1]=="C":
		str+="D"
		i+=2
	else:
		str+="X"
		i+=1

LSUM=[]
for i,x in enumerate(str):
	if i==0:
		if x=="A": LSUM.append(1)
		else: LSUM.append(1)
	else:
		if x=="A": LSUM.append(LSUM[-1]+1)
		elif x=="D": LSUM.append(LSUM[-1])
		elif x=="X": LSUM.append(0)


ans=0
for i,x in enumerate(str):
	if x=="D":
		ans+=LSUM[i]

print ans

Submission status: Wrong Answer

Solution code:
s = input()
num_a = 0
num_ab = 0
val = 0
for i in range(len(s)):
    if s[i] == 'A':
        num_a += 1
    elif s[i] == 'B':
        num_ab = num_a
        num_a = 0
    else:
        val += num_ab
        num_a = num_ab
        num_ab = 0
print(val)

Submission status: Wrong Answer

Solution code:
S = input().strip()
i = len(S)
ans = 0
while i >= 0:
    if S[i-2:i] == 'BC':
        # seek before
        j = i - 3
        bc = 0
        a = 0
        while j >= 0:
            if S[j] == 'A':
                a += 1
                j -= 1
                i -= 1
            elif S[j-1:j+1] == 'BC':
                bc += 1
                j -= 2
                i -= 2
            else:
                break
        ans = ans + (bc + a)
    else:
        i -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
s = list(input())

ans = 0
i = 0
while i < len(s) - 3:
    #print(s)
    if s[i] == 'A':
        i += 1
        count = 1
        while i < len(s) - 1:
            if s[i] == 'A':
                count += 1
                i += 1
            else:
                if s[i] == 'B' and s[i+1] == 'C':
                    ans += count
                    s[i] = 'C'
                    s[i+1] = 'A'
                i += 1
                break
    else:
        i += 1

print(ans)

Submission status: Wrong Answer

Solution code:
s = str(input())

retn = 0

loop = True
while(loop):

    x = s.find("BC")
    if (x == -1):
        break

    if (x != 0):
        bb = s.rfind("B",0,x)
        cc = s.rfind("C",0,x)

        if (cc > bb):
            bb = cc
        retn += x - bb - 1
        s = "A" + s[x+2:]
    else:
        s = s[x+2:]

print(retn)

Submission status: Wrong Answer

Solution code:
s = str(input())

retn = 0

loop = True
while(loop):

    x = s.find("BC")
    if (x == -1):
        break

    if (x != 0):
        bb = s.rfind("B",0,x)
        cc = s.rfind("C",0,x)

        if (cc > bb):
            bb = cc
        retn += x - bb - 1

    s = "A" + s[x+2:]

print(retn)

Submission status: Wrong Answer

Solution code:
s=input()
s=s.replace('BC','D')
s=list(s)
count=0
 
def change():
  global count
  flg=False
  for i in range(len(s)-2):
    if s[i]=='A' and s[i+1]=='D':
      s[i]='D'
      s[i+1]='A'
      count+=1
      flg=True
      
  return flg
      
while(change()):
  pass
 
print(count)

Submission status: Wrong Answer

Solution code:
s = str(input())

retn = 0

loop = True
while(loop):
    #####################
    #print(s)

    x = s.find("ABC")
    if (x == -1):
        break
    retn += 1

    #####################
    #print("x" ,x)

    if (x != 0):
        bb = s.rfind("B",0,x)
        cc = s.rfind("C",0,x)
        #####################
        #print(bb,cc)
        #print(s[0])

#        if ((bb != -1) or (cc != -1)):
        if (cc > bb):
            bb = cc
        retn += x - bb - 1
 #       else:



    #####################
    #print("r" ,retn)

    s = "A" + s[x+3:]

print(retn)

Submission status: Wrong Answer

Solution code:
s=input()
s=list(s)
count=0
count2=0
hozon=-1

for i in range(0,len(s)-2):
  if(i==hozon or count2==0) and s[i]=='A' and s[i+1]=='B' and s[i+2]=='C':
    hozon=i+3
    count2+=1
  elif hozon==i:
    for j in range(1,count2+1):
      count+=j
    count2=0
    hozon=-1
    
for j in range(1,count2+1):
  count+=j
      
print(count)
'''
def change():
  global count
  flg=False
  for i in range(len(s)-2):
    if s[i]=='A' and s[i+1]=='B' and s[i+2]=='C':
      s[i]='B'
      s[i+1]='C'
      s[i+2]='A'
      count+=1
      flg=True
      
  return flg
      
while(change()):
  pass

print(count)'''

Submission status: Wrong Answer

Solution code:
from collections import Counter as D, defaultdict as dd
from math import factorial as ft, ceil as aron
from fractions import gcd as pg 
from bisect import insort as ins, bisect_left as bl, bisect_right as br
import sys

#sys.stdin=open("./testfile1.py","r")
raw_input=sys.stdin.readline

f1=lambda : map(int,raw_input().split())
f2=lambda : map(int,list(raw_input()))
f3=lambda : int(raw_input())
f4=lambda : raw_input().rstrip()
def main():
	st=[]
	s=f4()
	n1=0
	ans=0
	na=0
	t=0
	#print s
	for i in s:
		
		n1+=1
		st.append(i)

		#print st,na,t
		if n1>=3 and st[n1-3:]==['A','B','C']:
			#print 123, na-1, ans+na
			na-=1
			st[-1]="A"
			st[-3]="B"
			st[-2]="C"
			ans+=1+na
			na+=1
			t=-1

		if i=="A": 
			na+=1
			t=-1
		elif t==2:
			na=0
		t+=1
	#print st 		
	print ans


if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
s = input()

# search A
listA = []
listBC = ""
ibc = 0
for c in s:
    if c == "A":
        listA.append(ibc)
    else:
        listBC += c
        ibc += 1
listA.reverse()

cnt = 0
for a in listA:
    while listBC[a : a + 2] == "BC":
        a += 2
        cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
s = input()

# search A
listA = []
for i in range(len(s) - 1, -1, -1):
    if s[i] == "A":
        listA.append(i)

cnt = 0
for a in listA:
    s = s[: a] + s[a + 1 :]
    while s[a : a + 2] == "BC":
        a += 2
        cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys;
import string;
sys.setrecursionlimit(20000) # 再起呼び出しの最大数をセット

import copy
import itertools

from functools import lru_cache
#@lru_cache(maxsize = None)

# 整数の入力
#n = int(input())

# スペース区切りの整数の入力
#a = [x for x in map(int, input().split())]
#n, a, b, c, d = map(int, input().split())
#print("sp", n, q, file=sys.stderr)

# 改行区切りの整数の入力
#a = []
#for x in range(m):
#  a.append([int(x) for x in input().split()])
#p = [int(x) for x in input().split()]

# 文字列の入力
s = input()

# 出力
#print("{} {}".format(a+b+c, s))
#a.sort()
#print(set(a), file=sys.stderr)
#print(len(set(a)))

#cache = dict()

abc = 'ABC'
bca = 'BCA'

# BCAAAABCABCCCABC
# BCBCAAAAABCCCABC

# AABCBCABC
# BCAABC
# BCBCAA

import re

def doit(s):
  res = 0
  a = 0
  preb = False
  abc = False
  for x in s:
    c = x == 'C'
    if c:
      if preb:
        abc = a > 0
        if abc:
          res += a
          print("res", res, file=sys.stderr)
      else:
        a = 0
      preb = False
      continue

    b = x == 'B'
    aa = x == 'A'
    if aa:
      a += 1
    elif preb:
      a = 0
    preb = b
  return res

def doit0(s):
  res = 0
  #s.re('A+BC')
  while True:
    s2 = s.replace(abc, bca, 1)
    if s == s2:
      break
    s = s2
    res += 1
  return res

#print(doit([0] * 4))
#doit(s)
try:
  print(doit(s))
    
except Exception as e:
  print("e", e, file=sys.stderr)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys;
import string;
sys.setrecursionlimit(20000) # 再起呼び出しの最大数をセット

import copy
import itertools

from functools import lru_cache
#@lru_cache(maxsize = None)

# 整数の入力
#n = int(input())

# スペース区切りの整数の入力
#a = [x for x in map(int, input().split())]
#n, a, b, c, d = map(int, input().split())
#print("sp", n, q, file=sys.stderr)

# 改行区切りの整数の入力
#a = []
#for x in range(m):
#  a.append([int(x) for x in input().split()])
#p = [int(x) for x in input().split()]

# 文字列の入力
s = input()

# 出力
#print("{} {}".format(a+b+c, s))
#a.sort()
#print(set(a), file=sys.stderr)
#print(len(set(a)))

#cache = dict()

abc = 'ABC'
bca = 'BCA'

# BCAAAABCABCCCABC
# BCBCAAAAABCCCABC

# AABCBCABC
# BCAABC
# BCBCAA

import re

def doit(s):
  res = 0
  a = 0
  preb = False
  abc = False
  for x in s:
    c = x == 'C'
    if c:
      if b:
        abc = a > 0
        if abc:
          res += a
          print("res", res, file=sys.stderr)
      else:
        a = 0
      preb = False
      continue

    b = x == 'B'
    aa = x == 'A'
    if aa:
      a += 1
    elif preb:
      a = 0
    preb = b
  return res

def doit0(s):
  res = 0
  #s.re('A+BC')
  while True:
    s2 = s.replace(abc, bca, 1)
    if s == s2:
      break
    s = s2
    res += 1
  return res

#print(doit([0] * 4))
#doit(s)
try:
  print(doit(s))
    
except Exception as e:
  print("e", e, file=sys.stderr)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(100000)

def intinput(): return map(int,input().split())

s=input()
s=s.replace("BC","D")
print(s)
acnt=0
dcnt=0
ans=0
for i in s[::-1]:
    if i=="D":
        ans+=acnt*dcnt
        acnt=0
        dcnt+=1
    elif i=="A":
        acnt+=1
    else:
        ans += acnt * dcnt
        acnt=0
        dcnt=0
ans+=acnt*dcnt
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
s.replace("BC","D")
c = 0
while True:
    s = s.replace("AD","DA", 1)
    c+=1
    if s.count('AD') == 0:
        break
print(c)

Submission status: Wrong Answer

Solution code:
s = input()
s.replace("BC","D")
c = 0
while True:
    c_tmp = c
    c += s.count('AD')
    s = s.replace("AD","DA")
    if c == c_tmp:
        break
print(c)

Submission status: Wrong Answer

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

flag = 0
# 0:CCCC 1:AAAA 2:BCBC
ans = 0
count = 0
i = -1
while i < l:
    i += 1
    if i >= l and flag == 2:
        ans += count
        break
    elif i >= l:
        break
    elif s[i] == 'A' and flag == 0:
        flag = 1
        continue
    elif s[i] == 'A' and flag == 1:
        count += 1
        continue
    elif s[i] == 'A':
        flag = 1
        ans += count
        count = 1
        continue
    elif s[i:i+2] == 'BC' and flag == 1:
        flag = 2
        ans += count+1
        count = 0
        i += 1
        continue
    elif s[i:i+2] == 'BC' and flag == 2:
        count += 1
        i += 1
        continue
    elif flag == 2:
        ans += count
    flag = 0
    count = 0
    
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
c = 0
while True:
    try:
        s = s.replace("ABC","BCA", 1)
        print(s)
        c+=1
    except:
        break
print(c)

Submission status: Wrong Answer

Solution code:
import re
s = input()
c = 0
while True:
    try:
        s = s.replace(re.search(r"ABC", s).group(),"BCA", 1)
        print(s)
        c+=1
    except:
        break
print(c)

Submission status: Wrong Answer

Solution code:
S=input()
n=S.count('A')
s=S.replace('BC','D')
ans=0
for i in range(n):
  k=s.rfind('A')
  b=s[k:].find('B')
  c=s[k:].find('C')
  if b==-1:
    b=1000000
  if c==-1:
    c=1000000
  ans+=min(b,c)-1
  s=s[:k]+s[k+1:]
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python

import sys
import re

s= sys.stdin.readline().strip()
s= s.replace("BC","D")
s= re.sub("[BC]+"," ",s).split()

t= 0
for seg in s:
    while True:
        i=seg.find("D")
        if i<=0: break
        a= len(seg[:i])
        if a==0: continue
        #
        d= 1
        for j in range(i+1,len(seg)):
            if seg[j]!="D": break
            d+= 1
        t+= a*d
        seg= ("A"*a) + seg[i+d:]
#
print( t )

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
s = input()

# search A
listABC = []
for i in range(len(s) - 2):
    if s[i:i+3] == "ABC":
        listABC.append(i)

cnt = len(listABC)
while len(listABC) > 0:
    #print("s={},listABC={}".format(s, listABC))
    for i in range(len(listABC)):
        s = s[:listABC[i]] + "BCA" + s[listABC[i] + 3:]

    newlist = []
    for i in range(len(listABC)):
        if i > 0:
            if s[listABC[i] - 1] == "A":
                if ((listABC[i] - 1) in newlist) == False:
                    cnt += 1
                    newlist.append(listABC[i] - 1)
        if i < len(s) - 4:
            if s[listABC[i] + 3 : listABC[i] + 5] == "BC":
                if ((listABC[i] + 2) in newlist) == False:
                    cnt += 1
                    newlist.append(listABC[i] + 2)
    listABC = newlist

print(cnt)

Submission status: Wrong Answer

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

sl = list(s)[::-1]
sll = []
i = 0
while i < n:
    if i == n-1:
        sll.append(sl[i])
        break
    if sl[i] == 'C' and sl[i+1] == 'B':
        sll.append('D')
        i += 2
    else:
        sll.append(sl[i])
        i += 1
n = len(sll)
ans = 0
for _ in range(5):
    id = 0
    while id < n:
        if id == n-1:
            break
        if sll[id] == 'D':
            now = id
            d = 0
            a = 0
            flag = True
            while True:
                if id == n:
                    break
                if flag:
                    if sll[id] == 'D':
                        d += 1
                        id += 1
                        continue
                    else:
                        flag = False
                        continue
                if not flag:
                    if sll[id] == 'A':
                        a += 1
                        id += 1
                        continue
                    else:
                        break
            if a == 0:
                id += 1
                continue
            for i in range(a):
                sll[now+i] = 'A'
            for i in range(d):
                sll[now+a+i] = 'D'
            ans += a*d
        else:
            id += 1

print(ans)

Submission status: Wrong Answer

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


S = str(input())
Sd = ""
l,r = 0,len(S)
while l < r-1:
  if S[l:l+2] == "BC":
    Sd += "D"
    l += 2
  else:
    Sd += S[l]
    l += 1


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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
s = input()
count = 0
a_stack = 0
b_flg = 0
for idx, char in enumerate(s):
    if char == "A":
        a_stack += 1
        b_flg = 0
    elif a_stack > 0 and char == "B":
        b_flg = 1
    elif a_stack > 0 and b_flg == 1 and char == "C":
        b_flg = 0
        count += a_stack
    else:
        a_stack = 0
        b_flg = 0
print(count)

Submission status: Wrong Answer

Solution code:
import re
S = input()
N1 = S.replace('A','0').replace('BC','1')
S_li = re.split('B|C',N1)

count = 0
for l in S_li:
    a = l.find('0')
    bc = l.rfind('1')
    if 0 <= a < bc:
        count += (bc-a)
        i=0
        while True:
            a = l[:bc].find('0',i)
            bc = l[:bc].rfind('1',i)
            if 0 <= a < bc:
                count += (bc-a)
                i = a+1
            else:
                break
print(str(count))

Submission status: Wrong Answer

Solution code:
import re

s=input()

#print(re.split('BB|CC|CB',s))

#print(s)

#s=s.replace("A","0")
s=s.replace("BC","1")
s=re.split('B|C|CB',s)


cnt=0
for i in s:
    
    start=0
    start=i.find("A")
    while start!=-1:
        
        
        if start<=len(i):
            cnt+=i[start:].count("1")
           
        start=i.find("0",start+1)
        
print(cnt)

Submission status: Wrong Answer

Solution code:
s = str(input())
cnt = 0
i = 0
while i <= len(s)-2:
    if s[i:i+2] == "BC":
        s = s[:i] + "D" +s[i+2]
    i += 1
a_cnt = 0
d_cnt = 0
for i in range(len(s)):
    if s[i] == "A":
        a_cnt += 1
    elif s[i] == "D":
        d_cnt += 1
    else:
        cnt += a_cnt * d_cnt
        a_cnt = 0
        d_cnt = 0
print(cnt)

Submission status: Wrong Answer

Solution code:
import re

s=input()

#print(re.split('BB|CC|CB',s))

#print(s)

s=s.replace("A","0")
s=s.replace("BC","1")
s=re.split('B|C|CB',s)


cnt=0
for i in s:
    
    start=0
    start=i.find("A")
    while start!=-1:
        
        
        if start<=len(i):
            cnt+=i[start:].count("1")
           
        start=i.find("0",start+1)
        
print(cnt)

Submission status: Wrong Answer

Solution code:
import re
S = input()
N1 = S.replace('A','0').replace('BC','1')
S_li = re.split('B|C',N1)

count = 0
for l in S_li:
    a = l.find('0')
    bc = l.rfind('1')
    if 0 <= a < bc:
        count += (bc-a)
        i=0
        j=0
        while True:
            i += a+1
            j = a+bc
            a = l[i:j].find('0')
            bc = l[i:j].rfind('1')
            if 0 <= a < bc:
                count += (bc-a)
            else:
                break
print(str(count))

Submission status: Wrong Answer

Solution code:
import re

s=input()

#print(re.split('BB|CC|CB',s))

#print(s)

#s=s.replace("A","0")
s=s.replace("BC","1")
s=re.split('B|C|CB',s)


cnt=0
for i in s:
    
    start=0
    start=i.find("A")
    while start!=-1:
        
        
        #if start<=len(i):
        cnt+=i[start:].count("1")
           
        start=i.find("0",start+1)
        
print(cnt)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
s = input()
count = 0
a_flg = 0
b_flg = 0
for idx, char in enumerate(s):
    if char == "A":
        a_flg = 1
    elif a_flg == 1 and char == "B":
        b_flg = 1
    elif a_flg == 1 and b_flg == 1 and char == "C":
        count += 1
    else:
        a_flg = 0
        b_flg = 0
print(count)

Submission status: Wrong Answer

Solution code:
s = input()
S = list(s)
 
abc = ['A','B','C']
bca = ['B','C','A']
bc = ['B','C']
ans = 0
i = 0
A = [0]*len(s)
while i < len(s)-2:
    if S[i] == 'A':
        if S[i+1:i+3] == bc:
            A[i] = 0
            ans += 1
            j = i-1
            while j >= 0 and A[j]:
                A[j] = 0
                ans += 1
                j -= 1
        else:
            A[i] = 1
    i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
S = list(s)
 
abc = ['A','B','C']
bca = ['B','C','A']
bc = ['B','C']
ans = 0
i = 0
A = [0]*len(s)
while i < len(s)-2:
    if S[i] == 'A':
        if S[i+1:i+3] == bc:
            A[i] = 0
            ans += 1
            j = i-1
            while j >= 0 and A[j]:
                A[j] = 0
                ans += 1
                j -= 1
            i += 2
        else:
            A[i] = 1
            i += 1
    else:
        i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 20 20:47:47 2019

@author: Owner
"""

# -*- coding: utf-8 -*-
"""
Created on Sat Apr 13 09:53:12 2019

@author: Owner
"""
import collections

#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)

    def get_size(self, x):
        """
        x が属するグループの要素数
        """
        x = self.find(x)
        return self.size[x]
    

"""
N, X = map(int, input().split())

x = list(map(int, input().split()))

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())

# 多次元配列の宣言（あとでintにすること。）（タプルにすること。）
dp = np.zeros((N+1, 4,4,4))
    
all(nstr.count(c) for c in '753')

# 複数配列を並び替え
ABT = zip(A, B, totAB)
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)

# 2進数のbit判定
(x >> i) & 1

# dp最小化問題
dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break
# 累積和
add = 1 # 問題によって決まる
res = 0
sums = [0]*(len(nums)+1)
for i in range(len(nums)):
    sums[i+1] = sums[i] + nums[i]
for i in range(0, len(nums), 2):
    left = i
    right = min(i+add, len(nums))
    tmp = sums[right] - sums[left]
    res = max(tmp, res)

#２分探索
li, ri = bisect.bisect_left(p_ac, l[i]-1), bisect.bisect_right(p_ac, r[i]-1)    

#ソート関数
org_list = [3, 1, 4, 5, 2]
new_list = sorted(org_list)
print(org_list)
print(new_list)
# [3, 1, 4, 5, 2]
# [1, 2, 3, 4, 5]

#Distance Transformation
    for h in range(0,H):
        for w in range(0,W):
            if h == 0 and w == 0:
                pass
            elif h == 0:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h-1][W-w]+1)
            elif w == 0:   
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1)
            else:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1, D[H-h-1][W-w]+1, D[H-h][W-w]+2)
            d_max = max(D[H-h-1][W-w-1], d_max)

"""



s = input()
def main(): 
    S = collections.deque(s)
    res = 0
    idx = "".join(list(S)).find("ABC")
    if idx == -1:
        return print(0)
    l_idx = [idx]
    while idx != -1:
        idx = "".join(list(S)).find("ABC", idx+1)
        if idx != -1:
            l_idx.append(idx)
        else:
            break
    
    for j, idx in enumerate(l_idx):
        cnt = 0
        res+=1
        for i in range(idx):
            if S[idx-(i+1)] == "A":
                res+=1
                cnt+=1
            else:
                break
        for i in range(idx+3):
            S.popleft()
        for i in range(cnt+1):
            S.appendleft("A") 
        for i in range(idx-cnt+2):
            S.appendleft("D")    
        #print("".join(list(S)))
        
    
    
    
    #print(res, l_idx)
    print(res)
                
                
                
            
            
                

    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = input()

s = s.replace('BC', 'D')
a_count = 0
count = 0
print(s)
for c in s:
    if c == 'A':
        a_count += 1
    elif c == 'D':
        count += a_count
    else:
        a_count = 0

print(count)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

def conv2num(c):
    if c == "A":
        return 1
    else:
        return 2

def solve(s: str):

    res = 0

    s = s.replace("BC","D")
    s = [ conv2num(c) for c in s ]
    i = 0
    endi = len(s) - 1
    while i < endi:
        if s[i] == 1 and s[i+1] == 2:
            ai = i
            for j in range(i-1,-1,-1):
                if s[j] == 1 and j >=0 :
                    ai = j 
                else:
                    break
            s[ai]   = 2
            s[ai+1] = 1
            res += 1

            st = ai+2
            ed = i +2
            if st != ed:
                for k in range(st,ed):
                    s[k] = 1
                    res += 1
            i += 1
        i += 1

    print(res)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    solve(s)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def snum(S):
    # bcの数
    origS = S[:]
    bccnt = 0
    i = 0
    bcIndex = []
    base = 0
    while "BC" in S[i:]:
        S = S[i:]
        bcIndex.append( S.find("BC")  + base)
        i = S.find("BC") + 2
        base += i
 
 
    aIndex = []
    i = 0
    base = 0
    S = origS[:]
    while "A" in S[i:]:    
        S = S[i:]
        aIndex.append(S.find("A") + base)
        i = S.find("A") + 1
        base += i
 
 
    ans = 0
    ai = 0
    bc = 0
    nokoriBC = len(bcIndex)
    nowA = 0
 
    subS = [0] * len(origS)
    for a in aIndex:
        subS[a] = 1
    for b in bcIndex:
        subS[b] = 2
 
    for i in range(len(origS)):
        if subS[i]  == 1:
            nowA += 1
        elif subS[i] == 2:
            ans += nowA * nokoriBC
            nowA = 0
            nokoriBC -= 1
            if (nokoriBC == 0): break
    return ans
    return (aIndex, bcIndex)
 
S = input()
pos = []
i = 0
while "CC"  in S[i:] or "BB" in S[i:] or "CB" in S[i:]:
    S = S[i:]
    # a = min( S.find("CC"), S.find("BB"))
    c = (S.find("CC"))
    b = S.find("BB")
    a = 0
    if ( c != -1 and b != -1) :
        a = min(b,c)
    elif b == -1:
        a = c
    else :
        a = b
 
    pos.append( S[i:a+1]  )
    i = a+2
pos.append(S[i:])
# print(kpos)
ans = 0
for p in pos:
    tmp = snum(p)
    ans += tmp
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import re
S = input()
N1 = S.replace('A','0').replace('BC','1')
S_li = re.split('B|C',N1)

count = 0
for l in S_li:
    while True:
        a = l.find('0')
        bc = l.rfind('1')
        if 0 < a < bc:
            count += (bc-a)
            l = l[a+1:bc]
        else:
            break

print(str(count))

Submission status: Wrong Answer

Solution code:
s = input()

count = 0
counta = 0
for i in range(len(s)):
    if s[i] == "A":
        counta += 1
    elif s[i] == "B":
        if s[i-1] == "B":
            counta = 0
    else:
        if s[i-1] == "B":
            count += counta
        else:
            counta = 0
print(count)

Submission status: Wrong Answer

Solution code:
S = str(input())

s = list()
s.append(2)
s.append(2)
s.append(2)

count= 0
i = 0

for i in range(len(s) -2):
        
    if(s[i]==0 and s[i+1]==1 and s[i+2] == 2):
        j = i
        while (s[j] == 0):
            count+= 1
            s[j+2] = 0
            j -= 1
            
        s[j+2] = 2

print(count)