Problem:


Score : 600 points

Problem Statement

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

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

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

Find the maximum possible number of operations.

Constraints

1 \leq |s| \leq 200000

Each character of s is A, B and C.

Input

Input is given from Standard Input in the following format:

s

Output

Find the maximum possible number of operations.

Sample Input 1

ABCABC

Sample Output 1

3

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

Sample Input 2

C

Sample Output 2

0

Sample Input 3

ABCACCBABCBCAABCB

Sample Output 3

6



Sample input:
ABCABC


Sample output:
3

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
cnt = 0
ans = 0
flag = False
for i in range(len(s) - 1):
    if flag:
        flag = False
        continue
    if s[i: i + 2] == 'BC':
        ans += cnt
        flag = True
    elif s[i] == 'A':
        cnt += 1
    else:
        cnt = 0
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
S = list(input())[: -1]
t = []
res = 0
i = 1
while i < len(S):
  if S[i - 1] == "B" and (S[i] == "C"):
    t.append("X")
    i += 1
  else:
    if S[i - 1] == "A": t.append(S[i - 1])
    else: t.append("Y")
  i += 1
tt = "".join(t).split("Y")
for x in tt:
  xs = x.count("X")
  for i in range(len(x)):
    if x[i] == "A":
      res += xs
    else: xs -= 1
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = "???" + input() + "???"

a = 0

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

    if s == "A":
        a += 1
        i += 1
        while i < len(S):
            s1 = S[i]
            s2 = S[i + 1]

            if s1 == "A":
                a += 1
                i += 1
                continue
            elif s1 + s2 == "BC":
                ans += a
                i += 2
            else:
                break

        a = 0
    else:
        i += 1
        continue

print(ans)

Submission status: Accepted

Solution code:
s=input()
n=len(s)
i,a,ans=0,0,0
while i<n:
    if s[i]=="A":
        a+=1
        i+=1
    elif i<n-1 and s[i:i+2]=="BC":
        ans+=a
        i+=2
        while i<n:
            if s[i]=="A":
                a+=1
                i+=1
            elif i<n-1 and s[i:i+2]=="BC":
                ans+=a
                i+=2
            else:
                a=0
                i+=1
                break
    else:
        i+=1
        a=0
print(ans)

Submission status: Accepted

Solution code:
S = list(input())

ans = 0
cnt = 0
i = len(S)-1
while i >= 0:
    if i > 0 and S[i] == "C" and S[i-1] == "B":
        cnt += 1
        i -= 2
    elif S[i] == "A":
        ans += cnt
        i -= 1
    else:
        cnt = 0
        i -= 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
ans = 0
Acnt = 0
cnt = 0
for c in s:
    if cnt <= 1 and c == "A":
        Acnt += 1
        cnt = 1
    elif c == "A":
        Acnt = 1
        cnt = 1
    elif cnt == 1 and c == "B":
        cnt = 2
    elif cnt == 2 and c == "C":
        ans += Acnt
        cnt = 1
    else:
        Acnt = 0
        cnt = 0
print(ans)

Submission status: Accepted

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

# AABC->ABCA->BCAA
# ABCの前にAがn個->ABCの後にAがn個

# ABCABC->BCABCA->BCBCAA

# AかBCでない並びがあったら切断

# Aを右に BCを左に移動させる操作
# BCがあったら、それより左にあるAの数だけansが増える


i = 0
a = 0
ans = 0

while i < len(s):
    if s[i] == 'A':
        a += 1
        i += 1
        continue
    if s[i] == 'B' and i + 1 < N:
        if s[i + 1] == 'C':
            ans += a
            i += 2
            continue
    a = 0
    i += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
compress = []
i = 0
while i < len(s):
    if s[i:i+2] == 'BC':
        compress.append('D')
        i += 2
    else:
        compress.append(s[i])
        i += 1
ans = 0
count = 0
for x in compress:
    if x == 'A':
        count += 1
    elif x == 'D':
        ans += count
    else:
        count = 0
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
s = stdin.readline().rstrip()
s = s.replace("BC","D")
point = 0
count = 0
for i in s:
    if i == "A":
        count += 1
    elif i == "D":
        point += count
    else:
        count = 0
print(point)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
ans = 0
idx = 0
a_count = 0
while idx < len(S):
    if S[idx] == "A":
        a_count += 1
    elif S[idx:idx+2] == "BC":
        ans += a_count
        idx += 1
    else:
        a_count = 0
    idx += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

if S[0] == 'A':
    ac = 1
else:
    ac = 0

ans = 0
for i in range(1,N):
    if S[i] == 'A':
        if S[i-1] != 'A':
            ac = 1
        else:
            ac += 1
    elif S[i] == 'B':
        if S[i-1] != 'A':
            ac = 0
    else:
        if S[i-1] == 'B':
            ans += ac
            S[i] = 'A'
        else:
            ac = 0

print(ans)

Submission status: Accepted

Solution code:
s=str(input())
n=len(s)
z=0
ans=0
i=0
while i<=n-2:
    if s[i]=='A':
        z+=1
        i+=1
        continue
    elif s[i:i+2]=='BC' and z>0:
        ans+=z
        i+=2
    else:
        z=0
        i+=1
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(S):
    S = S.replace('BC', 'D')
    S = S.replace('B', ' ')
    S = S.replace('C', ' ')

    ans = 0
    for s in S.split():
        a = 0
        for c in s:
            if c == 'A':
                a += 1
            else:
                ans += a
    return ans

def main():
    S = read_str()
    print(slv(S))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.readline
readlines = sys.stdin.buffer.readlines

S = readline().rstrip()
S = S.replace('BC', '#')

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

Submission status: Accepted

Solution code:
S = input()
c = 0
i = 0
ac = 0
while i < len(S):
    if S[i] == "A":
        ac += 1
    elif S[i:i+2] == "BC":
        c += ac
        i += 1
    else:
        ac = 0
    i += 1
print(c)

Submission status: Accepted

Solution code:
S = input()
ABD = S.replace("BC","D")
a_cnt = 0
ans = 0
# print(ABD)
# print(S)
for s in ABD:
    if s == 'A':
        a_cnt += 1
    elif s == 'D':
        ans += a_cnt
    elif s == 'B' or s == 'C':
        a_cnt = 0
print(ans)

Submission status: Accepted

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: Accepted

Solution code:
s = input()
ans = 0
a = 0
i = 0
while i < len(s):
    c = s[i]
    if c == 'A':
        a += 1
    elif c == 'B':
        i += 1
        if i >= len(s):
            break
        c = s[i]
        if c == 'C':
            ans += a
        elif c == 'A':
            a = 1
        else:
            a = 0
    elif c == 'C':
        a = 0
    i += 1
print(ans)

Submission status: Accepted

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

count = 0
a = 0
for si in list(new_s):
  if si == 'A':
    count += 1
  elif si == 'X':
    a += count
  else:
    count = 0
print(a)

Submission status: Accepted

Solution code:
from _collections import deque


def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number)


input_parser = parser()


def gw():
    global input_parser
    return next(input_parser)


def gi():
    data = gw()
    return int(data)


MOD = int(1e9 + 7)

import numpy
import scipy
from collections import deque
from math import sqrt
from math import floor
#https://atcoder.jp/contests/agc034/tasks/agc034_b
#B - ABC 
"""
need to consider the case that ticket is not enough to lower everything
"""


def cost(d):
    tc = 0
    d_cnt = 0
    for c in d:
        if c == 'D':
            tc += d_cnt
        else:
            d_cnt += 1

    return tc


s = gw()
d = []
i = 0
ans = 0
while i < len(s):
    if (s[i] == 'A'):
        d.append(s[i])
        i += 1
    elif (s[i] == 'B' and (i + 1) < len(s) and s[i + 1] == 'C'):
        d.append('D')
        i += 2
    else:
        ans += cost(d)
        d = []
        i += 1

ans += cost(d)

print(ans)

Submission status: Accepted

Solution code:
s = input()
cnt = 0
flg = 0
ans = 0
for i in range(len(s)-1):
  if s[i] == "A":
    if flg == 0:
      cnt += 1
    else:
      cnt = 1
  elif s[i:i+2] == "BC":
    ans += cnt
    flg = 1
  elif flg == 1:
    flg = 0
    continue
  else:
    cnt = 0
print(ans)

Submission status: Accepted

Solution code:
s = input()
count = 0
s = s.replace('BC','X')
s = s.replace('B','Z').replace('C','Z')
s = s.split('Z')
for i in s:
    ac = 0
    for j in range(len(i)):
        if i[j] == 'A':
            ac += 1
        if i[j] == 'X':
            count += ac
print(count)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def main():
	S = input().rstrip()
	S = [s for s in S]

	# AABCBC = 4 (BCが2つ、その前にAが2つ) 2*2 = 4
	# ABCABC = 3 (1つのBCには前にAが1つ、もう1つは前にAが2つ) 2*1+1*1 = 3
	# => それぞれのBCの前にAがある数で回数が決まる！
	# f(x) = BCの前にあるAの数 * BCの数

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

if __name__ == '__main__':
	main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 1度`BC`を`D`に置き換えて操作を考える
S = input()

new_s = ""
pointa = 0
while pointa != len(S):
    if pointa == len(S) - 1:
        new_s += S[pointa]
        break
    if S[pointa] == "B" and S[pointa+1] == "C":
        new_s += "D"
        pointa += 2
    else:
        new_s += S[pointa]
        pointa += 1

# Dが出現した時、その直前に存在するAの回数だけ操作を行うことができる
count = 0
ans = 0
for i in range(len(new_s)):
    if new_s[i] == "D":
        ans += count
    elif new_s[i] == "A":
        count += 1
    else:
        count = 0
print(ans)

Submission status: Accepted

Solution code:
S = input()

NS = ""
i = 0
while i < len(S):
    if S[i] == "A":
        NS += "A"
    elif i + 1 < len(S) and S[i] == "B" and S[i + 1] == "C":
        NS += "X"
        i += 1
    else:
        NS += "Z"
    i += 1

NS = NS[::-1]
res = 0
pos = -1

for i, s in enumerate(NS):
    if pos != -1 and s == "A":
        res += i - pos
        pos += 1
    elif pos == -1 and s == "X":
        pos = i
    elif s == "Z":
        pos = -1

print(res)

Submission status: Accepted

Solution code:
s = input().strip()
x = [s[0]]
for i in range(1,len(s)):
    if s[i]=="C" and s[i-1]=="B":
        x.pop()
        x.append("T")
    else:
        x.append(s[i])
cnt = 0
ca = 0
for i in range(len(x)):
    if x[i]=="A":
        ca += 1
    elif x[i]=="T":
        cnt += ca
    elif x[i]=="B" or x[i]=="C":
        ca = 0
print(cnt)

Submission status: Accepted

Solution code:
import re

s = input()
ans = 0
s = s.replace("BC", "D")
L = re.split('[BC]', s)
for i in L:
  k = len(i)
  temp = 0
  for j in range(k):
    if i[k-1-j] == "D":
      temp += 1
    else:
      ans += temp
print(ans)

Submission status: Accepted

Solution code:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

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

S = str(input())
S = S.replace('BC', 'D')

ans = 0
a = 0
d = 0
flag = False
for s in S[::-1]:
    if s=='D':
        if a>=1:
            ans += a*d
            a = 0
        d += 1
        flag = True
    elif s=='A':
        if flag:
            a += 1
    else:
        ans += a*d
        a,d = 0,0
        flag = False
ans += a*d

print(ans)

Submission status: Accepted

Solution code:
s=input()
s=s.replace("BC","D")
s=s.replace("B"," ")
s=s.replace("C"," ")
s=list(s.split())
ans=0
for u in s:
    if u:
        u=list(u)
        count=0
        cnt=0
        for i in range(len(u)):
            if u[i]=="D":
                count+=i
                cnt+=1
        ans+=count-cnt*(cnt-1)//2
print(ans)

Submission status: Accepted

Solution code:
s = input()
ind = 0
len_s = len(s)
string = ""
cnt = 0
ans = 0
while ind < len_s:
    _s = s[ind]
    if _s == "A":
        cnt += 1
        ind += 1
    elif _s == "B" and ind + 1 < len_s and s[ind + 1] == "C":
        ind += 2
        ans += cnt
    else:
        cnt = 0
        ind += 1

print(ans)

Submission status: Accepted

Solution code:
S=input()
S=list(S.replace("BC","D"))
ans=0
count=0
for x in S:
  if x=="A":
    count+=1
  else:
    if x=="D":
      ans+=count
      continue
    else:
      count=0
print(ans)

Submission status: Accepted

Solution code:
def sol(S):
  N = len(S)
  nums = [0 for _ in range(N+1)]
  i = N-1
  while i >= 0:
    if S[i-1:i+1] == 'BC':
      nums[i-1] = nums[i+1] + 1
      nums[i] = nums[i+1] + 1
      i -= 2
    else:
      nums[i] = nums[i+1]
      i -= 1
  ans = 0
  for i, s in enumerate(S):
    if s == 'A':
      ans += nums[i]
  return ans

S = input()
ans = 0
N = len(S)
si, i = 0, 0
while i < N:
  if S[i] == 'A':
    i += 1
  elif S[i:i+2] == 'BC':
    i += 2
  else:
    ans += sol(S[si:i+1])
    si = i + 1
    i += 1
ans += sol(S[si:])
print(ans)

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
    elif c == 'A':
        acc += 1
    else:
        ans += acc
print(ans)

Submission status: Accepted

Solution code:
def resolve():
  s = input()
  s = s.replace('BC', 'D')
  s = s.replace('B', 'C')

  ans = 0
  count = 0
  for c in s:
    if c == 'C':
      count = 0
      continue
    if c == 'A':
      count += 1
    if c == 'D':
      ans += count

  print(ans)


if __name__ == "__main__":
  resolve()

Submission status: Accepted

Solution code:
s = input()

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

print(ans)

Submission status: Accepted

Solution code:
s=input().replace("BC","X")
ans=0
acc=0
for i in range(len(s)):
    if s[i]=="B" or s[i]=="C":
        acc=0

    elif s[i]=="A":
        acc+=1
    elif s[i]=="X":
        ans+=acc


print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
s = (stdin.readline().rstrip())
s = s.replace("BC","D")
ans = 0
acc = 0

for i in s:
    if i == "B" or i == "C":
        acc = 0
        continue
        
    if i == "A":
        acc += 1
    
    if i == "D":
        ans += acc

print(ans)

Submission status: Accepted

Solution code:
so=input()

s=""

N=len(so)
i=0
while i<N:
    if so[i]=="A":
        s=s+"A"
        i+=1
    elif so[i:i+2]=="BC":
        s=s+"B"
        i+=2
    elif so[i]=="C" or so[i]=="B":
        s=s+"D"
        i+=1

L=len(s)
f=False
cnt=0
a=0
for i in range(L):
    if s[i]=="A":
        f=True
        a+=1
    elif f and s[i]=="B":
        cnt+=a
    elif s[i]=="D":
        f=False
        a=0
print(cnt)

Submission status: Accepted

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

while pos < str_len:
    if s[pos] == "A":
        while pos < str_len and s[pos] == "A":
            seq_a += 1
            pos += 1
        if pos+1 < str_len and s[pos] == "B" and s[pos + 1] == "C":
            while pos < str_len and s[pos] == "B" and pos + 1 < str_len and s[pos + 1] == "C":
                seq_bc += 1
                pos += 2
            count += seq_a * seq_bc
            if pos < str_len and s[pos] != "A":
                seq_a = 0
            seq_bc = 0
        else:
            pos += 1
            seq_a = 0
    else:
        pos += 1
        seq_a = 0

print(count)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

S = rs()
S = S.replace('BC', 'D')
cnt_A = 0
answer = 0
for s in S:
    if s == 'A':
        cnt_A += 1
    elif s == 'D':
        answer += cnt_A
    else:
        cnt_A = 0
print(answer)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

S = list(rs())
cur = 'D'
answer = 0
A_cnt = 0
for s in S:
    if cur == 'A':
        if s == 'A':
            A_cnt += 1
        elif s == 'B':
            cur = s
        else:
            cur = 'D'
            A_cnt = 0
    elif cur == 'B':
        if s == 'A':
            A_cnt = 1
            cur = s
        elif s == 'B':
            A_cnt = 0
            cur = 'D'
        elif s == 'C':
            answer += A_cnt
            cur = s
        else:
            cur = 'D'
            A_cnt = 0
    elif cur == 'C':
        if s == 'A':
            A_cnt += 1
            cur = s
        elif s == 'B':
            cur = s
        else:
            cur = 'D'
            A_cnt = 0
    else:
        if s == 'A':
            A_cnt += 1
            cur = s
        else:
            A_cnt = 0
            cur = 'D'

print(answer)

Submission status: Accepted

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

while pos < str_len:
    if s[pos] == "A":
        while pos < str_len and s[pos] == "A":
            seq_a += 1
            pos += 1
        if pos + 1 < str_len and s[pos] == "B" and s[pos+1] == "C":
            while pos < str_len and s[pos] == "B" and pos + 1 < str_len and s[pos+1] == "C":
                seq_bc += 1
                pos += 2
            count += seq_a * seq_bc
            if pos < str_len and s[pos] != "A":
                seq_a = 0
            seq_bc = 0
        else:
            pos += 1
            seq_a = 0
    else:
        pos += 1
        seq_a = 0

print(count)

Submission status: Accepted

Solution code:
s = input()
pos = 0
cnt = 0
acnt = 0
if len(s) < 3:
    print(0)
else:
    while(True):
        if s[pos:pos+2] == "BC" and acnt > 0:
            pos += 2
            cnt += acnt
            # print(s, s[pos:pos+2], cnt, pos)
        else:
            if s[pos] == "A":
                acnt += 1
            else:
                acnt = 0
            pos += 1
        if pos >= len(s)-1:
            break
    print(cnt)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
s += "???"

i = 0
ans = 0

while i < n:
    abc = []
    if s[i] == "A":
        i += 1
        abc.append(0)
        while True:
            if s[i] == "A":
                i += 1
                abc.append(0)
            elif s[i:i+2] == "BC":
                i += 2
                ans += len(abc)
            else:
                break
    i += 1

print(ans)

Submission status: Accepted

Solution code:
w=input()
count=0
num=len(w)
w1=""
w+=" "
while count<num:
  if w[count]=="A":
    w1+="A"
    count+=1
  elif w[count]=="B":
    if w[count+1]=="C":
      w1+="D"
      count+=2
    else:
      w1+="B"
      count+=1
  else:
    w1+="C"
    count+=1
counta=0
ans=0
num=len(w1)
for i in range(num):
  if w1[i]=="A":
    counta+=1
  elif w1[i]=="D":
    ans+=counta
  else:
    counta=0
print(ans)

Submission status: Accepted

Solution code:
s=list(input())
n=len(s)
l=[]
i=0
while i<n:
    if i<n-1 and s[i]=='B' and s[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: Accepted

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

def main():
    s=input()
    s2=list(s.replace('BC','D'))
    N=len(s2)
    ans=0
    c=0
    for i in range(N):
        if s2[i]=='A':
            c+=1
        elif c!=0 and s2[i]=='D':
            ans+=c
        else:
            c=0
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S=input()
S=S.replace("BC","X")
# "X"の移動先
target=0
ans=0
for i in range(len(S)):
  if S[i]=="X":
    ans+=(i-target)
    target+=1
  elif S[i]!="A" and S[i]!="X":
    # A,X以外の文字より左には移動できないので、その右位置が移動可能な左端となる。
    target=i+1
print(ans)

Submission status: Accepted

Solution code:
S=input()
S=S.replace("BC","X")
target=0
ans=0
for i in range(len(S)):
  if S[i]=="X":
    ans+=(i-target)
    target+=1
  elif S[i]!="A" and S[i]!="X":
    target=i+1
print(ans)

Submission status: Accepted

Solution code:
s = list(input())

i = 0
bc = list("BC")

a_cnt = 0
res = 0
i = 0
while i <= len(s)-1:
  if s[i] == "A":
    a_cnt += 1
  elif s[i:i+2] == bc:
    res += a_cnt
    i += 1
  else:
    a_cnt = 0
  i += 1

print(res)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
import sys
import bisect
import math
import itertools
import string
import queue
import copy
from heapq import heappop, heappush
#input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7

def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return sorted([list(map(int, input().split())) for _ in range(n)])
def sortx(x,n,k):
    if k == 0:x.sort(key=lambda y:y[1,n])
    else:x.sort(reversed=True, key=lambda y:y[1,n])
def graph():
    n=inp()
    g=[[] for _ in range(n)]
    for i in range(n):
        a=inp()
        a-=1
        g[i].append(a)
        g[a].append(i)
    return n,g
def graphm():
    n,m=inpm()
    g=[[] for _ in range(n)]
    for _ in range(m):
        a,b,w=inpm()
        a-=1
        b-=1
        g[a].append((b,w))
        g[b].append((a,w))
    return n,m,g

def dijkstra(s,n,g): # sからの最短距離 頂点数n
    s -= 1
    que = []
    d = [10**15 for _ in range(n)]
    d[s] = 0
    heappush( que,(0,s) )
    while len(que)>0:
        p =  heappop(que)
        v = p[1]
        if d[v] < p[0]:
            continue
        for i in range(len(g[v])):
            edge = g[v][i]
            if d[edge[0]] > d[v] + edge[1]:
                d[edge[0]] = d[v] + edge[1]
                heappush( que,(d[edge[0]] , edge[0]) )
    return d

def main():
    s=input()
    n=len(s)
    cnt_a=0
    cnt_b=0
    cnt=0
    ans=0
    for i in range(n):
        if s[i]=="A":
            cnt_a+=1
        elif i<n-1 and s[i:i+2]=="BC":
            cnt_b+=1
            cnt+=cnt_a
        elif 0<i and s[i-1:i+1]=="BC":
            continue
        else:
            ans+=cnt
            cnt=0
            cnt_a=0
            cnt_b=0
    ans+=cnt
    print(ans)
    
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors


s = input()
#a = list(map(int, input().split()))

mode=0
ans=0
anum=0
banum=0
for i in range(len(s)):
    if(mode==0 and s[i]=='A'):
        anum+=1
    elif(mode==1 and s[i]=='A'):
        anum=1
        mode=0
    elif(mode==0 and s[i]=='B'):
        mode=1
    elif(mode==1 and s[i]=='B'):
        mode=0
        anum=0
    elif(mode==0 and s[i]=='C'):
        mode=0
        anum=0
    elif(mode==1 and s[i]=='C'):
        mode=0
        ans += anum
    #print(ans)

print(ans)

Submission status: Accepted

Solution code:
from collections import deque
import heapq

s = input()
s += " "

S = ""

for i in range(len(s)-1):
    if s[i] == "B" and s[i+1] == "C":
        S += "Z"

    elif i > 0 and s[i] == "C" and s[i-1] == "B":
        continue
    else:
        S += s[i]

#print (S)
la = deque([])
ans = 0
for i in range(len(S)):

    if S[i] == "A":
        la.append(i)

    elif S[i] == "Z" and len(la) > 0:
        lastA = la.popleft()
        ans += i - lastA
        la.append(i)

    else:
        la = deque([])

print (ans)

Submission status: Accepted

Solution code:
import re


def main():
    s = input().replace('BC', 'X')
    S = re.split('[BC]', s)
    answer = 0

    for i in S:
        tmp = 0
        for j in i:
            if j == 'A':
                tmp += 1
            else:
                answer += tmp

    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import re

s = input().replace('BC', 'X')

S = re.split('[BC]', s)
answer = 0

for i in S:
    tmp = 0
    for j in i:
        if j == 'A':
            tmp += 1
        elif j == 'X':
            answer += tmp

print(answer)

Submission status: Accepted

Solution code:
s = input()
s_= s.replace("A", "0").replace("BC", "1").replace("B", "2").replace("C", "2")
s_012 = list(map(int, list(s_)))
count = 0
i = 0
ans = 0
while i < len(s_012):
    if s_012[i] == 0:
        count += 1
    elif s_012[i] == 1:
        ans += count
    else:
        count = 0
    i += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
a_count = 0
for s in S:
    if s == 'A':
        a_count += 1

    elif s == '>':
        ans += a_count

    else:
        a_count = 0

print(ans)

Submission status: Accepted

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

tmp = 0
ans = 0
for s in S:
    if s == 'A':
        tmp += 1
    elif s == 'D':
        ans += tmp
    else:
        tmp = 0
print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd
from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7


def main():
    s = input()
    s = s.replace("BC", "P")
    s = s.replace("B", "T")
    s = s.replace("C", "T")
    s = s.split("T")
    ans = 0
    for ss in s:
        p = 0
        for i in range(len(ss) - 1, -1 ,-1):
            if ss[i] == 'P':
                p += 1
            elif ss[i] == 'A':
                ans += p
    print(ans)





    


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s=list(input())
l=[]
f=0
for i in range(len(s)-1):
    if s[i]=="A":
        l.append("A")
        f=0
    elif s[i]=="B":
        if s[i+1]=="C":
            l.append("D")
            f=1
        else:
            l.append("B")
            f=0
    else:
        if f:
            f=0
            continue
        else:
            l.append("C")
ac=0
ans=0
for i in range(len(l)):
    if l[i]=="A":
        ac+=1
    elif l[i]=="D":
        ans+=ac
    else:
        ac=0
print(ans)