Problem:


Score : 600 points

Problem Statement

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

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

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

Find the maximum possible number of operations.

Constraints

1 \leq |s| \leq 200000

Each character of s is A, B and C.

Input

Input is given from Standard Input in the following format:

s

Output

Find the maximum possible number of operations.

Sample Input 1

ABCABC

Sample Output 1

3

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

Sample Input 2

C

Sample Output 2

0

Sample Input 3

ABCACCBABCBCAABCB

Sample Output 3

6



Sample input:
ABCABC


Sample output:
3

Submission status: Wrong Answer

Solution code:
s = input()
l = len(s)
t = [0]*l
c=0
ch=0
for i in range(l):
    if s[l-1-i]=='C' and c == 0:
        c=1
    elif s[l-i-1]=='B' and c == 1:
        c=0
        ch+=1
    elif s[l-i-1]=='A' and c == 1:
        c=0
        ch = 0
    elif s[l-i-1]=='A':
        c=0
    else:
        ch=0
        c=0
    t[l-i-1]=ch
ans = 0
for i in range(l):
    if s[i]=='A':
        ans += t[i]
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

s = list(input())
chain = {}
abcs = []
kugiri = 0
for i in range(1,len(s)):
    if not((s[i] == "B" and s[i-1] == "C") or (s[i] == "B" and s[i-1] == "A") or (s[i] == "C" and s[i-1] == "B") or (s[i] == "A" and s[i-1] == "C") or (s[i] == "A" and s[i-1] == "A")):
        chain["".join(s[kugiri:i])] = abcs
        abcs = []
        kugiri = i
    if s[i] == "C" and s[i-1] == "B":
        abcs.append(i-kugiri)
chain["".join(s[kugiri:len(s)])] = abcs

ans = 0
for key, value in chain.items():
    for x in value: 
        ans += Counter(key[:x])["A"]
print(ans)

Submission status: Wrong Answer

Solution code:
def main():

    s = list(input())
    ans = 0
    h = 0
    i = 0
    while i < len(s):
        if s[i] == "A":
            h += 1
            # print(i, h, s)
            if s[i:i+3] == ["A", "B", "C"]:
                ans += h
                h = 0
                i += 2
                s[i] = "A"
            else:
                i += 1
        else:
            h = 0
            i += 1
    return ans

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

Submission status: Wrong Answer

Solution code:
s = input()
l = len(s)
if l < 3:
  print(0)
  exit()
  
a = 0
abc = False
b = False
c = False
bc = 0
chk = set()
for i in range(l-2):
  if s[i]=='A' and s[i+1]=='B' and s[i+2]=='C':
    chk.add(i)
    
cnt = 0
ans = 0
for i,si in enumerate(s):
  if cnt > 0:
    cnt -= 1
    continue
  if not i in chk and not abc:
    if si == 'A':
      a += 1
    else:
      a = 0
  elif i in chk:
    p = a+1
    ans += p
    bc = 0
    abc = True
    c = True
    a += 1
    cnt = 2
    #print(ans,p)
  elif abc:
    if c and si=='A':
      abc = False
      b = False
      c = False
      a += 1
      #print(ans)
    elif b and si=='A':
      abc = False
      b = False
      c = False
      a = 1      
    elif c and si=='B':
      b = True
      c = False
    elif c and si=='C':
      abc = False
      c = False
      a = 0
    elif b and si=='B':
      b = False
      abc = False
      a =  0
    elif b and si=='C':
      ans += p
      b = False
      c = True
      
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
l = len(s)
if l < 3:
  print(0)
  exit()
  
a = 0
abc = False
b = False
c = False
chk = set()
for i in range(l-2):
  if s[i]=='A' and s[i+1]=='B' and s[i+2]=='C':
    chk.add(i)
    
cnt = 0
ans = 0
for i,si in enumerate(s):
  if cnt > 0:
    cnt -= 1
    continue
  if not i in chk and not abc:
    if si == 'A':
      a += 1
    else:
      a = 0
  elif i in chk:
    ans += a+1
    a = 1
    abc = True
    c = True
    cnt = 2
  elif abc:
    if si=='A':
      abc = False
      b = False
      c = False
      a += 1
    elif c and si=='B':
      b = True
      c = False
      a = 0
    elif c and si!='B':
      abc = False
      c = False
      a = 0
    elif b and si!='C':
      b = False
      abc = False
      a = 0
    elif b and si=='C':
      ans += 1
      a = 1
      b = False
      c = True
      
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
l = len(s)
if l < 3:
  print(0)
  exit()
  
a = 0
abc = False
b = False
c = False
chk = set()
for i in range(l-2):
  if s[i]=='A' and s[i+1]=='B' and s[i+2]=='C':
    chk.add(i)
    
cnt = 0
ans = 0
for i,si in enumerate(s):
  if cnt > 0:
    cnt -= 1
    continue
  if not i in chk and not abc:
    if si == 'A':
      a += 1
    else:
      a = 0
  elif i in chk:
    ans += a+1
    a = 1
    abc = True
    c = True
    cnt = 2
  elif abc:
    if si=='A':
      abc = False
      b = False
      c = False
      a += 1
    elif c and si=='B':
      b = True
      c = False
    elif c and si!='B':
      abc = False
      c = False
    elif b and si!='C':
      b = False
      abc = False
    elif b and si=='C':
      ans += 1
      a = 1
      b = False
      c = True
      
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    S = input()

    flag_C = False
    flag_BC = False
    flag_calc = False
    A_count = 0
    A = []
    ans = 0
    for i, c in enumerate(S[::-1]):
        if flag_BC:
            if c == "A":
                A_count += 1
            elif not flag_C:
                A.append(A_count)
                A_count = 0


            if flag_C:
                if c == "B":
                    flag_C = False
                else:
                    flag_BC = False
                    flag_calc = True
            else:
                if c == "B":
                    if flag_C:
                        flag_C = False
                    else:
                        flag_BC = False
                        flag_calc = True
                elif c == "C":
                    flag_C = True
        
        elif flag_C:
            if c == "B":
                flag_BC = True
                flag_C = False
            else:
                flag_C = False
                flag_BC = False
                flag_calc = True

        
        if c == "C":
            flag_C = True
        

        if i == len(S) - 1:
            A.append(A_count)
            flag_calc = True

        if flag_calc:
            cusum = [0] * (len(A)+1)
            for i, a in enumerate(A[::-1]):
                cusum[i+1] +=  cusum[i] + a
            ans += sum(cusum)
            A = []
        
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

a_cnt = 0
i = 0
ans = 0
while i + 2 <= ln:
    if s[i:i+2] == "BC" and a_cnt > 0:
        ans += a_cnt
        i += 2
        a_cnt = 1
        continue

    if s[i] == "A":
        a_cnt += 1

    else:
        a_cnt = 0

    i += 1

print(ans)

Submission status: Wrong Answer

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

abc = ["A", "B", "C"]
bca = ["B", "C", "A"]

ans = 0
for i in range(ln - 2):
    if s[i:i+3] == abc:
        s[i:i+3] = bca
        ans += 1
        j = i - 1
        while j >= 0 and s[j] == abc:
            s[j:j+3] = bca
            ans += 1
            j -= 1

print(ans)

Submission status: Wrong Answer

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

abc = ["A", "B", "C"]
bca = ["B", "C", "A"]

ans = 0
for i in range(ln - 2):
    if s[i:i+3] == abc:
        s[i:i+3] = bca
        ans += 1
        j = i - 1
        while j >= 0 and s[j] == "A":
            ans += 1
            j -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
S = list(input())
N = len(S)
cnt = 0
flg = 1


for _ in range(3):
    for i in range(N-2):
        if S[i] == 'A' and S[i+1] == 'B' and S[i+2] == 'C':
            cnt += 1
            S[i] = 'B'
            S[i+1] = 'C'
            S[i+2] = 'A'
print(cnt)

Submission status: Wrong Answer

Solution code:
s = input()

s = s.replace('ABC','X')
s = s.replace('BC','Y')

a = 0
x = 0
y = 0
ans = 0
phs = 0

#print(s)

for i in range(len(s)):
    if s[i] == 'X':
       if phs == 'y':
           ans += 1
           #y = 0
       ans += a
       ans += y
       y = 0
       a = 0
       x += 1
       phs = 'x'
    elif s[i] == 'A':
        if phs == 'y':
            ans += 1
        a += 1
        ans += y
        y = 0
        x = 0
        phs = 'a'
    elif s[i] == 'Y':
        a = 0
        x = 0
        if phs == 'x':
            y = 1
            phs = 'y'
        elif phs == 'y':
            y += 1
        else:
            y = 0
    else:
        ans += y
        x = 0
        y = 0
        a = 0
    
            
    #print(a,x,y)
ans += y
x = 0

for i in range(len(s)):
    if s[i] == 'X':
        x += 1
    else:
        ans += x*(x+1)//2
        x = 0

ans += (x+1)*x//2

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()

s = s.replace('ABC','X')
s = s.replace('BC','Y')

a = 0
x = 0
y = 0
ans = 0
phs = 0

#print(s)

for i in range(len(s)):
    if s[i] == 'X':
       if phs == 'y':
           ans += 1
           #y = 0
       ans += a
       ans += y
       y = 0
       a = 0
       x += 1
       phs = 'x'
    elif s[i] == 'A':
        if phs == 'y':
            ans += 1
        a += 1
        ans += y
        y = 0
        x = 0
        phs = 'a'
    elif s[i] == 'Y':
        a = 0
        if phs == 'x':
            y = 1
            phs = 'y'
        elif phs == 'y':
            y += 1
        else:
            y = 0
    else:
        x = 0
        y = 0
        a = 0
    
            
    #print(a,x,y)
ans += y
x = 0

for i in range(len(s)):
    if s[i] == 'X':
        x += 1
    else:
        ans += x*(x+1)//2
        x = 0

ans += (x+1)*x//2

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()

s = s.replace('ABC','X')
s = s.replace('BC','Y')

a = 0
x = 0
y = 0
ans = 0
phs = 0

#print(s)

for i in range(len(s)):
    if s[i] == 'X':
       if phs == 'y':
           ans += 1
           #y = 0
       ans += a
       ans += y
       y = 0
       a = 0
       x += 1
       phs = 'x'
    elif s[i] == 'A':
        a += 1
        ans += y
        y = 0
        x = 0
        phs = 'a'
    elif s[i] == 'Y':
        a = 0
        if phs == 'x':
            y = 1
            phs = 'y'
        elif phs == 'y':
            y += 1
        else:
            y = 0
            
    #print(a,x,y)
ans += y
x = 0

for i in range(len(s)):
    if s[i] == 'X':
        x += 1
    else:
        ans += x*(x+1)//2
        x = 0

ans += (x+1)*x//2

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()

s = s.replace('ABC','X')
s = s.replace('BC','Y')

a = 0
x = 0
y = 0
ans = 0
phs = 0

#print(s)

for i in range(len(s)):
    if s[i] == 'X':
       if phs == 'y':
           ans += 1
           y = 0
       ans += a
       ans += y
       y = 0
       a = 0
       x += 1
       phs = 'x'
    elif s[i] == 'A':
        a += 1
        ans += y
        y = 0
        x = 0
        phs = 'a'
    elif s[i] == 'Y':
        a = 0
        if phs == 'x':
            y = 1
            phs = 'y'
        elif phs == 'y':
            y += 1
        else:
            y = 0
            
    #print(a,x,y)
ans += y
x = 0

for i in range(len(s)):
    if s[i] == 'X':
        x += 1
    else:
        ans += x*(x+1)//2
        x = 0

ans += (x+1)*x//2

print(ans)

Submission status: Wrong Answer

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

cnt=0
ans=0

for i in range(n-1):
    if s[i]=="A":
        cnt+=1
    elif s[i:i+2]=="BC":
        ans+=cnt
    else:
        cnt=0

print(ans)

Submission status: Wrong Answer

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

cnt=0
ans=0

for i in range(n-2):
    if s[i]=="A":
        cnt+=1
    elif s[i:i+2]=="BC":
        ans+=cnt
    elif i>0 and s[i-1:i+1]=="BC":
        pass
    else:
        cnt=0

print(ans)

Submission status: Wrong Answer

Solution code:
s = list(input())
if len(s) <= 2:
    print(0)
else:
    ans = 0
    i = 2
    while i < len(s):
        if s[i] == "C" and s[i-1] == "B" and s[i-2] == "A":
            j = i-2
            a_count = 0
            while j >= 0:
                if s[j] == "A":
                    ans += 1
                    j -= 1
                    a_count += 1
                else:
                    break
            j = 1
            for _ in range(a_count):
                s[i-j+1] = "A"
                j += 1
            s[i-j-1] = "C"
            i += 2
        else:
            i += 1
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

s = s.replace("BC","X")
s += "DD"
nn = len(s)

alen = 0
xlen = 0
ans = 0
for i in range(nn):
    if s[i] == "A":
        alen += 1
    elif s[i] == "X":
        xlen += 1
        if s[i+1] == "A":
            ans += xlen * alen
            alen,xlen = 0,0
    else:
        ans += alen * xlen
        alen,xlen = 0,0

ss = []
ss.append(s[0])
for i in range(nn-1):
    if s[i+1] == s[i]:
        continue
    else:
        ss.append(s[i+1])
        
ss = "".join(ss)
ss = ss.replace("AX","P")
for i in range(len(ss)-1):
    if ss[i] == "P" and ss[i+1] == "P":
        ans += 1
        
print(ans)

Submission status: Wrong Answer

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

s = s.replace("BC","X")
s += "DD"
nn = len(s)

alen = 0
xlen = 0
ans = 0
for i in range(nn-1):
    if s[i] == "A":
        alen += 1
    elif s[i] == "X":
        xlen += 1
        if s[i+1] == "A":
            ans += xlen * alen
            alen,xlen = 0,0
    else:
        ans += alen * xlen
        alen,xlen = 0,0

ss = []
ss.append(s[0])
for i in range(nn-1):
    if s[i+1] == s[i]:
        continue
    else:
        ss.append(s[i+1])
        
ss = "".join(ss)
ss = ss.replace("AX","P")
for i in range(len(ss)-1):
    if ss[i] == "P" and ss[i+1] == "P":
        ans += 1
        
print(ans)

Submission status: Wrong Answer

Solution code:
string = input()

def countABC(string):
  tmp = ""
  i = 0
  count = 0
  subtract = 0
  for x in string:
    # print(tmp, i)
    tmp += x
    if len(tmp) == 3:
      if tmp == "ABC":
        count += 1
        tmp = ""
      elif tmp != "BCA":
        tmp = tmp[1:]
    elif len(tmp) == 5:
      count += 1
      if tmp == "BCABC":
        tmp = ""
      else:
        subtract += 1
        tmp = tmp[3:]
    i += 1
  return count, subtract

def sol(n):
  if n==0:
    return 0
  r = 1
  i = 2
  while n > 1:
    r += i
    i += 1
    n -= 1
  return r

c, s = countABC(string)
r = sol(c) - s
print(r)

Submission status: Wrong Answer

Solution code:
string = input()

def countABC(string):
  tmp = ""
  i = 0
  count = 0
  subtract = 0
  for x in string:
    # print(tmp, i)
    tmp += x
    if len(tmp) == 3:
      if tmp == "ABC":
        count += 1
        tmp = ""
      elif tmp == "BCA":
        count += 1
        tmp = ""
        subtract += 1
      else:
        tmp = tmp[1:]
    i += 1
  return count, subtract

def sol(n):
  if n==0:
    return 0
  r = 1
  i = 2
  while n > 1:
    r += i
    i += 1
    n -= 1
  return r

c, s = countABC(string)
r = sol(c) - s
print(r)

Submission status: Wrong Answer

Solution code:
string = input()

def countABC(string):
  tmp = ""
  i = 0
  count = 0
  for x in string:
    # print(tmp, i)
    tmp += x
    if len(tmp) == 3:
      if tmp == "ABC":
        count += 1
        tmp = ""
      else:
        tmp = tmp[1:]
    i += 1
  return count

def sol(n):
  if n==0:
    return 0
  r = 1
  i = 2
  while n > 1:
    r += i
    i += 1
    n -= 1
  return r

c = countABC(string)
r = sol(c)
print(r)

Submission status: Wrong Answer

Solution code:
string = input()

def countABC(string):
  tmp = ""
  i = 0
  count = 0
  for x in string:
    # print(tmp, i)
    tmp += x
    if len(tmp) == 3:
      if tmp == "ABC":
        count += 1
        tmp = ""
      else:
        tmp = tmp[1:]
    i += 1
  return count

def sol(n):
  r = 1
  i = 2
  while n > 1:
    r += i
    i += 1
    n -= 1
  return r

c = countABC(string)
r = sol(c)
print(r)

Submission status: Wrong Answer

Solution code:
s = list(input())
t = []
ls = len(s)
for i in range(ls):
    if s[i] == "A":
        t.append("A")
    elif s[i] == "B":
        if not i == ls - 1:
            if s[i + 1] == "C":
                t.append("D")
            else:
                t.append("B")
    else:
        if not i == 0:
            if not s[i - 1] == "B":
                t.append("C")
t = "".join(t).split("B")
t = "".join(t).split("C")
ans = 0
for u in t:
    dcnt = 0
    u = list(u)
    for i in range(len(u)):
        if u[i] == "D":
            ans += (i - dcnt)
            dcnt += 1
print(ans)

Submission status: Wrong Answer

Solution code:
# map(int, input().split())
# list(map(int, input().split()))
# for _ in range(int(input())):
# print(' '.join([str(x) for x in ans]))

s = input()

numBC = 0
total = 0
i = len(s)-1
while i >= 0:    
    if s[i] == 'A':
        total += numBC
    elif s[i] == 'C':
        if (i > 0 and s[i-1] == 'B'):
            numBC += 1
            i -= 1
    else:
        numBC = 0
    i-=1

print(total)

Submission status: Wrong Answer

Solution code:
s = input()
cnt = 0
ac = 0
bc = 0 
cc = 0
for i in range(len(s)):
  if s[i] == "A":
    bc = 0 
    cc = 0
    ac += 1
  if s[i] == "B":
    if bc == 1 or cc == 1:
      ac = 0
    bc = 1
    cc =0
  if s[i] == "C":
    if bc == 0 and ac > 0:
      ac = 0
      cc = 1
    if cc == 1:
      ac = 0
      cc = 1   
    if bc == 1:
      cnt += ac
      bc = 0
      if ac >0:
        cc = 0
      else:
        cc = 1
print(cnt)

Submission status: Wrong Answer

Solution code:
s = input()
cnt = 0
ac = 0
bc = 0 
cc = 0
for i in range(len(s)):
  if s[i] == "A":
    bc = 0 
    cc = 0
    ac += 1
  if s[i] == "B":
    if bc == 1 or cc == 1:
      ac = 0
    bc = 1
    cc =0
  if s[i] == "C":
    if bc == 0 and ac > 0:
      ac = 0
      cc = 1
    if cc == 1:
      ac = 0
      cc = 1   
    if bc == 1:
      cnt += ac
      bc = 0
      cc = 0
print(cnt)

Submission status: Wrong Answer

Solution code:
s = input()
cnt = 0
ac = 0
bc = 0 
cc = 0
for i in range(len(s)):
  if s[i] == "A":
    bc = 0 
    cc = 0
    ac += 1
  if s[i] == "B":
    if bc == 1 or cc == 1:
      ac = 0
    bc = 1
    cc =0
  if s[i] == "C":
    if bc == 0 and ac > 0:
      ac = 0
      cc = 1
    if cc == 1:
      ac = 0
    cc = 1   
    if bc == 1:
      cnt += ac
      bc = 0
      cc = 0
print(cnt)

Submission status: Wrong Answer

Solution code:
s = input()
cnt = 0
ac = 0
bc = 0 
cc = 0
for i in range(len(s)):
  if s[i] == "A":
    bc = 0 
    cc = 0
    ac += 1
  if s[i] == "B":
    if bc == 1 or cc == 1:
      ac = 0
    bc = 1
    cc =0
  if s[i] == "C":
    if cc == 1:
      ac = 0
    cc = 1   
    if bc == 1:
      cnt += ac
      bc = 0
      cc = 0
print(cnt)

Submission status: Wrong Answer

Solution code:
s=input()
t=0
l=len(s)
a=0
g=-10
while t+3<=l:
    if s[t:t+3]!="ABC":
        t+=1
        continue
    i=t-1
    while i>=0:
        if s[i]=="A":
            a+=1
            i-=1
        else:
            break
    if i+1==g:
        a+=1
    t+=3
    k=1
    while t+3<=l:
        if s[t:t+3]!="ABC":
            break
        k+=1
        t+=3
    a+=k*(k+1)//2
    while t+2<=l:
        if s[t:t+2]!="BC":
            break
        t+=2
        a+=1
    g=t
print(a)

Submission status: Wrong Answer

Solution code:
s = input()
segments = []
i = 0
segment = []
while i < len(s):
    if s[i] == 'A':
        segment.append(s[i])
    elif i + 1 < len(s) and s[i] == 'B' and s[i + 1] == 'C':
        segment.append('BC')
        i += 1
    else:
        if segment:
            segments.append(segment)
        segment = []
    i += 1
if segment:
    segments.append(segment)

ans = 0
for segment in segments:
    left_bc_ind = 0
    exist_A = False
    for i, s in enumerate(segment):
        if s == 'A':
            exist_A = True
        elif s == 'BC' and exist_A:
            ans += (i - left_bc_ind)
            left_bc_ind += 1
print(ans)

Submission status: Wrong Answer

Solution code:
t=input().replace("ABC","T")
s=t.replace("BC","Z")
l=[]
flagA=False
cntA=0
cnt=0
count=0
flag=False
comb=False
cmcnt=0
tmp=0
#print(s)
for i in range(len(s)):


    if s[i]=="T":
        if comb:
            cmcnt=1
        count+=1
        flag=True
        if flagA:
            flagA=False
            cntA=tmp
        continue

    if flag:
        if s[i]=="Z":
            cnt+=1
        else:
            l.append([cmcnt,cntA,count,cnt])
            comb=True
            flag=False
            flagA=False
            cnt=0
            count=0
            cntA=0
            if s[i]=="A":
                tmp+=1
                flagA=True
    else:
        if s[i]=="A":
            tmp+=1
            flagA=True
        else:
            tmp=0
            comb=False
ans=0
if count>0:
    l.append([cmcnt,cntA,count,cnt])
#print(l)
for i in range(len(l)):
    ans+=l[i][0]
    ans+=l[i][1]
    ans+=(l[i][2]*(l[i][2]+1))//2
    ans+=l[i][3]
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    S = input().strip()
    a_cnt = 0
    state = 0
    ans = 0
    for s in S:
        if s == 'A':
            a_cnt += 1
            state = 0
        elif s == 'B':
            if state == 0:
                state = 1
            else:
                a_cnt = 0
                state = 0
        elif s == 'C':
            if state == 1:
                ans += a_cnt
                state = 0
            else:
                a_cnt = 0

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    S = input().strip()
    a_cnt = 0
    state = 0
    ans = 0
    for s in S:
        if s == 'A':
            a_cnt += 1
            state = 0
        elif s == 'B':
            if state == 0:
                state = 1
            else:
                ans = 0
                state = 0
        elif s == 'C':
            if state == 1:
                ans += a_cnt
                state = 0
            else:
                a_cnt = 0

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    S = input().strip()
    a_cnt = 0
    state = 0
    ans = 0
    for s in S:
        if s == 'A':
            a_cnt += 1
            state = 0
        elif s == 'B':
            state = 1
        elif s == 'C':
            if state == 1:
                ans += a_cnt
                state = 0
            else:
                a_cnt = 0

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

c = 0
if l < 3:
	print(0)
	exit()
for i in range(l-3,-1,-1):
	if t[i] == "A" and t[i+1] == "B" and t[i+2] == "C":
		c += 1
		t[i],t[i+1],t[i+2] = "B","C","A"
for i in range(l-2):
	if t[i] == "A" and t[i+1] == "B" and t[i+2] == "C":
		c += 1
		t[i],t[i+1],t[i+2] = "B","C","A"
print (c)

Submission status: Wrong Answer

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

c = 0
if l < 3:
	print(0)
	exit()
for i in range(l-2):
	if t[i] == "A" and t[i+1] == "B" and t[i+2] == "C":
		c += 1
		t[i],t[i+1],t[i+2] = "B","C","A"
flg = 0
for i in range(l-3,-1,-1):
	if flg == 1:
		if t[i] == "A":
			c += 1
		else:
			flg = 0
	if t[i] == "A" and t[i+1] == "B" and t[i+2] == "C":
		c += 1
		flg = 1
print (c)

Submission status: Wrong Answer

Solution code:
s = input()
s = s.replace("ABC","x").replace("BC","y")
ans = s.count("x")
for i in range(len(s)-1):
    if s[i] == "x" and s[i+1] == "y":
        ans += 1
    if s[i] == "A" and s[i+1] == "x":
        ans += 1
    if s[i] == "x" and s[i+1] == "x":
        ans += 1
print(ans)

Submission status: Wrong Answer

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

ans = 0
cnt = 0
for i in range(n-3+1):
    if s[i] == 'A':
        cnt += 1
    else:
        cnt = 0
    if s[i] == 'A' and s[i+1] == 'B' and s[i+2] == 'C':
        ans += 1
        if i+5 <= n-1:
            if s[i+3] == 'A' and s[i+4] == 'B' and s[i+5] == 'C':
                ans += 2
                s[i+3] = 'C'
                s[i+4] = 'A'
                s[i+3] = 'A'
        if i+4 <= n-1:
            if s[i+3] == 'B' and s[i+4] == 'C':
                ans += 1
                s[i+3] = 'C'
                s[i+4] = 'A'
        ans += cnt-1

print(ans)

Submission status: Wrong Answer

Solution code:
s =input()
n = len(s)
ans  = 0
cnt = 0
pre = s[0]
for i in range(n):
    if s[i] == "A":
        cnt+=1

    elif s[i] =="C":
        if pre == "B":
            ans += cnt
        else:cnt = 0
    elif s[i] == "B":
        if pre == "B":cnt = 0
    pre = s[i]
print(ans)

Submission status: Wrong Answer

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

ans = 0
for i in range(n-3+1):
    if s[i] == 'A' and s[i+1] == 'B' and s[i+2] == 'C':
        ans += 1
    if i+5 <= n-1:
        if s[i+3] == 'A' and s[i+4] == 'B' and s[i+5] == 'C':
            ans += 2
            s[i+3] = 'C'
            s[i+4] = 'A'
            s[i+3] = 'A'
    if i+4 <= n-1:
        if s[i+3] == 'B' and s[i+4] == 'C':
            ans += 1
            s[i+3] = 'C'
            s[i+4] = 'A'
print(ans)

Submission status: Wrong Answer

Solution code:
s = str(input())

ans = 0
for i in range(100):
    t = s.count('ABC')
    if t == 0:
        break
    ans += t
    s = s.replace('ABC', 'BCA')
print(ans)

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

s = STR()
a = []
i = 0
while i < len(s):
    if s[i] == 'A':
        a.append(0)
        i += 1
    elif i < len(s) - 1 and s[i:i + 2] == 'BC':
        a.append(1)
        i += 2
    else:
        a.append(2)
        i += 1
debug(a)
ans = 0
for i in reversed(range(1, len(a))):
    if a[i] == 1 and a[i - 1] == 0:
        ans += 1
        a[i], a[i - 1] = a[i  - 1], a[i]
for i in range(1, len(a)):
    if a[i] == 1 and a[i - 1] == 0:
        ans += 1
        a[i], a[i - 1] = a[i  - 1], a[i]
print(ans)

Submission status: Wrong Answer

Solution code:
# BCが左に移動してAが右に詰められるって感じにすると、移されたAはそれまで後ろに続いていたBCBC..のセットぶんだけ移動できるのでうれしい
s = input()
ans = 0
idx = len(s) - 2
bc_sequencies = 0
while idx >= 0:
    if s[idx] == "B" and s[idx + 1] == "C":
        if idx >= 2:
            if s[idx - 2] == "B" and s[idx - 1] == "C":
                idx -= 2
                bc_sequencies += 1
            elif s[idx - 1] == "A":
                ans += 1 + bc_sequencies
                bc_sequencies = 1
                idx -= 1
            else:
                idx -= 1
        else:
            if s[idx - 1] == "A":
                ans += 1 + bc_sequencies
                bc_sequencies = 1
            idx -= 1
    else:
        idx -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
# BCが左に移動してAが右に詰められるって感じにすると、移されたAはそれまで後ろに続いていたBCBC..のセットぶんだけ移動できるのでうれしい
s = input()
ans = 0
idx = len(s) - 2
bc_sequencies = 0
while idx >= 0:
    if s[idx] == "B" and s[idx + 1] == "C":
        if idx >= 2:
            if s[idx - 2] == "B" and s[idx - 1] == "C":
                idx -= 2
                bc_sequencies += 1
            elif s[idx - 1] == "A":
                ans += 1 + bc_sequencies
                bc_sequencies = 1
                idx -= 1
            else:
                idx -= 1
        else:
            if s[idx - 1] == "A":
                ans += 1 + bc_sequencies
                bc_sequencies = 1
                idx -= 1
    else:
        idx -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
s = s.replace("BC", "D")
result = 0
i = 0
while i < len(s)-1:
    if s[i]=="A":
        y = 1
        for j in range(i+1, len(s)):
            if s[j]=="A":
                y += 1
            elif s[j]=="D":
                result += y
            else:
                break
        i += j
    else:
        i += 1
print(result)

Submission status: Wrong Answer

Solution code:
s = input()
s = s.replace("BC", "D")
result = 0
i = 0
s = s+"x"
while i < len(s)-1:
    if s[i]=="A":
        y = 1
        for j in range(i+1, len(s)):
            if s[j]=="A":
                y += 1
            elif s[j]=="D":
                result += y
            else:
                break
        i += j
    else:
        i += 1
print(result)

Submission status: Wrong Answer

Solution code:
s = input()
s = s.replace("BC", "D")
result = 0
i = 0
s = s+"x"
while i < len(s)-1:
    if s[i]=="A":
        x = 0
        y = 1
        for j in range(i+1, len(s)):
            if s[j]=="A":
                result += x*y
                x = 0
                y += 1
            elif s[j]=="D":
                x += 1
            else:
                result += x*y
                break
        i += j
    else:
        i += 1

print(result)