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: Runtime Error

Solution code:
S=input()

i=0
T=[]
while i<len(S):

    if i+1<len(S) and S[i]+S[i+1]=="BC":
        T.append("D")
        i+=2
    else:
        T+=append(S[i])
        i+=1
count=0
m=0
Acount=0
#print(T)
for i in range(len(T)):
    if "A"==T[i]:
        Acount+=1
    elif "D"==T[i]:
        count+=Acount
    else:
        Acount=0



#print(T)
print(count)

Submission status: Runtime Error

Solution code:
S = input()
N = len(S)
a = 0
ans = 0
for i in range(N):
    if S[i] == 'A':
        a += 1
    elif S[i] == 'B':
        if S[i+1] == 'C':
            ans += a
        else:
            a = 0
    else:
        a = 0
print(ans)

Submission status: Runtime Error

Solution code:
S=list(input())
s=[]
for i in range(len(S)):
    if S[i] == "A":
        s.append("A")
    elif(S[i] == "B" and S[i+1] == "C"):
        s.append("D")
s=s+[""]
c=0
i=0
while(len(s)>i):
    if s[i]=="A" and s[i+1]=="D":
        s[i]="D"
        s[i+1]="A"
        i-=2
        c+=1
    i+=1

print(c)

Submission status: Runtime Error

Solution code:
s = list(input())

ans = 0
i = 0
if s[0] == 'A' and s[1] == 'B' and s[2] == 'C':
    s[0] = 'B'
    s[1] = 'C'
    s[2] = 'A'
    ans += 1
    i = 3

while i+2 < len(s):
    if s[i] == 'A' and s[i+1] == 'B' and s[i+2] == 'C':
        ans += 1
        s[i] = 'B'
        s[i+1] = 'C'
        s[i+2] = 'A'
        i -= 1
    else:
        i += 1

print(ans)

Submission status: Runtime Error

Solution code:
s = input()
if "BC" in s:
    s = s.replace("BC", "D")
else:
    print(0)
    quit()

pos = 0
str_len = len(s)
count = 0
seq_a = 0
seq_d = 0

while pos < str_len:
    if s[pos] == "A":
        while pos < str_len and s[pos] == "A":
            seq_a += 1
            pos += 1
        if s[pos] == "D":
            while pos < str_len and s[pos] == "D":
                seq_d += 1
                pos += 1
            count += seq_a * seq_d
            if pos < str_len and s[pos] != "A":
                seq_a = 0
            seq_d = 0
        else:
            pos += 1
            seq_a = 0
    else:
        pos += 1
        seq_a = 0

print(count)

Submission status: Runtime Error

Solution code:
s = input()
pos = 0
str_len = len(s)
count = 0
seq_a = 0
seq_d = 0

while pos < str_len:
    if s[pos] == "A":
        while pos < str_len and s[pos] == "A":
            seq_a += 1
            pos += 1
        if s[pos] == "D":
            while pos < str_len and s[pos] == "D":
                seq_d += 1
                pos += 1
            count += seq_a * seq_d
            if pos < str_len and s[pos] != "A":
                seq_a = 0
            seq_d = 0
        else:
            pos += 1
            seq_a = 0
    else:
        pos += 1
        seq_a = 0

print(count)

Submission status: Runtime Error

Solution code:
s = input()
pos = 0
str_len = len(s)
count = 0
seq_a = 0
seq_d = 0

# if str_len < 3:
#     print(count)
#     exit()

if "BC" in s:
    s = s.replace("BC", "D")
else:
    print(count)
    exit()

while pos < str_len:
    if s[pos] == "A":
        while pos < str_len and s[pos] == "A":
            seq_a += 1
            pos += 1
        if s[pos] == "D":
            while pos < str_len and s[pos] == "D":
                seq_d += 1
                pos += 1
            count += seq_a * seq_d
            if pos < str_len and s[pos] != "A":
                seq_a = 0
            seq_d = 0
        else:
            pos += 1
            seq_a = 0
    else:
        pos += 1
        seq_a = 0

print(count)

Submission status: Runtime Error

Solution code:
s = input()
pos = 0
str_len = len(s)
count = 0
seq_a = 0
seq_d = 0

if str_len < 3:
    print(count)
    exit()

if "BC" in s:
    s = s.replace("BC", "D")
else:
    print(count)
    exit()

while pos < str_len:
    if s[pos] == "A":
        while pos < str_len and s[pos] == "A":
            seq_a += 1
            pos += 1
        if s[pos] == "D":
            while pos < str_len and s[pos] == "D":
                seq_d += 1
                pos += 1
            count += seq_a * seq_d
            if pos < str_len and s[pos] != "A":
                seq_a = 0
            seq_d = 0
        else:
            pos += 1
            seq_a = 0
    else:
        pos += 1
        seq_a = 0

print(count)

Submission status: Runtime Error

Solution code:
s = input()
pos = 0
str_len = len(s)
count = 0
seq_a = 0
seq_d = 0

if len(s) < 3:
    print(0)
    quit()

if "BC" in s:
    s = s.replace("BC", "D")
else:
    print(0)
    quit()

while pos < str_len:
    if s[pos] == "A":
        while pos < str_len and s[pos] == "A":
            seq_a += 1
            pos += 1
        if s[pos] == "D":
            while pos < str_len and s[pos] == "D":
                seq_d += 1
                pos += 1
            count += seq_a * seq_d
            if pos < str_len and s[pos] != "A":
                seq_a = 0
            seq_d = 0
        else:
            pos += 1
            seq_a = 0
    else:
        pos += 1
        seq_a = 0

print(count)

Submission status: Runtime Error

Solution code:
s = input()
if "BC" in s:
    s = s.replace("BC", "D")
else:
    print(0)
    quit()
pos = 0
str_len = len(s)
count = 0
seq_a = 0
seq_d = 0

while pos < str_len:
    if s[pos] == "A":
        while pos < str_len and s[pos] == "A":
            seq_a += 1
            pos += 1
        if s[pos] == "D":
            while pos < str_len and s[pos] == "D":
                seq_d += 1
                pos += 1
            count += seq_a * seq_d
            if pos < str_len and s[pos] != "A":
                seq_a = 0
            seq_d = 0
        else:
            pos += 1
            seq_a = 0
    else:
        pos += 1
        seq_a = 0

print(count)

Submission status: Runtime Error

Solution code:
s = input()
s = list(s.replace("BC", "D"))
pos = 0
str_len = len(s)
count = 0
seq_a = 0
seq_d = 0

while pos < str_len:
    if s[pos] == "A":
        while pos < str_len and s[pos] == "A":
            seq_a += 1
            pos += 1
        if s[pos] == "D":
            while pos < str_len and s[pos] == "D":
                seq_d += 1
                pos += 1
            count += seq_a * seq_d
            if pos < str_len and s[pos] != "A":
                seq_a = 0
            seq_d = 0
        else:
            pos += 1
            seq_a = 0
    else:
        pos += 1
        seq_a = 0

print(count)

Submission status: Runtime Error

Solution code:
s = list(input())
pos = 0
str_len = len(s)
count = 0
state = 0

while pos < str_len:
    if state == 0:
        if s[pos] == "A":
            state = 1
        pos += 1
    elif state == 1:
        if s[pos] == "B":
            state = 2
        elif s[pos] == "A":
            state = 1
        else:
            state = 0
        pos += 1
    elif state == 2:
        if s[pos] == "C":
            s[pos-2:pos+1] = "BCA"
            pos -= 3
            if pos < 0:
                pos = 0
            count += 1
            print(s)
        elif s[pos] == "A":
            state = 1
            pos += 1
        else:
            state = 0
            pos += 1

print(count)

Submission status: Runtime Error

Solution code:
s = input()
pos = 0
cnt = 0
if len(s) < 3:
    print(0)
else:
    while(True):
        if s[pos:pos+3] == "ABC":
            s = s[:pos] + "BCA" + s[pos+3:]
            if pos > 0:
                pos -= 1
            cnt += 1
        else:
            if s[pos+1:pos+3] == "AB":
                pos += 1
            elif s[pos+2:pos+3] == "A":
                pos += 2
            else
                pos += 3
        if pos >= len(s)-2:
            break
    print(cnt)

Submission status: Runtime Error

Solution code:
s = list(input())
pos = 0
str_len = len(s)
count = 0
state = 0

while pos < str_len:
    if state == 0:
        if s[pos] == "A":
            state = 1
        pos += 1
    elif state == 1:
        if s[pos] == "B":
            state = 2
        elif s[pos] == "A":
            state = 1
        else:
            state = 0
        pos += 1
    elif state == 2:
        if s[pos] == "C":
            s[pos-2:pos+1] = "BCA"
            # pos -= 3
            # if pos < 0:
            #     pos = 0
            pos = 0
            count += 1
            print(s)
        else:
            pos += 1
        state = 0

print(count)

Submission status: Runtime Error

Solution code:
w=list(input())
now=0
num=len(w)
w.append(" ")
count=0
while now<num:
  if w[now]!="A":
    now+=1
  else:
    if w[now+1]!="B":
      now+=1
    else:
      if w[now+2]!="C":
        now+=1
      else:
        w[now]="B"
        w[now+1]="C"
        w[now+2]="A"
        count+=1
        back=now-1
        b=True
        while back>0 and b=True:
          if w[back]!="A":
            b=False
          else:
            w[back]="B"
            w[back+1]="C"
            w[back+2]="A"
            count+=1
            back-=1
print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    def checkABC(x):
        if s[x]=='A' and s[x+1]=='B' and s[x+2]=='C':
            s[x],s[x+1],s[x+2]='B','C','A'
            return True
        else:
            return False
    
    s=list(input())
    N=len(s)
    i=0
    ans=0
    while True:
        if i >= N-2:
            break
        if checkABC(i) == True:
            if i!=0 and s[i-1]=='A':
                i-=2
            else:
                i+=1
            ans+=1
        while True:
            i+=1
            if s[i] == 'A':
                break
    print(ans)
        
        

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
s = list(input())

i = 0
abc = list("ABC")

def roop(n): #n:現在地
  if n >= len(s)-2:
    return 0
  elif s[n:n+3] == abc:
    s[n] = "B"
    s[n+1] = "C"
    s[n+2] = "A"
    if n == 0: return roop(n+2)+1 
    return roop(n-1)+1
    # return roop(n-1)+1
  else:
    return roop(n+1)


print(roop(0))

Submission status: Runtime Error

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

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

while True:
    if i < 0 :
        i += 1
    elif len(s)-2 <= i:
        break
    else:
        if s[i] == 'A'
            if s[i+1] == 'B' and s[i+2] == 'C':
                ans += 1
                s[i], s[i+1], s[i+2] = 'B', 'C', 'A'
                i -= 1
            else:
                i += 1
        else:
            i += 1

print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
s=input()

temp=0
ans=0
while s:
    if len(s)>=3:
        if s[0]+s[1]+s[2]=='ABC':#ABCABCをBCBCAAに変換したい
            temp+=1
            del s[0:2]
            continue
    
    ans+=(temp*(temp+1))/2#上の清算をする
    temp=0
    
    s_chi=s.pop(0)
    if s_chi="A":#AABCをBCAAに変換したい
        if 
        temp+=1
    elif s_chi="B":
        if 
    elif s_chi="C":

Submission status: Runtime Error

Solution code:
s = list(input())

count = 0
for i in range(len(s) - 2):
    if s[i] == 'A' and s[i+1] == 'B' and s[i+2] == 'C':
        count += 1
        s[i] = 'B'
        s[i+1] = 'C'
        s[i+2] = 'A'


for i in reversed(range(len(s) - 2)):
    if s[i] == 'A' and s[i+1] == 'B' and s[i+2] == 'C':
        count += 1
        flag = True
    else:
        if flag and s[i] == 'A':
            count += 1
        else:
            flag = False
print(count)

Submission status: Runtime Error

Solution code:
import re
 
count = 0

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
  
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
  
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
            
 
def count_inversion(sequence):
    for i, p in enumerate(sequence):
        bit.add(p, 1)
        ans += i + 1 - sum(p)
    return ans
 
s = input()
s = s.replace("BC", "D")
s = re.split(r"[B-C]+", s)
 
while "" in s:
    s.remove("")
for x in s:
    count += count_inversion(list(x))
        
print(count)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
s=input()
count=0
i=len(s)-1

def counting(i,count,tentative):
    if s[i]=="C" and s[i-1]=="B":
        tentative=tentative+1
        while True:
            if i-2<0 or s[i-2]=="B":
                tentative=0
                i=i-3
                break
            elif s[i-2]=="A":
                count=count+tentative
                i=i-1
            else:
                i,count,tentative=counting(i-2,count,tentative)
    else:
        i=i-1
    return i,count,tentative

while i>1:
    i,count,tentative=counting(i,count,0)
print(count)

Submission status: Runtime Error

Solution code:
import sys
INPUT = sys.stdin.readline
 
def SINGLE_INT(): return int(INPUT())
def MULTIPLE_INT_LIST(): return list(map(int, INPUT().split()))
def MULTIPLE_INT_MAP(): return map(int, INPUT().split())
def SINGLE_STRING(): return INPUT()
def MULTIPLE_STRING(): return INPUT().split()

s = SINGLE_STRING()
s = list(s)

i = 0
ans=0

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

Submission status: Runtime Error

Solution code:
s = input()
counts = s.count("ABC")
s = s.replace("ABC","BCA")
tmp = s.count("ABC")
count += tmp 
while tmp != 0:
  s = s.replace("ABC","BCA")
  tmp = s.count("ABC")
  count += tmp
  
print(count)

Submission status: Runtime Error

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 ans

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s = input()

count = 0

while True:
  index = s.find("ABC")
  if index < 0:
    break
  s[index:index+3] = "BAC"
  count += 1

print(count)

Submission status: Runtime Error

Solution code:
string = input()

count = 0

while True:
  index = string.find("ABC")
  if index < 0:
    break
  string[index:index+3] = "BAC"
  count += 1

print(count)

Submission status: Runtime Error

Solution code:
string = input()

count = 0

while True:
  index = string.find("ABC")
  if index < 0:
    break
  string[index:index+3] = "BAC"

print(count)

Submission status: Runtime Error

Solution code:
s = input()
c = 0
def conv(s):
    if 'ABC' in s:
        global c
        c += s.count('ABC')
        return conv(s.replace('ABC', 'BCA'))
    else:
        return None
while conv(s):
    pass
print(c)

Submission status: Runtime Error

Solution code:
import sys
from copy import deepcopy
from math import inf

sys.setrecursionlimit(10 ** 6) 

def merge(num_array, left, mid, right):
    '''
    配列num_arrayとその配列の部分配列を表す変数left, mid, rightを引数とし、部分配列をソートする。
    leftは部分配列の先頭要素であるがrightは部分配列の末尾+1である。
    '''
    L = deepcopy(num_array[left:mid])
    R = deepcopy(num_array[mid:right])
    inversionCnt = 0

    remainL = len(L)

    L.append(inf)
    R.append(inf)    

    i = 0
    j = 0

    for k in range(left, right):
        if L[i] <= R[j]:
            num_array[k] = L[i]
            i += 1
            remainL -= 1
        else:
            num_array[k] = R[j]
            j += 1
            inversionCnt += remainL
    
    return inversionCnt

def SetnumberInversion(num_array, left, right, inversion_list):
    if left == right - 1:
        return
    
    mid = (left + right) // 2
    SetnumberInversion(num_array, left, mid, inversion_list)
    SetnumberInversion(num_array, mid, right, inversion_list)
    inversion_list.append(merge(num_array, left, mid, right))

def numberInversion(num_array):
    left = 0
    right = len(num_array)
    inversion_list = []

    SetnumberInversion(num_array, left, right, inversion_list)
    return (sum(inversion_list))
  
S = input()
S = S.replace("BC", "D")
S_list = S.split("B")
SS_list = []
for SS in S_list:
    SS_list.append(SS.split("C"))

allinversion = 0

for ss in SS_list:
    for s in ss:
        s = s.replace("D", "0")
        s = s.replace("A", "1")
        num_array = [int(num) for num in s]
        if s:
            allinversion += numberInversion(num_array)

print(allinversion)

Submission status: Runtime Error

Solution code:
from copy import deepcopy
from math import inf

def merge(num_array, left, mid, right):
    '''
    配列num_arrayとその配列の部分配列を表す変数left, mid, rightを引数とし、部分配列をソートする。
    leftは部分配列の先頭要素であるがrightは部分配列の末尾+1である。
    '''
    L = deepcopy(num_array[left:mid])
    R = deepcopy(num_array[mid:right])
    inversionCnt = 0

    remainL = len(L)

    L.append(inf)
    R.append(inf)    

    i = 0
    j = 0

    for k in range(left, right):
        if L[i] <= R[j]:
            num_array[k] = L[i]
            i += 1
            remainL -= 1
        else:
            num_array[k] = R[j]
            j += 1
            inversionCnt += remainL
    
    return inversionCnt

def SetnumberInversion(num_array, left, right, inversion_list):
    if left == right - 1:
        return
    
    mid = (left + right) // 2
    SetnumberInversion(num_array, left, mid, inversion_list)
    SetnumberInversion(num_array, mid, right, inversion_list)
    inversion_list.append(merge(num_array, left, mid, right))

def numberInversion(num_array):
    left = 0
    right = len(num_array)
    inversion_list = []

    SetnumberInversion(num_array, left, right, inversion_list)
    return (sum(inversion_list))
  
S = input()
S = S.replace("BC", "D")
S_list = S.split("B")
SS_list = []
for SS in S_list:
    SS_list.append(SS.split("C"))

allinversion = 0

for ss in SS_list:
    for s in ss:
        s = s.replace("D", "0")
        s = s.replace("A", "1")
        num_array = [int(num) for num in s]
        if s:
            allinversion += numberInversion(num_array)

print(allinversion)

Submission status: Runtime Error

Solution code:
from copy import deepcopy
from math import inf

def merge(num_array, left, mid, right):
    '''
    配列num_arrayとその配列の部分配列を表す変数left, mid, rightを引数とし、部分配列をソートする。
    leftは部分配列の先頭要素であるがrightは部分配列の末尾+1である。
    '''
    L = deepcopy(num_array[left:mid])
    R = deepcopy(num_array[mid:right])
    inversionCnt = 0

    remainL = len(L)

    L.append(inf)
    R.append(inf)    

    i = 0
    j = 0

    for k in range(left, right):
        if L[i] <= R[j]:
            num_array[k] = L[i]
            i += 1
            remainL -= 1
        else:
            num_array[k] = R[j]
            j += 1
            inversionCnt += remainL
    
    return inversionCnt

def SetnumberInversion(num_array, left, right, inversion_list):
    if left == right - 1:
        return
    
    mid = (left + right) // 2
    SetnumberInversion(num_array, left, mid, inversion_list)
    SetnumberInversion(num_array, mid, right, inversion_list)
    inversion_list.append(merge(num_array, left, mid, right))

def numberInversion(num_array):
    left = 0
    right = len(num_array)
    inversion_list = []

    SetnumberInversion(num_array, left, right, inversion_list)
    return (sum(inversion_list))
  
S = input()
S = S.replace("BC", "D")
S_list = S.split("B")
SS_list = []
for SS in S_list:
    SS_list.append(SS.split("C"))

allinversion = 0

for ss in SS_list:
    for s in ss:
        s = s.replace("D", "0")
        s = s.replace("A", "1")
        num_array = [int(num) for num in s]
        print(num_array)
        if s:
            allinversion += numberInversion(num_array)

print(allinversion)

Submission status: Runtime Error

Solution code:
s=input()
ans=0
while 'ABC' in str1:
    n=str1.count('ABC')
    ans+=n
    str1=str1.replace('ABC','BCA',n)
print(ans)

Submission status: Runtime Error

Solution code:
s=input()

count=0

while ('ABC' in s)==True:
    s=s.replace("ABC","BCA",1)
    print(s)
    count+=1
    
print(count)

Submission status: Runtime Error

Solution code:
# coding: utf-8
import os
import time
import re
import math

def main():
    s=input().replace("BC","D")
    max=0
    acount=0
    for a in len(s):
        if s[a]=='D':
            max+=acount
        elif s[a]=='A':
            acount+=1
        else:
            acount=0
    print(max)



start=time.time();
main()
#print(time.time()*1000-start*1000)

Submission status: Runtime Error

Solution code:
from functools import lru_cache


@lru_cache()
def findall(s,n):
    flag=s.find("ABC")
    if flag==-1:
        return []
    else:
        return [flag+n]+findall(s[3::],n+3)

@lru_cache()
def abc(s):
    index=findall(s,0)
    if len(index)==0:
        return 0
    retval=0
    for i in index:
        retval=max(retval,1+abc(s[:i:]+"BCA"+s[i+3::]))
    return retval

print(abc(input()))

Submission status: Runtime Error

Solution code:
import math
import numpy as np
import re


def inputs(): return [int(s) for s in input().split()]


def main():
    s = input()
    cnt = 0
    s = s.replace('A', '1').replace('BC', '0')
    arr = re.split('[A-C]', s)
    arr = [list(x) for x in arr]
    flag = True
    while flag:
        flag = False
        for a in arr:
            tmp = 0
            for i in a:
                tmp += i
                if i is 0:
                    cnt += tmp
                    
    return cnt


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

Submission status: Runtime Error

Solution code:
s = input()

N = len(s)

i = 0
result = 0
count_a = 0
count_bc = 0

while i < N-2:
    if s[i] == 'A':
        while s[i] == 'A':
            count_a += 1
            i += 1
        
        if i >= N-1:
            break
        
#        if s[i] == 'B' and s[i+1] == 'C':
#            result += count_a - 1
                
        while s[i] == 'B' and s[i+1] == 'C':
            count_bc += 1
            i += 2
            if i >= N-1:
                break
        
        result += count_a * count_bc

        if i >= N-1:
            break
        
        if count_bc > 0 and s[i] == 'A':
            count_a = count_a
        else:
            count_a = 0
        
        count_bc = 0
                    
    else:
        i += 1
        
print(result)

Submission status: Runtime Error

Solution code:
s = input()

N = len(s)

i = 0
result = 0
count_a = 0
count_bc = 0

while i < N-2:
    if s[i] == 'A':
        while s[i] == 'A':
            count_a += 1
            i += 1
        
        if i >= N-1:
            break
        
        if s[i] == 'B' and s[i+1] == 'C':
            result += count_a - 1
        
        count_a = 0
        
        while s[i] == 'B' and s[i+1] == 'C':
            count_bc += 1
            i += 2
            if i >= N-1:
                break
            if s[i] == 'A':
                count_a = 1
        
        result += count_bc
        count_bc = 0
                    
    else:
        i += 1
        
print(result)

Submission status: Runtime Error

Solution code:
s = input()

N = len(s)

i = 0
result = 0
count_a = 0
count_bc = 0

while i < N-2:
    if s[i] == 'A':
        while s[i] == 'A':
            count_a += 1
            i += 1
        
        if i >= N-1:
            break
        
        if s[i] == 'B' and s[i+1] == 'C':
            result += count_a - 1
        
        count_a = 0
        
        while s[i] == 'B' and s[i+1] == 'C':
            count_bc += 1
            i += 2
            if i >= N-1:
                break
            if s[i] == 'A':
                count_a = 1
        
        result += count_bc
        count_bc = 0
            
        if i >= N -1:
            break
        
    else:
        i += 1
        
print(result)

Submission status: Runtime Error

Solution code:
s=input()
s+="Z"
S=""
F=0
for i in range(len(s)):
    if F==0:
        if s[i]=="B":
            F=1
        else:
            S+=s[i]
    else:
        if s[i]=="C":
            S+="D"
            F=0
        elif s[i]=="B":
            S+="B"
        else:
            S+=s[i]
            F=0
if S[len(S)-1]=="Z":
    S=S[:len(S)-1]
#print(S)
S=S[::-1]
L=[]
if S[0]=="D":
    L.append(1)
else:
    L.append(0)
for i in range(1,len(S)):
    if S[i]=="D":
        L.append(L[i-1]+1)
    elif S[i]=="A":
        L.append(L[i-1])
    else:
        L.append(0)
L=L[::-1]
S=S[::-1]
#print(S)
#print(L)
ANS=0
for i in range(len(S)):
    if S[i]=="A":
        ANS+=L[i]
print(ANS)

Submission status: Runtime Error

Solution code:
s=input()
s+="Z"
S=""
F=0
for i in range(len(s)):
    if F==0:
        if s[i]=="B":
            F=1
        else:
            S+=s[i]
    else:
        if s[i]=="C":
            S+="D"
            F=0
        elif s[i]=="B":
            S+="B"
        else:
            S+=s[i]
            F=0
S=S[:len(S)-1]
#print(S)
S=S[::-1]
L=[]
if S[0]=="D":
    L.append(1)
else:
    L.append(0)
for i in range(1,len(S)):
    if S[i]=="D":
        L.append(L[i-1]+1)
    elif S[i]=="A":
        L.append(L[i-1])
    else:
        L.append(0)
L=L[::-1]
S=S[::-1]
#print(S)
#print(L)
ANS=0
for i in range(len(S)):
    if S[i]=="A":
        ANS+=L[i]
print(ANS)

Submission status: Runtime Error

Solution code:
orozco = 0
def cont():
    global orozco
    orozco = orozco +1
def trocar(vetor, i):
    if(vetor[i] == "A" and vetor[i+1] == "B" and vetor[i+2] == "C"):
        vetor[i] = "B"
        vetor[i+1] = "C"
        vetor[i+2] = "A"
        cont()
        trocar(vetor, i-1)
        trocar(vetor, i+2)

a = input()
x = []
for i in range(3):
    x.append(0)

for i in range(a.__len__()):
    x.append(a[i])

for i in range(3):
    x.append(0)

for i in range(2, a.__len__()+1, 1):
    trocar(x, i)

print(orozco)

Submission status: Runtime Error

Solution code:

def bubble_sort(A):
    cnt = 0
    for i in range(len(A)):
        for j in range(len(A)-1, i, -1):
            if A[j] == 'D' and A[j-1] == 'A':
                A[j], A[j-1] = A[j-1], A[j]
                cnt += 1
    return cnt

s = input()
total = 0
new_s = s.replace("BC", "D")
new_s_list = list(new_s).append("G")
tmp_start = 0
for i in range(len(new_s_list)):
  if new_s_list[i] in {'B', 'C', 'G'}:
    total += bubble_sort(new_s_list[tmp_start:i])
    tmp_start = i

print(total)

Submission status: Runtime Error

Solution code:
sl = s.replace('BC', 'D').replace('B', 'C')
while 'AC' in sl or  'CD' in sl or  'CC' in sl:
    sl = sl.replace('AC', 'C')
    sl = sl.replace('CD', 'C')
    sl = sl.replace('CC', 'C')
sl = sl.split('C')

def func(l):
    ind = [i for i, x in enumerate(l) if x == 'D']
    cl =  sum([l[:i].count('A') for i in ind])
    return cl

c = 0
for l in sl:
    l = list(l)
    c += func(l)
print(c)

Submission status: Runtime Error

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

print(answer)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def dfs(string, idx):
  tmp_s = string[0:idx]+"BCA"+string[idx+3:]
  # left
  if len(string[0:idx]) >= 1 and tmp_s[idx-1:idx+2] == "ABC":
    left_translated, left_count = dfs(tmp_s[:idx+2], idx-1)
  else:
    left_translated = tmp_s[:idx+2]
    left_count = 0
  #print("left:"+left_translated)
  if len(string[idx+3:]) >= 2 and tmp_s[idx+2:idx+5] == "ABC":
    right_translated, right_count = dfs(tmp_s[idx+2:], 0)
  else:
    right_translated = tmp_s[idx+2:]
    right_count = 0
    #print("right:"+right_translated)
  return left_translated + right_translated, left_count + right_count + 1


s = input()
total = 0
idx = s.find("ABC") 
while idx != -1:
  s, count = dfs(s, idx)
  total += count
  idx = s.find("ABC")
  
print(total)

Submission status: Runtime Error

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

len_s = len(S)
count = 0
tmp = 0

def change(s, i):
  global tmp
  if s[i:i+2] == "AD":
    s = s[:i] + "DA" + s[i+2:]
    if i > 0 and S[i-1] == "A":
      s, tmp = change(s, i-1)
      return s, 1+tmp
    return s, 1+tmp
  return s, 0

if len_s < 1:
  print(count)
else:
  i = 0
  while i < len(S)-1:
    tmp = 0
    S, plus = change(S, i)
    count += plus
    i += 1
  print(count)

Submission status: Runtime Error

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)
s.remove("")

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("A",start+1)
        
print(cnt)

Submission status: Runtime Error

Solution code:
s = list()
s.append(2)
s.append(2)
s.append(2)


for i in S:
    if(i=="A"):
        s.append(0)
    elif(i=="B"):
        s.append(1)
    else:
        s.append(2)


count= 0
i = 0

while( i < 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

    i += 1
print(count)