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:
import sys
import re
sys.setrecursionlimit(10 ** 7)


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def SI(): return input()


def main():
    S = SI()
    ans = 0
    while(1):
        a = S.find("ABC")
        if a == -1:
            break
        ans += 1
        i = 1
        aa = 0
        while(S[a-i] == 'A' and a-i >= 0):
            ans += 1
            i += 1
            aa += 1
        S = S[a+3:]
        bc = 0
        while(S[:2] == "BC"):
            ans += 1
            S = S[2:]
            bc += 1
        ans += min(aa, bc)
        S = "A" + S
    print(ans)


main()

Submission status: Wrong Answer

Solution code:
#B問題
s = list(str(input()))
slen = len(s)
Anum = 0
cflag = 0
ans = 0
for i in range(slen):
    if s[i] == "A":
        if cflag == 0:
            Anum+=1
        else:
            Anum = 1
            cflag = 1
    elif s[i] == "B":
        if i > 0:
            if s[i-1] == "A":
                cflag = 1
            else:
                Anum = 0
                cflag = 0
    else:
        if cflag == 1:
            ans+=Anum
            s[i] = "A"
            cflag = 0
        else:
            Anum = 0
            
print(ans)

Submission status: Wrong Answer

Solution code:
S=list(input())
l = len(S)
i = 0
j = -1
ans = 0
while i<l:
    if j==-1 and S[i] == "A":
        j=i
        i+=1
    elif j>=0 and S[i] == "A":
        i+=1
    elif j>=0:
        if len(S[i:i+2])==2 and S[i] == "B" and S[i+1] == "C":
            S[j] = "B"
            S[j+1] = "C"
            S[i] = "A"
            S[i+1] = "A"
            ans += i-j
            i = j
            j = -1
        else:
            j = -1
            i+=1
    else:
        i+=1
print(ans)

Submission status: Wrong Answer

Solution code:
S=input()
N=len(S)
i=0
ans=0
d=0

p=""
while i<N:
  if S[i]=="A":
    d+=1
  elif S[i]=="B":
    b=1
    if p=="B":
      d=0
  else:
    if p=="B":
      ans+=d
    elif p=="C":
      d=0
      
  p=S[i]
  i+=1
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
c = 0
while 'ABC' in s:
  if 'ABCABC' in s:
    s = s.replace('ABCABC', 'BCBCAA')
    c += 3
  elif 'AABC' in s:
    s = s.replace('AABC', 'BCAA')
    c += 2
  elif 'ABC' in s:
    s = s.replace('ABC', 'BCA')
    c += 1

Submission status: Wrong Answer

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


def solve(s: str):

    res = 0

    s = list(s)
    for i in range(len(s)):
        if s[i:i+3] == ["A","B","C"]:
            ai = -1
            for j in range(i-1,-1,-1):
                if s[j] == "A":
                    ai = j 
                else:
                    break
            if ai > 0:
                s[ai]   = "B"
                s[ai+1] = "C"
                s[ai+2] = "A"

                res += 1
                for k in range(ai+3,i+3):
                    s[k] = "A"
                    res += 1
            else:
                s[i]   = "B"
                s[i+1] = "C"
                s[i+2] = "A"
                res += 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:
s = input()

Amemo = 0
result = 0
A = False
B = False
C = False
BC = False
for c in s:
    if c == 'A':
        A = True
        B = False
        C = False
        BC = False
        Amemo += 1
    elif c == 'B':
        if A:
            A = False
            B = True
            C = False
            BC = False
        elif C:
            A = False
            B = False
            C = False
            BC = True
        else:
            Amemo = 0
            A = False
            B = False
            C = False
            BC = False
    elif c == 'C':
        if B:
            C = True
            result += Amemo
            A = False
            B = False
            BC = False
            Amemo = 1
        elif BC:
            result += 1
            A = False
            B = False
            C = True
            BC = False
        else:
            A = False
            B = False
            C = False
            BC = False
print(result)

Submission status: Wrong Answer

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

ans = 0
flag = 0
ABCflag = 0

i = 0
while i < N-2:

    if S[i]+S[i+1]+S[i+2] == 'ABC':
        ans += 1
        if flag:
            ans += flag
        if ABCflag:
            ans += ABCflag
        i += 2
        ABCflag += 1

    elif S[i] == 'A':
        flag += 1

    else:
        flag = 0
        if S[i]+S[i+1] == 'BC':
            if ABCflag:
                ans += 1
            i += 1
        else:
            ABCflag = 0
    i += 1

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
ans = 0
cnt_a = 0
change = False
abc = ''
for i in s:
  if i == 'A':
    cnt_a += 1
  elif i == 'B' and cnt_a > 0:
    abc = 'B'
  elif i == 'C' and cnt_a > 0 and abc == 'B':
    ans += cnt_a
    abc = 'C'
  else:
    cnt_a = 0
print(ans)

Submission status: Wrong Answer

Solution code:
s = list(input())
cnt = 0
for i in range(len(s) - 2):
    if s[i:i + 3] == ["A", "B", "C"]:
        s[i:i + 3] = ["B", "C", "A"]
        cnt += 1
    #print(i)

for i in range(len(s) - 1, 1, -1):
    if s[i - 2:i + 1] == ["A", "B", "C"]:
        s[i - 2:i + 1] = ["B", "C", "A"]
        cnt += 1
    #print(i)

print(cnt)

Submission status: Wrong Answer

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


# 'A' ならば aの個数を +1
# 'BC'ならば、変換の個数 に +a
# 'BB'なら aを0
# 'C' なら　aを0

def f(S):
    a = 0
    n = 0
    b = False

    for c in S:
        if c == 'A':
            a += 1
            b = False

        elif c == 'B':
            if b:
                a = 0
            else:
                b = True
                
        else:
            if b:
                n += a
                b = False
            else:
                a = 0
                
    return n


def main():
    S = input()

    print(f(S))
 


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#B問題
s = list(str(input()))
slen = len(s)
Anum = 0
cflag = 0
ans = 0
for i in range(slen):
    if s[i] == "A":
        if cflag == 0:
            Anum+=1
        else:
            Anum = 1
            cflag = 1
    elif s[i] == "B":
        if i > 0:
            if s[i-1] == "A":
                cflag = 1
            else:
                Anum = 0
    else:
        if cflag == 1:
            ans+=Anum
            s[i] = "A"
            
            cflag = 0
        else:
            Anum = 0
            
print(ans)

Submission status: Wrong Answer

Solution code:

s = input()
#print(s)
#print(s.count("ABC"))
cnt = 0
while ("ABC" in s):
    idx = s.find("ABC")
    s = s[idx:]
    cnt += s.count("ABC")
    s = s.replace("ABC", "BCA")

print(cnt)

Submission status: Wrong Answer

Solution code:
s = input()
counter = 0
n = s.find('BC')
while n != -1:
    k = 1
    while k <= n and s[n-k] == 'A':
        k += 1
    a_num = k-1
    counter += a_num
    s = s[:n] + s[n+2:]
    while True:
        n_new = s.find('BC')
        if n_new == -1:
            n = -1
            break
        elif n_new == n:
            counter += a_num
            s = s[:n] + s[n+2:]
        else:
            if s[n:n_new].count('A') == n_new-n:
                a_num += (n_new-n)
                counter += a_num
                n = n_new
                s = s[:n] + s[n+2:]
            else:
                n = n_new
                break
print(counter)

Submission status: Wrong Answer

Solution code:
S = input()

preS = ''

a_cnt = 0
bc_cnt = 0
ans = 0

for i, v in enumerate(S):
  if preS == 'A':
    if v == 'C':
      a_cnt = 0
      bc_cnt = 0
  elif preS == 'B':
    if v == 'C':
      bc_cnt += 1
    else:
      a_cnt = 0
      bc_cnt = 0      
  elif preS == 'C':
    if v == 'A' and a_cnt > 0 and bc_cnt > 0:
      ans += a_cnt * bc_cnt
      bc_cnt = 0      
    elif v != 'B':
      ans += a_cnt * bc_cnt
      a_cnt = 0
      bc_cnt = 0
  if v == 'A':
    a_cnt += 1

  preS = v
else:
  ans += a_cnt * bc_cnt
print(ans)

Submission status: Wrong Answer

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

concurrent_BC_cnt = 0
old1 = ""
cnt = 0
for tmp in (reversed(s)):
	if tmp == "A":
		cnt += concurrent_BC_cnt
		# if "A" not update old1
	else:
		if tmp == "B" and old1 == "C":
			concurrent_BC_cnt += 1
		elif tmp == "C" and old1 == "B":
			pass
		else:
			concurrent_BC_cnt = 0
			
		old1=tmp
	
print(cnt)

Submission status: Wrong Answer

Solution code:
s=input()
ad=1
cnt=0

while s.count("ABC")!=0:
        s=s.replace("ABC","BCA")
        cnt+=ad

print(cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np
words = lambda t : list(map(t, input().split()))

str = input()
s = [c for c in str]
total = 0
for i in range(len(s)):
    #print(s)
    if s[i] == 'A':
        cnta = 0
        cntbc = 0
        j = i
        for _ in range(i,len(s)):
            #print(j, s[j])
            if s[j] == 'A':
                cnta += 1
                j+=1
            else:
                break
        k = j
        for _ in range(j, len(s)-1):
            #print(k, s[k], s[k+1])
            if s[k] == 'B' and s[k+1] == 'C':
                cntbc += 1
                k += 2
            else:
                break
            if k >= len(s)-1:
                break
        if cnta > 0 and cntbc > 0:
            total += cnta + cntbc - 1
            x = i
            #print(cnta, cntbc)
            for _ in range(cntbc):
                s[x] = 'B'
                s[x+1] = 'C'
                x += 2
            for _ in range(cnta):
                s[x] = 'A'
                x += 1
print(total)

Submission status: Wrong Answer

Solution code:
s = input()

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

Submission status: Wrong Answer

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

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

print(co)

Submission status: Wrong Answer

Solution code:
S = input()
ans = 0
bc = 0
for i in range(len(S) + 1):

    if S[len(S) - i - 2 : len(S) - i] == 'BC':
        bc += 1
    elif S[len(S) - i - 2 : len(S) - i] == 'BB' or S[len(S) - i - 2 : len(S) - i] == 'CC':
        bc = 0
    if len(S) - i - 2 >= 0 and S[len(S) - i - 2] == 'A':
        ans += bc
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
ans = 0

while len(S) >= 3:
    ids = []
    for i in range(len(S)-2):
        if S[i:i+3] == 'ABC':
            ids.append(i)
    seq = 1
    pi = -999
    rep = []
    for i in ids:
        if i - pi == 3:
            seq += 1
        else:
            ans += seq*(seq+1)//2
            rep.append((i,i+3*seq))
            seq = 1
        pi = i

    if not rep: break
    for a,b in reversed(rep):
        S = S[:a] + 'BCA' + S[b:]

print(ans)

Submission status: Wrong Answer

Solution code:
import re
s = input()
ans = 0
for v in re.finditer('(ABC|BCA)+', s):
    sub = s[v.start():v.end()]
    total = len(sub) // 3
    abc_num = sub.count('ABC')
    ans += total * (total - 1) // 2 + abc_num
    
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

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

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

print(score)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import numpy as np
from functools import lru_cache
import time

def main(): 
    if True:
        S = np.asarray(list(str(input())))
    else:
        pass

    count = 0
    Acount = 0
    ABC = 0
    for i in range(S.size):
        if (S[i] == "A"):
            ABC = 1
            Acount += 1
        elif(ABC == 1) & (S[i] == "B"):
            ABC += 1
        elif(ABC == 2) & (S[i] == "C"):
            count += Acount
            ABC = 1
        else:
            Acount = 0
            ABC = 0
       #print(S[i],ABC,Acount)

    print(count)
if __name__ =='__main__':
    main()

Submission status: Wrong Answer

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

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

print(co)

Submission status: Wrong Answer

Solution code:
s=input()
a=0
r=0
for i in range(len(s)-1):
  if s[i]=="A":
    a=a+1
    if s[i+1]=="C":
      a=0
  elif s[i]=="B":
    if s[i+1]=="C":
      r=r+a
    else:
      a=0
print(r)

Submission status: Wrong Answer

Solution code:
import sys
import re
sys.setrecursionlimit(10 ** 7)


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def SI(): return input()


def main():
    S = SI()
    ans = 0
    while(1):
        a = S.find("ABC")
        if a == -1:
            break
        ans += 1
        i = 1
        while(S[a-i] == 'A' and a-i >= 0):
            ans += 1
            i += 1
        if len(S) == a+3:
            break
        S = S[a+3:]
        while(S[:2] == "BC"):
            ans += 1
            S = S[2:]
        S = "A" + S

    print(ans)


main()

Submission status: Wrong Answer

Solution code:
s = input()

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

Submission status: Wrong Answer

Solution code:
def solve():
    s = input()
    ans = 0
    x = 0 #どこまで完成しているか
    a = 0 #連続するAの数
    n = len(s)
    for i in range(n):
        c = s[i]
        if x == 0:
            if c == 'A':
                x = 1
                a = 1
            continue
        if x == 1:
            if c == 'A':
                a += 1
            if c == 'B':
                x = 2
            if c == 'C':
                x = 0
                a = 0
            continue
        if x == 2:
            if c == 'A':
                x = 1
                a = 1
            if c == 'B':
                x = 0
                a = 0
            if c == 'C':
                x = 1
                ans += a
                a = 1
    return ans
print(solve())

Submission status: Wrong Answer

Solution code:
S = str(input())
ans = 0

while True:
    m = S.find('ABC')
    #print(S)
    #print(m)
    if(m == -1):
        break
    else:    
      ans += 1  
      i = m-1
      while(S[i] == 'A'):
        if(i<0):
          break
        else:
          ans += 1
          i -= 1

      S = 'A' + S[m+3:len(S)]
      #print(S)
        

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

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

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

print(score)

Submission status: Wrong Answer

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

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

print(co)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#B問題
s = list(str(input()))
slen = len(s)
Anum = 0
cflag = 0
ans = 0
for i in range(slen):
    if s[i] == "A":
        Anum+=1
    elif s[i] == "B":
        if i > 0:
            if s[i-1] == "A":
                cflag = 1
            else:
                Anum = 0
    else:
        if cflag == 1:
            ans+=Anum
            s[i] = "A"
            
            cflag = 0
        else:
            Anum = 0
            
print(ans)

Submission status: Wrong Answer

Solution code:

s = list(input())

cnt = 0
flag = True

while flag:
    cnt_flag = False
    for i in range(len(s) - 4):
        if s[i] == "A" and s[i + 1] == "B" and s[i + 2] == "C":
            if s[i + 3] == "B" and s[i + 4] == "C":
                s[i : i + 5] = ["B", "C", "B", "C", "A"]
                cnt += 2
                cnt_flag = True
    for i in range(1, len(s) - 3):
        if s[i] == "A" and s[i + 1] == "B" and s[i + 2] == "C":
            if s[i - 1] == "A":
                s[i - 1 : i + 3] = ["B", "C", "A", "A"]
                cnt += 2
                cnt_flag = True
    if not cnt_flag:
        flag = False
for i in range(len(s) - 2):
    if s[i] == "A" and s[i + 1] == "B" and s[i + 2] == "C":
        s[i : i + 3] = ["B", "C", "A"]
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
# from sys import exit
# A, B, C = [int(n) for n in input().split()]
# N = int(input())
# a = [int(input()) for _ in range(N)]
S = list(str(input()))
L = len(S)
# print(S)
ans = 0
for i in range(L-1):
    if S[i] == "B" and S[i+1] == "C":
        cur = i-1
        while(S[cur] == "A" and cur != -1):
            S[cur+2] = "A"
            cur-=1
            ans+=1
        # print(S)
# print(S)
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
ans = 0
while "ABC" in s:
    index = s.find("ABC")
    s ="A"+ s[index+3:]
    ans += 1
print(ans)

Submission status: Wrong Answer

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

while True:
    x = re.search('(ABC|BCA)+', s)
    if x is None:
        break
    sub = s[x.start():x.end()]
    total = len(sub) // 3
    abc_num = sub.count('ABC')
    ans += total * (total - 1) // 2 + abc_num
    
    s = s[:x.start()] + s[x.end():]
    
print(ans)

Submission status: Wrong Answer

Solution code:

S = input()
start_A = -1
i = 0
N = len(S)
ans = 0
while i < N:
	if S[i] == 'A':
		start_A = i
		i += 1
		while i < N and S[i] == 'A':
			i += 1
		n = i - start_A
		c = 0
		while i < N:
			if S[i:i+2] == "BC": 
				c += 1
				i += 2
			else:
				break
		ans += n*c
		S = S[:start_A] + S[start_A+n:start_A+n+c*2] + S[start_A:start_A+n] + S[start_A+n+c*2:]
		i = start_A + n + c*2
	i += 1
i = 0
while i < N:
	if S[i] == 'A':
		start_A = i
		i += 1
		while i < N and S[i] == 'A':
			i += 1
		n = i - start_A
		c = 0
		while i < N:
			if S[i:i+2] == "BC": 
				c += 1
				i += 2
			else:
				break
		ans += n*c
		S = S[:start_A] + S[start_A+n:start_A+n+c*2] + S[start_A:start_A+n] + S[start_A+n+c*2:]
		i = start_A + n + c*2
	i += 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import re
sys.setrecursionlimit(10 ** 7)


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def SI(): return input()


def main():
    S = SI()
    ans = 0
    now = 0
    while(1):
        a = S.find("ABC")
        if a == -1:
            break
        ans += 1
        i = 1
        while(S[a-i] == 'A'):
            ans += 1
            i += 1
        S = S[a+3:]
        while(S[:2] == "BC"):
            ans += 1
            S = S[2:]
        S = "A" + S
        now = a + i

    print(ans)


main()

Submission status: Wrong Answer

Solution code:
s = input()

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

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

print(cnt)

Submission status: Wrong Answer

Solution code:
S = input()

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

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

print(score)

Submission status: Wrong Answer

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

cnt = 0
flag = True

while flag:
    cnt_flag = False
    for i in range(len(s) - 4):
        if s[i] == "A" and s[i + 1] == "B" and s[i + 2] == "C":
            if s[i + 3] == "B" and s[i + 4] == "C":
                s[i : i + 5] = ["B", "C", "B", "C", "A"]
                cnt += 2
                cnt_flag = True
    for i in range(1, len(s) - 3):
        if s[i] == "A" and s[i + 1] == "B" and s[i + 2] == "C":
            if s[i - 1] == "A":
                s[i - 1 : i + 3] = ["B", "C", "A", "A"]
                cnt += 2
                cnt_flag = True
    if not cnt_flag:
        flag = False
for i in range(len(s) - 2):
    if s[i] == "A" and s[i + 1] == "B" and s[i + 2] == "C":
        s[i : i + 3] = ["B", "C", "A"]
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import numpy as np
from functools import lru_cache
import time

def main(): 
    if True:
        S = np.asarray(list(str(input())))
    else:
        pass

    count = 0
    Acount = 0
    ABC = 0
    for i in range(S.size):
        if S[i] == "A":
            Acount += 1
        
        if (S[i] == "A"):
            ABC = 1
        elif(ABC == 1) & (S[i] == "B"):
            ABC += 1
        elif(ABC == 2) & (S[i] == "C"):
            count += Acount
            #print(Acount)
            #Acount = Acount
            ABC = 1
        else:
            if S[i] != "A":
                Acount = 0
            ABC = 0
       #print(S[i],ABC,Acount)

    print(count)
if __name__ =='__main__':
    main()

Submission status: Wrong Answer

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

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

print(co)

Submission status: Wrong Answer

Solution code:
s=list(input())
n=len(s)
i,a=0,0
for i in range(n-2):
  if s[i]+s[i+1]+s[i+2]=="ABC":
    s[i+2]="A"
    a+=1
    if i!=0:
      j=1
      while s[i-j]=="A":a+=1;j+=1
print(a)

Submission status: Wrong Answer

Solution code:
S = input()
ans = 0
bc = 0
c_flag = 0
for i in range(len(S) - 1, -1, -1):
    if S[i] == "A" and c_flag == 0:
        ans += bc
    elif S[i] == "A" and c_flag == 1:
        bc = 0
        c_flag = 0
    elif S[i] == "C" and c_flag == 0:
        c_flag = 1
    elif S[i] == "B" and c_flag == 1:
        bc += 1
        c_flag = 0
    else:
        bc = 0
        c_flag = 0
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
counter = 0
n = s.find('BC')
while n != -1:
    k = 1
    while k <= n and s[n-k] == 'A':
        counter += 1
        k += 1
    a_num = k-1
    s = s[:n] + s[n+2:]
    while True:
        n_new = s.find('BC')
        if n_new == -1:
            n = -1
            break
        elif n_new == n:
            counter += a_num
            s = s[:n] + s[n+2:]
        else:
            if s[n-a_num:n_new].count('A') == a_num+n_new-n:
                a_num += (n_new-n)
                counter += a_num
                n = n_new
                s = s[:n] + s[n+2:]
            else:
                n = n_new
                break
print(counter)

Submission status: Wrong Answer

Solution code:
S = [ord(c) for c in list(input())]
length = len(S)

count = 0
i = 0
if length > 2:
    while i > length - 3:
        if S[i] == 65:
            if S[i + 1] == 66:
                if S[i + 2] == 67:
                    S[i] = 66
                    S[i + 1] = 67
                    S[i + 2] = 65
                    count += 1
                    i = max(i - 2, 0)
print(count)

Submission status: Wrong Answer

Solution code:
S = str(input())
ans = 0

while True:
    m = S.find('ABC')
    #print(S)
    #print(m)
    if(m == -1):
        break
    else:    
      ans += 1
      i = m-1
      while (S[i] == 'A'):
        if(i == -1 or i == 0):
          break
        else:
          ans +=1
          i -= i
      if(m >= len(S)-3):
        S = 'A'
      else:
      	S = 'A' + S[m+3:len(S)]
      #print(S)
        

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=input()
ans=0
a=0
if len(s)<3:
  print(0)
else:
  c0=ord(s[2])-ord("A") #A0
  c1=ord(s[1])-ord("A") #B1
  c2=ord(s[0])-ord("A") #C2
  for i in range(2,len(s)):
    c0=ord(s[i])-ord("A")
    if c2==0 and c1==1 and c0==2:
      #print(1+a)
      ans+=1+a
      c2=1
      c1=2
      c0=0
    if c2==0:
      a+=1
    else: #c2!=0
      a=0
    c2=c1
    c1=c0
  print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import numpy as np
from functools import lru_cache
import time

def main(): 
    if True:
        S = np.asarray(list(str(input())))
    else:
        pass

    count = 0
    Acount = 0
    ABC = 0
    for i in range(S.size):
        if S[i] == "A":
            Acount += 1
        
        if (S[i] == "A"):
            ABC = 1
        elif(ABC == 1) & (S[i] == "B"):
            ABC += 1
        elif(ABC == 2) & (S[i] == "C"):
            count += Acount
            #print(Acount)
            Acount = 1
            ABC = 1
        else:
            if S[i] != "A":
                Acount = 0
            ABC = 0
       #print(S[i],ABC,Acount)

    print(count)
if __name__ =='__main__':
    main()

Submission status: Wrong Answer

Solution code:
S = str(input())
ans = 0

while True:
    m = S.find('ABC')
    #print(S)
    #print(m)
    ans += 1
    if(m == -1):
        break
    else:      
      i = m-1
      while (S[i] == 'A'):
        if(i == -1 or i == 0):
          break
        else:
          ans +=1
          i -= i
      if(m >= len(S)-3):
        S = 'A'
      else:
      	S = 'A' + S[m+3:len(S)]
      #print(S)
        

print(ans)

Submission status: Wrong Answer

Solution code:

s = input()
stock_b = 0
stock_c = 0
stock_bc = 0
state = 0
ans = 0

for i in range(len(s)):
    if s[-1-i] == "C":
        if state == 1:
            stock_b = 0
            stock_c = 0
            stock_bc = 0

        stock_c += 1
        state = 1

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

        stock_b += 1
        state = 0

    elif s[-1-i] == "A":
        ans += stock_bc

print(ans)

Submission status: Wrong Answer

Solution code:
s = list(input())
a_cnt = 0
b_flag = 0
total = 0

for c in s:
#  print(c, a_cnt, b_flag)
  if c == "A":
    if b_flag:
      b_flag = 0
      a_cnt = 1
    else:
      a_cnt += 1
  elif c == "B":
    if a_cnt:
      b_flag = 1
    elif b_flag:
      b_flag = 0
      a_cnt = 0
  elif c == "C":
    if b_flag:
      total += a_cnt
      b_flag = 0
    else:
      a_cnt = 0
      
print(total)