Problem:


Score : 600 points

Problem Statement

You are given a string s consisting of A, B and C.

Snuke wants to perform the following operation on s as many times as possible:

Choose a contiguous substring of s that reads ABC and replace it with BCA.

Find the maximum possible number of operations.

Constraints

1 \leq |s| \leq 200000

Each character of s is A, B and C.

Input

Input is given from Standard Input in the following format:

s

Output

Find the maximum possible number of operations.

Sample Input 1

ABCABC

Sample Output 1

3

You can perform the operations three times as follows: ABCABC → BCAABC → BCABCA → BCBCAA. This is the maximum result.

Sample Input 2

C

Sample Output 2

0

Sample Input 3

ABCACCBABCBCAABCB

Sample Output 3

6



Sample input:
ABCABC


Sample output:
3

Submission status: Accepted

Solution code:
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict
import math


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def mod_inv(x):
    # available only when mod is prime
    global mod
    return pow(x, mod - 2, mod)


def gcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    ret = math.factorial(x)
    ret = ret // (math.factorial(x - y) * math.factorial(y))

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


class UnionFind:

    def __init__(self, n):
        self.parent = [i for i in range(n)]

    def root(self, i):
        if self.parent[i] == i:
            return i
        self.parent[i] = self.root(self.parent[i])
        return self.parent[i]

    def unite(self, i, j):
        rooti = self.root(i)
        rootj = self.root(j)
        if rooti == rootj:
            return
        if rooti < rootj:
            self.parent[rootj] = rooti
        else:
            self.parent[rooti] = rootj

    def same(self, i, j):
        return self.root(i) == self.root(j)


###############################################################################


def main():
    s = input()

    slistlist = []
    slist = []
    prev = None
    for c in s:
        if c == 'A':
            if prev == 'B':
                if slist:
                    slistlist.append(slist)
                slist = []
            slist.append(c)
            prev = None
        if c == 'B':
            if prev == 'B':
                if slist:
                    slistlist.append(slist)
                slist = []
            prev = c
        if c == 'C':
            if prev == 'B':
                slist.append('X')
            else:
                if slist:
                    slistlist.append(slist)
                slist = []
            prev = None
    if slist:
        slistlist.append(slist)

    ans = 0
    for slist in slistlist:
        count = 0
        for i in slist:
            if i == 'A':
                count += 1
            if i == 'X':
                ans += count

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import os
import sys

if os.getenv('LOCAL'):
    sys.stdin = open('_in.txt', 'r')

sys.setrecursionlimit(2147483647)
INF = float('inf')

S = sys.stdin.readline().rstrip()

a = 0
ans = 0
i = 0
while i < len(S):
    if S[i] == 'A':
        a += 1
    elif S[i] == 'B':
        if i + 1 < len(S) and S[i + 1] == 'C':
            i += 1
            ans += a
        else:
            a = 0
    else:
        a = 0
    i += 1
print(ans)

Submission status: Accepted

Solution code:
s = input()

s = s.replace("A","0").replace("BC", "1").replace("B"," ").replace("C"," ")
ss = list(s.split())
ans = 0
for e in ss:
    next = 0
    for i in range(len(e)):
        if e[i] == "1":
            ans += (i-next)
            next += 1
print(ans)

Submission status: Accepted

Solution code:
def solve():
    s = input()
    n=len(s)
    cnt = 0
    ans = 0
    j = 0
    for i in range(n-1):
        if j>=n-1:
            break
        if s[j]=='A':
            cnt+=1
        elif s[j]=='B' and s[j+1]=='C':
            ans+=cnt
            j+=1
        else:
            cnt = 0
        j+=1
    return ans
print(solve())

Submission status: Accepted

Solution code:
s = input()
sg = s.replace('BC', 'G')
sg = sg + 'E'

ans = 0
anstmp = 0
acount = 0
for i in sg:
    if i == 'A':
        acount += 1
    elif i == 'G':
        anstmp += acount
    else:
        ans += anstmp
        acount = 0
        anstmp = 0

print(ans)

Submission status: Accepted

Solution code:
S = input()[::-1]
N = len(S)
ans = 0
i = 0
cb = 0
ans = 0
while i < N:
    if S[i:i + 2] == 'CB':
        i += 2
        cb += 1
    elif S[i] == 'A':
        i += 1
        ans += cb
    else:
        i += 1
        cb = 0
print(ans)

Submission status: Accepted

Solution code:
s = input()

s_len = len(s)
ans = 0
A_cnt = 0
BC_flag = False

i = 0
while i < s_len:
	if not BC_flag:
		if s[i] == "A":
			A_cnt += 1
			BC_flag = True
		i += 1
	else:
		if s[i] == "A":
			A_cnt += 1
			i += 1
		elif s[i:i+2] == "BC":
			ans += A_cnt
			i += 2
		else:
			A_cnt = 0
			BC_flag = False
print(ans)

Submission status: Accepted

Solution code:
S = input()
L = len(S)
S += "!"
c = 0
i = 0
count_of_A = 0
while i < L:
    if S[i] == 'A':
        count_of_A += 1
        i += 1
    elif S[i] == 'B' and S[i+1] == 'C':
        c += count_of_A
        i += 2
    else:
        count_of_A = 0
        i += 1

print(c)

Submission status: Accepted

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

ss = None
r = 0
ac = 0
for c in s:
    if c == "A":
        if ss == "A":
            ac += 1
        else:
            ac = 1
    elif c == "C" and ss == "B":
        r += ac
        ss = "A"
#        print(c, r,ac)
        continue
    elif c == "B" and ss == "A":
        pass
    else:
        ac = 0
    ss = c
#print(c, r,ac)
print(r)

Submission status: Accepted

Solution code:
s = list(input())

# count BC from left
bc_cnt = 0
res = 0
for i in range(len(s)-2, -1, -1):
    if s[i] == "B":
        if s[i+1] == "C":
            bc_cnt += 1
        else:
            bc_cnt = 0
    elif s[i] == "A":
        if s[i+1] == "C":
            bc_cnt = 0
    else:
        if s[i+1] == "C":
            bc_cnt = 0
    if s[i] == 'A':
        res += bc_cnt
print(res)

Submission status: Accepted

Solution code:
s = input()
s_X = list(s.replace("BC", "X"))

A_count = 0
ans = 0
for i in range(len(s_X)):
    if s_X[i] == "A":
        A_count += 1
    elif s_X[i] == "X":
        ans += A_count
    else:
        A_count = 0

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

s=input().split("BC")
s.pop()
ans = 0
now=0
#print(s)
for i in s:
    if "B" not in i and "C" not in i:
        now += len(i)
        ans += now
    else:
        x=i.rfind('B')
        y=i.rfind('C')
        now = len(i) - max(x,y) - 1
        ans += now
#    print(now,ans)

print(ans)

Submission status: Accepted

Solution code:
def main():
    n = input().rstrip()

    n = n.replace('BC','z')

    op = 0
    cz = 0
    isZ = False
    for i in reversed(n):
        if i == 'z':
            isZ = True
            cz += 1
        elif i == 'A' and isZ:
            op += cz
        else:
            isZ = False
            cz = 0
    print(op)
    
if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
st = input()
N = len(st)
ans = 0
cnt = 0
i = 0
while i < N-1:
  if st[N-2-i:N-i] == "BC":
    cnt += 1
    i += 2
  elif st[N-1-i] ==  'A':
    ans += cnt
    i += 1
  else:
    cnt = 0
    i +=1
else:
  if st[0] == 'A':
    ans += cnt
  
print(ans)

Submission status: Accepted

Solution code:
S = input()
N = len(S)
A = [0]*N
BC = [0]*N
count = 0
i = 0
while i < N:
  if S[i] == "A":
    A[count] += 1
    i += 1
  elif i<N-1 and  S[i] == "B" and S[i+1] == "C":
    BC[i] += A[count]
    i += 2
  else:
    count += 1
    i += 1
print(sum(BC))

Submission status: Accepted

Solution code:
s=input()
n=len(s)
s+="X"
acnt=0
bccnt=0
res=0
i=0
while(i<n):
    if s[i:i+2]=="BC":
        bccnt+=1
        i+=1
    elif s[i]=="A":
        acnt+=1
        res-=bccnt
    else:
        res+=bccnt*acnt
        bccnt=0
        acnt=0
    i+=1
res+=bccnt*acnt
print(res)

Submission status: Accepted

Solution code:
import sys, math, collections, heapq, itertools
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0: a, b = b, a % b
    return b
  
def solve():
    s = input()
    t = ""
    i = 0
    while i < len(s):
        if s[i] == "A":
            t += "A"
            i += 1
        elif s[i] == "B":
            if i < len(s) - 1:
                if s[i+1] == "C":
                    t += "D"
                    i += 2
                else:
                    t += "X"
                    i += 1
            else:
                t += "X"
                i += 1
        else:
            t += "X"
            i += 1
    
    total = 0
    numA = 0
    for i in range(len(t)):
        if t[i] == "X":
            numA =  0
        else:
            if t[i] == "A": numA += 1
            else: total += numA

    print(total)
    INF = 10 ** 25
    mod = 7 + 10 ** 9
    return 0
  
if __name__ == "__main__":
    solve()

Submission status: Accepted

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


# BCの左にAがいくつあるかを持つ
cnt_A = 0
answer = 0
for s in S:
  if s == 'A':
    cnt_A += 1
  elif s =='X':
    answer += cnt_A
  else:
    cnt_A = 0
print(answer)

Submission status: Accepted

Solution code:
s=input()

b_charged=False
s1 = []

for i in range(len(s)):
    if s[i]=="B":
        b_charged = True
        s1.append("B")
    elif s[i]=="C":
        if b_charged:
            b_charged=False
            s1[-1]="BC"
        else:
            s1.append("C")
    else:
        b_charged=False
        s1.append("A")

a_count = 0
count = 0
for i in range(len(s1)):
    if s1[i]=="A":
        a_count+=1
    elif s1[i]=="BC":
        count+=a_count
    else:
        a_count=0

print(count)

Submission status: Accepted

Solution code:
s = input()
t = ""
last = ""
for i in s:
    if last == "B":
        if i == "C":
            t += "X"
        elif i == "B":
            t += last
        else:
            t += last
            t += i
    else:
        if i != "B":
            t += i
    last = i
count = 0
ans = 0
for i in t[::-1]:
    if i == "X":
        count += 1
    elif i == "A":
        ans += count
    else:
        count = 0
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

def main():
    s = SI().replace('BC', 'X')
    cnt = 0
    ans = 0
    for k in s[::-1]:
        if k == 'X':
            cnt += 1
        elif k == 'A':
            ans += cnt
        else:
            cnt = 0
    return ans

print(main())

Submission status: Accepted

Solution code:
#coding:utf-8
s = input()
ls_s = []
Skip = 0
s2 = ""
for i in range(len(s)-1):
    if Skip:
        Skip = 0
    elif s[i:i+2] == "BC":
        s2 += 'W'
        Skip = 11
    elif s[i] == "A":
        s2 += 'B'
    else:
        ls_s.append(s2)
        s2 = ""
ls_s.append(s2)
#print (ls_s)
        
def bw(s):
    ls = []
    cnt_b =0
    for i in range(len(s)):
        if s[i] == "W":
            ls.append(cnt_b)
        else:
            cnt_b+=1
    return sum(ls)
sm = 0
for s2 in ls_s:
    sm += bw(s2)
print (sm)

Submission status: Accepted

Solution code:
s = input()
s = s.replace('BC','D')
N = len(s)
a = [0]*(N+1)
ans = [0]*(N+1)

for n in range(N):
    ans[n+1] = ans[n]
    if s[n] == 'A':
        a[n+1] = a[n]+1
    elif s[n] == 'D':
        a[n+1] = a[n]
        ans[n+1] += a[n]

print(ans[N])

Submission status: Accepted

Solution code:
s=list(input())
n=len(s)
a=0
ans=0
i=0
while i < n-1:
    if s[i]=='A':
        a+=1
        i+=1
    elif s[i]=='B' and s[i+1]=='C':
        ans+=a
        i+=2
    else:
        a=0
        i+=1
print(ans)

Submission status: Accepted

Solution code:
S = input()
S = S[::-1]


C = False
CB = False
cbcount = 0
ans = 0
for i in range(len(S)):
    if S[i] == "C":
        if CB:
            C = True
            CB = False

        elif not C:
            C = True

        else:
            cbcount = 0

    elif S[i] == "B":
        if C:
            CB = True
            C = False
            cbcount += 1
        else:
            C = False
            CB = False
            cbcount = 0
    else:
        if CB:
            ans += cbcount
        else:
            C = False
            CB = False
            cbcount = 0
print(ans)

Submission status: Accepted

Solution code:
"""
ABCABC
BCABCA
BCBCAA

"""

s =input().replace('BC', 'Z')
ss = s.split('B')
sss = []
for t in ss:
    sss.extend(t.split('C'))
ss = [t for t in sss if t]

# 各文字列について全てのZは自身より前のAと反応できる
def solve(s):
    a_cnt = 0
    cnt = 0
    for c in s:
        if c == 'A':
            a_cnt += 1
        else:
            cnt += a_cnt
    return cnt

total = 0
for s in ss:
    total += solve(s)
print(total)

Submission status: Accepted

Solution code:
def main():
	s = input()
	ans = 0
	stock_a = 0
	state = 0 # 0 = prechar is C,B  2 = prestr=("A"*n|n>0)
	ans = 0
	for i in range(len(s)):
		if state == 0:
			if s[i] == "A":
				stock_a = 1
				state = 1
			else:
				stock_a = 0
		elif state == 1:
			if s[i] == "B":
				state = 2
			elif s[i] == "A":
				stock_a += 1
			else:
				stock_a = 0
				state = 0
		elif state == 2:
			if s[i] == "C":
				ans += stock_a
				state = 1
			elif s[i] == "A":
				stock_a = 1
				state = 1
			else:
				state = 0
				stock_a = 0
	print(ans)

main()

Submission status: Accepted

Solution code:
s=input()
n=len(s)
s+="ZZZ"
si=0
ra=0
rbc=0
ans=0
while si<n:
    if(s[si]=="A"):
        ra+=1
        si+=1
    else:
        if(s[si:si+2]=="BC"):
            ans+=ra
            si+=2
        else:
            ra=0
            si+=1
print(ans)

Submission status: Accepted

Solution code:
s = raw_input()

ans = 0
c = 0
i = 0
while i<len(s)-1:
  if s[i]=="A":
    c += 1
    i += 1
  elif s[i:i+2]=="BC":
    ans += c
    i += 2
  else:
    c = 0
    i += 1
print ans

Submission status: Accepted

Solution code:
from sys import exit, setrecursionlimit, stderr, stdin
from functools import reduce
from itertools import *
from collections import defaultdict, Counter
from bisect import bisect
import functools

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

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

s = input()
s = s.replace("BC", "X")
N = len(s)

ans = 0

x = 0
for i in range(N-1, -1, -1):
  if s[i] == "X":
    x += 1
  elif s[i] == "A":
    ans += x
  else:
    x = 0
print(ans)

Submission status: Accepted

Solution code:
l = []
for i in input().replace('BC', '!').split('B'):
        l += i.split('C')

ans = 0
for i in l:
        p = i.count('!')
        cnt = 0
        for j in i:
                if j == '!': cnt += 1
                else: ans += p - cnt
print(ans)

Submission status: Accepted

Solution code:
S=input()
data=[]
now=[]
idx=0
while idx<len(S):
    if S[idx]=="A":
        now.append(0)
        idx+=1
    elif S[idx]=="B" and idx+1<len(S):
        idx+=1
        if S[idx]=="C":
            now.append(1)
            idx+=1
        elif len(now)>0:
            data.append(now)
            now=[]
    else:
        idx+=1
        if len(now)>0:
            data.append(now)
            now=[]
if len(now)>0:
    data.append(now)

def calc(x):
    cnt=0
    ans=0
    for i in x:
        if i==0:
            cnt+=1
        elif i==1:
            ans+=cnt
    return ans
ans=0
for x in data:
    ans+=calc(x)
print(ans)

Submission status: Accepted

Solution code:
S = input()
ans = 0
cnt_a = 0
pc = "."
for c in S:
    #print(c, cnt_a)
    if pc=="B":
        if c=="C":
            ans += cnt_a
        elif c=="A":
            cnt_a = 1
        else:
            cnt_a = 0
    else:
        if c=="C":
            cnt_a = 0
        elif c=="B":
            pass
        else:
            cnt_a += 1
    pc = c

print(ans)

Submission status: Accepted

Solution code:
s = input()
ans = 0
a = 0
b = False
for i in range(len(s)):
	if s[i] == "A":
		if b:
			a = 0
		a += 1
		b = False
	elif s[i] == "B":
		if b:
			a = 0
		b = True
	else:
		if b:
			ans += a
		else:
			a = 0
		b = False
print(ans)

Submission status: Accepted

Solution code:
s=input()
s=s.replace("BC","D").replace("B","C")
l=[i for i in s.split("C") if len(i) !=0]
cnt=0

for line in l:
  dcnt =0 
  for ch in reversed(line):
    if ch == "D":
      dcnt+=1
    else:
      cnt+=dcnt

print(cnt)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)


def main():
    s = S()
    l = len(s)
    a = []
    si = 0
    while si < l:
        if s[si] == 'A':
            a.append(1)
            si += 1
        elif s[si:si+2] == 'BC':
            a.append(2)
            si += 2
        else:
            a.append(0)
            si += 1

    r = 0
    t = 0
    for c in a:
        if c == 0:
            t = 0
        elif c == 1:
            t += 1
        else:
            r += t


    return r


print(main())

Submission status: Accepted

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

acc = 0
ans = 0
for c in s:
    if c == 'B' or c == 'C':
        acc = 0
        continue
    if c == 'A':
        acc += 1
    if c == 'D':
        ans += acc
print(ans)

Submission status: Accepted

Solution code:
import re
s = input()
subs = re.sub('BC', 'X', s)

answer = 0
A = 0
for i in range(len(subs)):
    if subs[i] == 'A' :
        A += 1
    elif subs[i] == 'X':
        answer += A
    else:
        A = 0
print(answer)

Submission status: Accepted

Solution code:
import sys
from collections import deque
from collections import defaultdict
import math
sys.setrecursionlimit(20000000)
#input = sys.stdin.readline
 
s = input()

s = s.replace("BC","X")
n = len(s)
ten = []
ans = 0
for i in range(n):
        if s[i] == "A" or s[i] == "X":
                ten.append(s[i])
        else:
                acount = 0
                for j in range(len(ten)):
                        if ten[j] == "A":
                                acount+=1
                        else:
                                ans += acount
                ten= []
acount = 0
for j in range(len(ten)):
        if ten[j] == "A":
                acount+=1
        else:
                ans += acount
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env pypy
from __future__ import division, print_function

import os
import sys
from __builtin__ import xrange as range
from cStringIO import StringIO
from future_builtins import ascii, filter, hex, map, oct, zip
from io import IOBase

import __pypy__


def main():
    s = input().replace('BC', 'D')

    res, cnt = 0, 0
    for si in s:
        if si == 'A':
            cnt += 1
        if si == 'B' or si == 'C':
            cnt = 0
        if si == 'D':
            res += cnt
    print(res)


# region fastio

BUFSIZE = 8192


class FastI(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = StringIO()
        self.newlines = 0

    def read(self):
        if self._buffer.tell():
            return self._buffer.read()
        return os.read(self._fd, os.fstat(self._fd).st_size)

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count("\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()


class FastO(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = __pypy__.builders.StringBuilder()
        self.write = lambda s: self._buffer.append(s)

    def flush(self):
        os.write(self._fd, self._buffer.build())
        self._buffer = __pypy__.builders.StringBuilder()


def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
s = str(input())

ans = 0
for i in range(len(s)-1):
  if s[i:i+2] == 'BC':
    cnt = 0
    for j in range(i):
      if s[i-1-j] == 'A':
        cnt += 1
      else:
        break
    s = s[:i-cnt] + 'BC' + 'A'*cnt + s[i+2:]
    ans += cnt
    print(s)
print(ans)

Submission status: Runtime Error

Solution code:
s = str(input())

ans = 0
for i in range(len(s)-1):
  if s[i:i+2] == 'BC':
    cnt = 0
    for j in range(i):
      if s[i-1-j] == 'A':
        cnt += 1
      else:
        break
    s = s[:i-j-cnt] + 'BC' + 'A'*cnt + s[i+2:]
    ans += cnt
print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(1000000000)
s=list(input())

def saiki(i):
  
  global c
  if 0<=i <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"
      c+=1
      saiki(i-1)
    else:
      saiki(i+1)
  elif i==-1:
      saiki(0)
c=0
saiki(0)

print(c)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10000000)
s=list(input())

def saiki(i):
  global c
  if 0<=i <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"
      c=c+1
      
      saiki(i-1)
    else:
      saiki(i+1)
  elif i==-1:
      saiki(0)
c=0
saiki(0)

print(c)

Submission status: Runtime Error

Solution code:
from numba import jit
s = list(input())
n = len(s)
ans = 0
@jit
def p(ans):
    for i in range(0, n-2):
        b = True
        if s[i:i+3] == ['A', 'B', 'C']:
            s[i] = 'B'
            s[i+1] = 'C'
            s[i+2] = 'A'
            ans += 1
            b = False
        
    return ans, b
while True:
    ans, b = p(ans)
    if not b:
        break
print(ans)

Submission status: Runtime Error

Solution code:
#import random
#import string
#def randomname(n):
#    candidate_text = ["A","B","C"] #出力候補を限定する場合
#    randlst = [random.choice(candidate_text) for i in range(n)] #()の中身を string.ascii_letters + string.digits とすると大小英数字
#    return ''.join(randlst)

s = list(input()) #list(randomname(200000)) 
N = len(s)

ans = 0

def ABC_check(i):
    if 0 <= i-1 and i+1 <= N-1 and s[i-1]=="A" and s[i]=="B" and s[i+1]=="C":
        temp_ans = 1
        s[i-1]="B"
        s[i]="C"
        s[i+1]="A"
        
        temp_ans += ABC_check(i-1)
        
        return temp_ans
    else:
        return 0

for i in range(1,N-1):
    ans += ABC_check(i)

print(ans)

Submission status: Runtime Error

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

ans = 0

def ABC_check(i):
    if 0 <= i-1 and i+1 <= N-1 and s[i-1]=="A" and s[i]=="B" and s[i+1]=="C":
        temp_ans = 1
        s[i-1]="B"
        s[i]="C"
        s[i+1]="A"
        
        temp_ans += ABC_check(i-1)
        temp_ans += ABC_check(i+2)
        return temp_ans
    else:
        return 0

for i in range(0,N):
    ans += ABC_check(i)

print(ans)

Submission status: Runtime Error

Solution code:
#import random
#import string
#def randomname(n):
#    candidate_text = ["A","B","C"] #出力候補を限定する場合
#    randlst = [random.choice(candidate_text) for i in range(n)] #()の中身を string.ascii_letters + string.digits とすると大小英数字
#    return ''.join(randlst)

s = list(input()) #list(randomname(200000)) 
N = len(s)

ans = 0

def ABC_check(i):
    if 0 <= i-1 and i+1 <= N-1 and s[i-1]=="A" and s[i]=="B" and s[i+1]=="C":
        temp_ans = 1
        s[i-1]="B"
        s[i]="C"
        s[i+1]="A"
        
        temp_ans += ABC_check(i-1)
        temp_ans += ABC_check(i+2)
        return temp_ans
    else:
        return 0

for i in range(1,N-1):
    ans += ABC_check(i)

print(ans)

Submission status: Runtime Error

Solution code:
#import random
#import string
#def randomname(n):
#    candidate_text = ["A","B","C"] #出力候補を限定する場合
#    randlst = [random.choice(candidate_text) for i in range(n)] #()の中身を string.ascii_letters + string.digits とすると大小英数字
#    return ''.join(randlst)

s = list(input()) #list(randomname(200000)) 
N = len(s)

ans = 0

def ABC_check(i):
    if 0 <= i and i+1 <=N-1 and s[i-1]=="A" and s[i]=="B" and s[i+1]=="C":
        temp_ans = 1
        s[i-1]="B"
        s[i]="C"
        s[i+1]="A"
        
        temp_ans += ABC_check(i-1)
        temp_ans += ABC_check(i+2)
        return temp_ans
    else:
        return 0

for i in range(1,N-1):
    ans += ABC_check(i)

print(ans)

Submission status: Runtime Error

Solution code:
s = raw_input()
def test(s):

	res = 0
	aAdd = 0
	last = ''
	s1 = s
	tmp = ''
	for i in xrange(len(s)-2):
		if tmp and tmp > i:
			continue
		if s1[i] == 'A' and (not last or last == 'A'):
			aAdd += 1
		else:
			aAdd = 0
			last = s1[i]

		if s1[i:i+3] == 'ABC':
			print s1
			print aAdd
			res = res + aAdd
			last = 'A'
			aAdd -= 1
			tmp = i + 2
			s1 = s1[:i] + 'BCA' + s1[i+3:]

	return res
print test(s)

Submission status: Runtime Error

Solution code:
s = raw_input()
n = 0

def mul(s):
    if len(s) < 3:
        return 0
    n = 0
    flag = True
    while flag:
        res = 0
        s1 = s
        _res = 0
        for i in xrange(len(s) - 2):
        	j = j + _res
            str = s[j:(j+3)]
            if str == "ABC":
                n = n + 1
                res = res + 1
                _res = _res + 2
                s1 = s1[:j] + "BCA"+ s1[j+3:]
        if res == 0:
            flag =False
        s = s1
    return n
print mul(s)

Submission status: Runtime Error

Solution code:
s = raw_input()
# a, b = s.split(' ')
# a, b = int(a), int(b)
n = 0

def mul(s, n):
    if len(s) < 3:
        return 0
    for i in xrange(len(s) - 2):
        str = s[i:(i+3)]
        if str == "ABC":
            n = n + 1
            # print(s[:i] + "BCA"+ s[i+3:])
            return mul(s[:i] + "BCA"+ s[i+3:], n)
            # _str[i:i+3] = "BCA"+ _str[i+3:]
    return n
print mul(s,n)

Submission status: Runtime Error

Solution code:
s = raw_input()
# a, b = s.split(' ')
# a, b = int(a), int(b)
n = 0

def mul(s, n):
    if len(s) < 3:
        return 0
    for i in range(len(s) - 2):
        str = s[i:(i+3)]
        if str == "ABC":
            n = n + 1
            print(s[:i] + "BCA"+ s[i+3:])
            return mul(s[:i] + "BCA"+ s[i+3:], n)
            # _str[i:i+3] = "BCA"+ _str[i+3:]
    return n
print(mul(s,n))

Submission status: Runtime Error

Solution code:
def c(s, cnt):
    tmp = s.count("ABC")
    if tmp == 0:
        print(cnt)
    else:
        cnt += tmp
        s = s.replace("ABC", "BCA")
        c(s, cnt)
s = input()
ans = 0
c(s, ans)

Submission status: Runtime Error

Solution code:
def check(s,cnt):
    if ('ABC' in s):
        s=s.replace('ABC','BCA',1)
        cnt+=1
        check(s,cnt)
    else :
        print(cnt)

s=input()
cnt=0
(check(s,cnt))

Submission status: Runtime Error

Solution code:
s = list(input())

i = 0
res = 0
cnt = 0
while i != len(s) - 2:
    if s[i] == "A" and s[i + 1] == "A":
        cnt += 1
        i += 1
    elif s[i] == "A" and s[i + 1] == "B" and s[i + 2] == "C":
        res += cnt + 1
        s[i], s[i + 1], s[i + 2] = "B", "C", "A"
        cnt = 0
        i += 1
    else:
        cnt = 0
        i += 1
print(res)

Submission status: Runtime Error

Solution code:
N, X = map(int, input().split())
a, p = [1], [1]
for i in range(N):
    a.append(a[i] * 2 + 3)
    p.append(a[i] * 2 + 1)

def f(N, X):
    if N == 0:
        return 0 if X <= 0 else 1
    elif X <= 1 + a[N-1]:
        # B(N-1) | P(N-1)B の真ん中のパティの前までの範囲がわかればいい場合
        # Xから先頭のバンの数を引いて、N-1の先頭からX-1までの数を数えるために再帰で呼び出す
        return f(N-1,X-1)
    else:
        # 真ん中のパティ以上の枚数を数える必要がある場合
        # 一つ前のレベルのパティの数 + 真ん中のパティ + f(レベル-1, この関数呼び出しで知りたいトータルの枚数-2(先頭のバンと真ん中のパティ)-一つ前のレベルのハンバーガーのトータルの枚数)
        # X-2-a[N-1] → X - (B(N-1)P)|ここから後ろの先頭からK枚を数えるために再帰で呼び出す
        return p[N-1] + 1 + f(N-1, X-2-a[N-1])

print(f(N,X))

Submission status: Runtime Error

Solution code:

import numpy as np

def f(lst):
    return np.cumsum(lst)

s = input()
cnt = 0
s = s.replace('BC', 'D')

x = [0]*len(s)
for i in range(len(s)):
    if s[i]=='A':
        x[i] += 1
x = f(x)

res = 0
for i in range(len(s)):
    if s[i]=='D':
        res += x[i]
print(res)