ZhenlongDai/ACPR huggingface dataset:
Problem: p03018
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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
                break
    else:
        i+=1
print(ans)

Failing test case input:
DBBBCCBAACBBABCCA

Expected output:
1


Actual output:
3


Fixed submission (verdict: Accepted):
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)

Problem: p03018
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = ['C']+list(input())
n = len(s)
res = 0
p = []

def f(p):
    if len(p) == 0:
        return 0
    cnt = 0
    ans = 0
    for e in p:
        if e == 'A':
            cnt += 1
        else:
            ans += cnt
    return ans

for i in range(1,n):
    if s[i] == 'A':
        p.append('A')
    elif s[i] == 'B':
        if s[i-1] == 'B':
            res += f(p)
            p = []
    else:
        if s[i-1] == 'B':
            p.append('B')
        else:
            res += f(p)
            p = []
res += f(p)
print(res)



Failing test case input:
ABDB@BBCAADCCCBBD

Expected output:
0


Actual output:
2


Fixed submission (verdict: Accepted):
s = ['C']+list(input())
n = len(s)
res = 0
p = []

def f(p):
    if len(p) == 0:
        return 0
    cnt = 0
    ans = 0
    for e in p:
        if e == 'A':
            cnt += 1
        else:
            ans += cnt
    return ans

for i in range(1,n):
    if s[i] == 'A':
        p.append('A')
    elif s[i] == 'B':
        if s[i-1] == 'B' or (i+1<=n-1 and s[i+1] != 'C'):
            res += f(p)
            p = []
    else:
        if s[i-1] == 'B':
            p.append('B')
        else:
            res += f(p)
            p = []
res += f(p)
print(res)
Problem: p03018
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
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
        Acnt = 1
        cnt = 1
    else:
        Acnt = 0
        cnt = 0
print(ans)

Failing test case input:
ACCAAABCAABCCBBBD

Expected output:
8


Actual output:
6


Fixed submission (verdict: Accepted):
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)

Problem: p03018
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    S = input().strip()

    lS = list(S)
    acnt = 0
    ans = 0
    for i in range(len(S) - 2):
        if lS[i] == "A":
            acnt += 1
        else:
            acnt = 0

        if lS[i] == "A" and lS[i + 1] == "B" and lS[i + 2] == "C":
            lS[i + 2] = "A"
            ans += acnt
            acnt = 0

    print(ans)



if __name__ == '__main__':
    main()


Failing test case input:
ACCAAABCAABCCBBBD

Expected output:
8


Actual output:
6


Fixed submission (verdict: Accepted):
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    S = input().strip()

    lS = list(S)
    acnt = 0
    ans = 0
    for i in range(len(S) - 2):
        if lS[i] == "A":
            acnt += 1
        else:
            acnt = 0

        if lS[i] == "A" and lS[i + 1] == "B" and lS[i + 2] == "C":
            ans += acnt
            lS[i + 2] = "A"
            if acnt > 1:
                lS[i + 1] = "A"
                acnt -= 2

    print(ans)



if __name__ == '__main__':
    main()

Problem: p03018
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
n = len(s)

ans = 0
cnt = 0

for i in range(n-1):
    if s[i] == "A":
        cnt += 1
    elif s[i]+s[i+1] == "BC":
        ans += cnt
    elif s[i]+s[i+1] in ("AC","BA","BB","CC"):
        cnt = 0
    
print(ans)

Failing test case input:
ACCAACBCAABCCBBBC

Expected output:
2


Actual output:
6


Fixed submission (verdict: Accepted):
s = input()
n = len(s)

ans = 0
cnt = 0

for i in range(n-1):
    if s[i] == "A":
        cnt += 1
    if s[i]+s[i+1] == "BC":
        ans += cnt
    if s[i]+s[i+1] in ("AC","BA","BB","CC"):
        cnt = 0

print(ans)
Problem: p03018
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()
ans = 0
bc = 0
for i in range(len(S) + 1):

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

Failing test case input:
ACBAACBCAABCCBBBC

Expected output:
2


Actual output:
8


Fixed submission (verdict: Accepted):
S = input()
ans = 0
bc = 0
reset = set(['AC','BA','BB','CC'])
for i in range(len(S) + 1):

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

Problem: p03018
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    s = list(input().rstrip())
    ans = 0
    cnt = 0
    for i in range(len(s)-2):
        if s[i] == "A":
            cnt += 1
        else:
            cnt = 0
        if s[i] == "A" and s[i+1] == "B" and s[i+2] == "C":
            ans += cnt
            cnt = 1
            s[i+2] = "A"
    print(ans)

if __name__ == "__main__":
    main()

Failing test case input:
ACCAAABCAABCCBBBC

Expected output:
8


Actual output:
6


Fixed submission (verdict: Accepted):
def main():
    s = list(input().rstrip())
    ans = 0
    cnt = 0
    for i in range(len(s)-2):
        if s[i] == "A":
            cnt += 1
        else:
            cnt = 0
        if s[i] == "A" and s[i+1] == "B" and s[i+2] == "C":
            ans += cnt
            if cnt == 1:
                s[i+2] = "A"
                cnt = 0
            else:
                s[i+1] = "A"
                s[i+2] = "A"
                cnt -= 2
    print(ans)

if __name__ == "__main__":
    main()

Problem: p03018
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
s=list(input())
n=len(s)
amount=0
t=0
b=0
bc=0
for i in range(n):
    if s[i]=='A':
        t += 1
        b=0
    elif s[i]=='B':
        if b==1:
            t=0
        b=1
    else:
        if b==1:
            amount += t
            bc=1
            b=0
        else:
            t=0
print(amount)

Failing test case input:
ABDB@BBCAADCCCBBD

Expected output:
0


Actual output:
2


Fixed submission (verdict: Accepted):
s=list(input())
n=len(s)
S=[]
t=0
while t<n-1:
    if s[t]=='B' and s[t+1]=='C':
        S.append('R')
        t+=1
    else:
        S.append(s[t])
    t+=1
if t==n-1:
    S.append(s[t])
m=len(S)
amount=0
bc=0
a=0
for i in range(m):
    if S[i]=='A':
        a += 1
    elif S[i]=='R':
        amount += a
        bc=1
    else:
        a=0
        bc=0
print(amount)
Problem: p03018
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
s = input()
ans = 0
Acnt = 0
cnt = 0
for c in s:
    if c == "A":
        Acnt += 1
        cnt = 1
    elif cnt == 1 and c == "B":
        cnt += 1
    elif cnt == 2 and c == "C":
        ans += Acnt
        Acnt = 1
        cnt = 1
    else:
        Acnt = 0
        cnt = 0
print(ans)

Failing test case input:
ACCAAABCAABCCBBBC

Expected output:
8


Actual output:
6


Fixed submission (verdict: Accepted):
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)

Problem: p03018
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
s=list(input())
count=0
for i in range(len(s)-3):
    if s[i:i+3]==['A','B','C']:
        count+=1
        s[i]='B'
        s[i+1]='C'
        s[i+2]='A'
        for j in range(1,len(s)):
            if i-j<0:
                break
            if s[i-j]=='A':
                count+=1
                s[i-j]='B'
                s[i-j+1]='C'
                s[i-j+1]='A'
                
            
            else:
                break
        
print(count)


        
    
        

        
    


Failing test case input:
ABCABC

Expected output:
3

Actual output:
1


Fixed submission (verdict: Accepted):
s=list(input())
count=0
count1=0
for i in range(len(s)-2):
    if s[i:i+3]==['A','B','C']:
        count+=1
        s[i]='B'
        s[i+1]='C'
        s[i+2]='A'

            
        for j in range(1,len(s)):
            if i-j<0:
                count+=count1
                break
            if s[i-j]=='A':
                count1+=1
            else:
                count+=count1
                break
            
    if s[i:i+3]==['A','A','A'] or s[i:i+3]==['A','A','B'] or s[i:i+3]==['C','A','A'] or s[i:i+3]==['C','A','B'] or s[i:i+3]==['B','C','A']:
        continue
    else:
        count1=0


print(count)
Problem: p03018
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys
INF = 1 << 60
MOD = 10**9 + 7 
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    ans = 0
    stack = []
    for c in input():
        if len(stack) >= 2 and stack[-2:] == ["A", "B"] and c == 'C':
            ans += len(stack) - 1
            stack.pop()
        elif len(stack) >= 1 and stack[-1] == 'A' and c in ('A', 'B'):
            stack.append(c)
        elif c == 'A':
            stack = ['A']
    print(ans)
resolve()

Failing test case input:
ACCAABBCAABCCBBBD

Expected output:
2


Actual output:
8


Fixed submission (verdict: Accepted):
import sys
INF = 1 << 60
MOD = 10**9 + 7 
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    ans = 0
    stack = []
    for c in input():
        if len(stack) >= 2 and stack[-2:] == ["A", "B"] and c == 'C':
            ans += len(stack) - 1
            stack.pop()
        elif len(stack) >= 1 and stack[-1] == 'A' and c in ('A', 'B'):
            stack.append(c)
        elif c == 'A':
            stack = ['A']
        else:
            stack = []
    print(ans)
resolve()

Problem: p03018
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):





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)



Failing test case input:
ABBBCCBACCBCAABCB

Expected output:
2


Actual output:
4


Fixed submission (verdict: Accepted):





s = input()

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

print(total)

Problem: p03018
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  s=S()

  
  
  
  
  
  
  

  

  a_c=0
  bc_c=0
  sm=0
  for i in range(len(s)):
    if s[i:i+2]=='BC':
      sm+=a_c
    elif s[i]=='A':
      a_c+=1

  return sm

print(main())


Failing test case input:
ACCAABBCAABCCBBBD

Expected output:
2


Actual output:
8


Fixed submission (verdict: Accepted):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  s=S()

  
  
  
  
  
  
  

  
  

  s=list(s)
  s.reverse()
  s=''.join(s)

  cb_c=0
  sm=0
  f=False
  for i in range(len(s)):
    if f:
      f=False
      continue
    if s[i:i+2]=='CB':
      cb_c+=1
      f=True
    elif s[i]=='A':
      sm+=cb_c
    else:
      cb_c=0

  return sm

print(main())
Problem: p03018
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()
L = [" "]
for s in S:
  if s == 'A':
    L.append('0')
  elif s == 'B':
    L.append('B')
  elif s == 'C' and L[-1] == 'B':
    L[-1] = '1'
  else:
    L.append('C')

def func(a,b):

  return a * b

ans = 0
a,b = 0,0
i = 0
while i < len(S):
  if S[i] == 'A':
    if b != 0:
      ans += func(a,b)
      a,b = 2,0
    else:
      a += 1
  elif S[i:i + 2] == 'BC':
    b += 1
  elif S[i - 1:i + 1] == "BC":
    ()
  else:
    ans += func(a,b)
    a,b = 0,0
  i += 1
print(ans + func(a,b))

Failing test case input:
ACCAACBCAABCCBBBC

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
S = input()
L = [" "]
for s in S:
  if s == 'A':
    L.append('0')
  elif s == 'B':
    L.append('B')
  elif s == 'C' and L[-1] == 'B':
    L[-1] = '1'
  else:
    L.append('C')

def func(a,b):

  return a * b

ans = 0
a,b = 0,0
i = 0
while i < len(S):
  if S[i] == 'A':
    if b != 0:
      ans += func(a,b)
      b = 0
    a += 1
  elif S[i:i + 2] == 'BC':
    b += 1
  elif S[i - 1:i + 1] == "BC":
    ()
  else:
    ans += func(a,b)
    a,b = 0,0
  i += 1
print(ans + func(a,b))

Problem: p03018
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()
ans = 0
bc = 0
c_flag = 0
for i in range(len(S) - 1, -1, -1):
    if S[i] == "A" and c_flag == 0:
        ans += bc
    elif S[i] == "A" and c_flag == 1:
        bc = 0
        c_flag = 0
    elif S[i] == "C" and c_flag == 0:
        c_flag = 1
    elif S[i] == "B" and c_flag == 1:
        bc += 1
        c_flag = 0
    else:
        bc = 0
        c_flag = 0
print(ans)






Failing test case input:
ABCAACBCAABCCBBBC

Expected output:
3


Actual output:
1


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

Problem: p03018
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)


Failing test case input:
ABCAACBCAABCCBBBC

Expected output:
3


Actual output:
1


Fixed submission (verdict: Accepted):
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
    elif s[l-i-1]=='C' and c==1:
        ch=0
        c=1
    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)
Problem: p03018
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)

Failing test case input:
ABBBCCBACCBCAABCB

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
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")
for u in range(len(t)):
    t[u] = t[u].split("C")
ans = 0
for u in t:
    for v in u:
        dcnt = 0
        v = list(v)
        for i in range(len(v)):
            if v[i] == "D":
                ans += (i - dcnt)
                dcnt += 1
print(ans)

Problem: p03018
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()
idx = 0
a_cnt = 0
cnt = 0
len_s = len(S)
while idx < len_s:
  if S[idx:idx+3] == 'ABC':
    cnt += 1 + a_cnt
    idx += 3
    a_cnt = 1
    bc_cnt = 0
    while idx < len(S):
      if S[idx:idx+2] == 'BC':
        bc_cnt += 1
        idx += 2
      else:
        break
    cnt += bc_cnt
  else:
    if S[idx] == 'A':
      a_cnt += 1
    idx += 1
print(cnt)

Failing test case input:
ACCBABBCAABCCBBBD

Expected output:
2


Actual output:
4


Fixed submission (verdict: Accepted):
S = input()
idx = 0
a_cnt = 0
cnt = 0
len_s = len(S)
while idx < len_s:
  if S[idx:idx+3] == 'ABC':
    cnt += 1 + a_cnt
    idx += 3
    a_cnt += 1
    bc_cnt = 0
    while idx < len(S):
      if S[idx:idx+2] == 'BC':
        cnt += a_cnt
        idx += 2
      else:
        break
  else:
    if S[idx] == 'A':
      a_cnt += 1
    else:
      a_cnt = 0
    idx += 1
print(cnt)
Problem: p03018
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
s = list(input())
cnt = 0
for i in range(len(s) - 2):
    if s[i:i + 3] == ["A", "B", "C"]:
        s[i:i + 3] = ["B", "C", "A"]
        cnt += 1
    

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

print(cnt)

Failing test case input:
ACCAAABCAABCCBBBD

Expected output:
8


Actual output:
6


Fixed submission (verdict: Accepted):
s = list(input())
def change(i):
    global s
    
    if s[i : i + 3] == ["A", "B", "C"]:
        s[i:i + 3] = ["B", "C", "A"]
        
        return 1
    return 0

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

print(cnt)

Problem: p03018
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
s = list(input())
n = len(s)
ans = 0
i = 0
c = 1
while i < n-2:
    if s[i] == "A" and s[i+1] == "B" and s[i+2] =="C":
        ans += c
        for j in range(c):
            s[i+2-j] = "A"
        c = 1
    elif s[i] == "A":
        c += 1
    else:
        c = 1
    i += 1
print(ans)

Failing test case input:
ACCAAABCAABCCBBBC

Expected output:
8


Actual output:
7


Fixed submission (verdict: Accepted):
s = list(input())
n = len(s)
ans = 0
c = 0
i = 0
while i < n-1:
    if s[i] == "B" and s[i+1] == "C":
        ans += c
        i += 1
    elif s[i] == "A":
        c += 1
    else:
        c = 0
    i += 1
print(ans)

Problem: p03018
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

import sys
INF = float("inf")


def solve(s: str):

    ans = 0
    A = 0
    B = 0
    for c in s:
        if c == "A":
            A += 1
        elif A > 0 and c == "B":
            B = 1
        elif A > 0 and B > 0 and c == "C":
            ans += A
            B = 0
        else:
            A = 0
            B = 0
    print(ans)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  
    solve(s)


if __name__ == '__main__':
    main()


Failing test case input:
ADCBABBCAABCCBBBD

Expected output:
2


Actual output:
4


Fixed submission (verdict: Accepted):

import sys
INF = float("inf")


def solve(s: str):

    ans = 0
    A = 0
    B = 0
    process = []
    for c in s:
        if c == "A":
            if B == 0:
                A += 1
            else:
                A = 1
                B = 0
        elif A > 0 and c == "B":
            if B == 0:
                B = 1
            else:
                B = 0
                A = 0
        elif A > 0 and B > 0 and c == "C":
            ans += A
            B = 0
        else:
            A = 0
            B = 0
    print(ans)
    

    
    
    
    
    
    

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  
    solve(s)


if __name__ == '__main__':
    main()
Problem: p03018
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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" and s[i+1]=="C":
        l.append("D")
        f=1
    elif s[i]=="C":
        if f:
            pass
        else:
            l.append("C")
ans=0
ac=0

for i in range(len(l)):
    if l[i]=="A":
        ac+=1
    elif l[i]=="D":
        ans+=ac
    else:
        ac=0
print(ans)


Failing test case input:
ABCAACBCAABCCBBBC

Expected output:
3


Actual output:
5


Fixed submission (verdict: Accepted):
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)

Problem: p03018
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()
S.replace('BC','X')
res = 0
cnt = 0
for i in range(len(S)):
    if S[i] == 'A' :
        cnt += 1
    elif S[i] == 'X':
        res += cnt
    else:
        cnt = 0
print(res)


Failing test case input:
ABCAACBCAABCCBBBC

Expected output:
3


Actual output:
0


Fixed submission (verdict: Accepted):
S = input()
T = S.replace('BC','X')
res = 0
cnt = 0
for s in T:
    if s == 'A' :
        cnt += 1
    elif s == 'X':
        res += cnt
    else:
        cnt = 0
print(res)

Problem: p03018
Buggy submission (Python (3.8.2), verdict: Wrong Answer):

from itertools import accumulate

s = input()
l = s.split('BC')


if l[-1] == '':
    l = l[:-1]
l = l[::-1]

ans = 0
i = 0

while i < len(l):
    anum = []
    flag = True
    while flag and i < len(l):
        M = len(l[i])
        tmp = 0
        for j in range(M):
            if l[i][M-j-1] == 'A':
                tmp += 1
            else:
                flag = False
                break
        anum.append(tmp)
        if flag:
            i += 1
    
    ans += sum(accumulate(anum[::-1]))
    i += 1
print(ans)


Failing test case input:
@AFCAA

Expected output:
0


Actual output:
2


Fixed submission (verdict: Accepted):

from itertools import accumulate

s = input()
l = s.split('BC')[:-1]
l = l[::-1]

ans = 0
i = 0

while i < len(l):
    anum = []
    flag = True
    while flag and i < len(l):
        M = len(l[i])
        tmp = 0
        for j in range(M):
            if l[i][M-j-1] == 'A':
                tmp += 1
            else:
                flag = False
                break
        anum.append(tmp)
        if flag:
            i += 1
    ans += sum(accumulate(anum[::-1]))
    i += 1
print(ans)
Problem: p03018
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)
    

Failing test case input:
CBAABC

Expected output:
2


Actual output:
0


Fixed submission (verdict: Accepted):
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
    elif i>0 and s[i-1:i+1]=="BC":
        pass
    else:
        cnt=0

print(ans)

Problem: p03018
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
s=list(input())
n=len(s)
amount=0
t=0
b=0
for i in range(n):
    if s[i]=='A':
        t += 1
        b=0
    elif s[i]=='B':
        if b==1:
            t=0
        b=1
    else:
        if b==1:
            amount += t
            b=0
        else:
            t=0
print(amount)

Failing test case input:
ABDC@BBCAADCCCBBD

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
s=list(input())
n=len(s)
S=[]
t=0
while t<n-1:
    if s[t]=='B' and s[t+1]=='C':
        S.append('R')
        t+=1
    else:
        S.append(s[t])
    t+=1
if t==n-1:
    S.append(s[t])
m=len(S)
amount=0
bc=0
a=0
for i in range(m):
    if S[i]=='A':
        a += 1
    elif S[i]=='R':
        amount += a
        bc=1
    else:
        a=0
        bc=0
print(amount)

Problem: p03018
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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
print("".join(l))
for i in range(len(l)):
    if l[i]=="A":
        ac+=1
    elif l[i]=="D":
        ans+=ac
    else:
        ac=0
print(ans)


Failing test case input:
ABBBCCBACCBCAABCA

Expected output:
2


Actual output:
ABBDCBACCDAAD
2


Fixed submission (verdict: Accepted):
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)
Problem: p03018
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    s = SS()

    
    
    ans = 0
    len_s = len(s)
    for i in range(len_s):
        cnt = 0
        if s[i] == 'A':
            cnt += 1
        elif i + 1 < len_s and s[i] == 'B' and s[i+1] == 'C':
            ans += cnt
        else:
            cnt = 0
            
    print(ans)

if __name__ == '__main__':
    resolve()


Failing test case input:
ABBBCCBACCBCAABCB

Expected output:
2


Actual output:
0


Fixed submission (verdict: Accepted):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    s = SS()

    
    
    ans = 0
    len_s = len(s)
    cnt = 0
    i = 0
    while i < len_s:
        
        if s[i] == 'A':
            cnt += 1
            i += 1
        elif i + 1 < len_s and s[i] == 'B' and s[i+1] == 'C':
            ans += cnt
            i += 2
        else:
            cnt = 0
            i += 1
            
    print(ans)

if __name__ == '__main__':
    resolve()

Problem: p03018
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
s=input()
ans=0
a=[0 for i in range(len(s))]
bc=[0 for i in range(len(s))]
if len(s)<3:
  print(0)
else:
  for i in range(len(s)):
    if s[i]=="A":
      a[i]=1
  for i in range(len(s)-1):
    if s[i]=="B" and s[i+1]=="C":
      bc[i]=1
  for i in range(len(s)-2):
    if a[i]>0 and bc[i+1]>0:
      a[i+2]=1
  for i in range(len(s)-1):
    if a[i+1]>0:
      a[i+1]+=a[i]
      a[i]=0
  for i in range(len(s)-2,-1,-1):
    if bc[i-2]>0:
      bc[i-2]+=bc[i]
      bc[i]=0
  for i in range(len(s)-2):
    if a[i]>0 and bc[i+1]>0:
      ans+=a[i]*bc[i+1]
  print(ans)
  

Failing test case input:
ACCAAABCAABCCBBBC

Expected output:
8


Actual output:
6


Fixed submission (verdict: Accepted):
s=input()
ans=0
a=[0 for i in range(len(s))]
bc=[0 for i in range(len(s))]
if len(s)<3:
  print(0)
else:
  for i in range(len(s)-2):
    if s[i]=="A":
      a[i]+=1
    if s[i+1]=="B" and s[i+2]=="C":
      a[i+2]+=a[i]
    if s[i+1]=="A":
      a[i+1]+=a[i]
      
  for i in range(len(s)-1):
    if s[i]=="B" and s[i+1]=="C":
      bc[i]=1
  
   
    
     
  
   
    
  
   
    
     
  
   
    
     
  
  for i in range(len(s)-2):
    if a[i]>0 and bc[i+1]>0:
      ans+=a[i]*bc[i+1]
  print(ans)
Problem: p03018
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def give(list):
    i=0
    count=0
    count1=0
    while i<len(list)-2:
        if list[i]=='A':
            count1+=1
            if list[i]=='A' and list[i+1]=='B' and list[i+2]=='C':
                list[i]='B'
                list[i+1]='C'
                list[i+2]='A'
                i+=2
                count+=count1
                count1=0
            else:
                i+=1
        else:
            count1=0
            i+=1
    return count
s=list(input())
print(give(s))


Failing test case input:
ACCAAABCAABCCBBBD

Expected output:
8


Actual output:
6


Fixed submission (verdict: Accepted):
def give(list):
    i=0
    count=0
    count1=0
    while i<len(list)-2:
        if list[i]=='A':
            count1+=1
            if list[i]=='A' and list[i+1]=='B' and list[i+2]=='C':
                list[i+2]='A'
                
                i+=2
                count+=count1
                count1-=1
                
            else:
                i+=1
        else:
            count1=0
            i+=1
    return count
s=list(input())
print(give(s))

Problem: p03018
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():

    s = list(input())
    ans = 0
    h = 0
    i = 0
    while i < len(s):
        if s[i] == "A":
            h += 1
            
            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())


Failing test case input:
ACCAAABCAABCCBBBD

Expected output:
8


Actual output:
6


Fixed submission (verdict: Accepted):
def main():

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

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

Problem: p03018
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
s = input()
a = 0
count = 0
for i in range(len(s)-1):
  if s[i] == 'A':
    a += 1
  elif s[i] == 'B' and s[i+1]== 'C':
    count += a
  elif s[i]==s[i+1]=='B' or s[i]==s[i+1]=='C' or (s[i]=='C' and s[i+1]=='B'):
    a = 0
print(count)

Failing test case input:
ABCACCBABCBCAABCB

Expected output:
6

Actual output:
4


Fixed submission (verdict: Accepted):
s = input()
a = 0
count = 0

i = 0
while i < len(s)-1:
  if s[i]=='A':
    a += 1
    i += 1
  elif s[i]=='B' and s[i+1]=='C':
    count += a
    i += 2
  else:
    a = 0
    i += 1
print(count)
Problem: p03018
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  s=S()

  
  
  
  
  
  
  

  
  

  a_c=0
  bc_c=0
  sm=0
  for i in range(len(s)):
    if s[i:i+2]=='BC':
      sm+=a_c
    elif s[i]=='A':
      a_c+=1
    elif s[i:i+2] in ['AC','CC']:
      a_c=0

  return sm

print(main())


Failing test case input:
DBBBCCBAACBB@BCDA

Expected output:
0


Actual output:
2


Fixed submission (verdict: Accepted):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  s=S()

  
  
  
  
  
  
  

  
  

  s=list(s)
  s.reverse()
  s=''.join(s)

  cb_c=0
  sm=0
  f=False
  for i in range(len(s)):
    if f:
      f=False
      continue
    if s[i:i+2]=='CB':
      cb_c+=1
      f=True
    elif s[i]=='A':
      sm+=cb_c
    else:
      cb_c=0

  return sm

print(main())

Problem: p03018
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
import re
sys.setrecursionlimit(10 ** 7)


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


def SI(): return input()


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

    print(ans)


main()


Failing test case input:
ACCAAABCAABCCBBBC

Expected output:
8


Actual output:
6


Fixed submission (verdict: Accepted):
import sys
import re
sys.setrecursionlimit(10 ** 7)


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


def SI(): return input()


def main():
    S = SI()
    ans = 0
    S = S.replace("A", "0")
    S = S.replace("BC", "1")
    a = 0
    b = 0
    for s in S:
        if s == "0":
            a += 1
        elif s == "1":
            ans += a
            b = 1
        else:
            a = 0
    print(ans)


main()
Problem: p03018
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()
ans = 0
bc = 0
c_flag = 0
for i in range(len(S) - 1, -1, -1):
    if S[i] == "A" and c_flag == 0:
        ans += bc
    elif S[i] == "C" and c_flag == 0:
        c_flag = 1
    elif S[i] == "B" and c_flag == 1:
        bc += 1
        c_flag = 0
    else:
        bc = 0
        c_flag = 0
print(ans)






Failing test case input:
ACCAAABCAABCCBBBD

Expected output:
8


Actual output:
3


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

Problem: p03018
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
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
print(ans)

Failing test case input:
CBAABC

Expected output:
2


Actual output:
0


Fixed submission (verdict: Accepted):
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)

Problem: p03018
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
S=input()

N=len(S)
if N<3:
    print(0)
    exit()
S=list(S)

As=0

BCs=0
ans=0
flag=False
for i in range(N-2):
    if "".join(S[i:i+3])=="ABC":
        ans+=1
        ans+=As
        BCs=0

        S[i]="B"
        S[i+1]="C"
        S[i+2]="A"
    elif S[i]=="A":
        As+=1
    else:
        As=0

print(ans)

Failing test case input:
ACCAAABCAABCCBBBD

Expected output:
8


Actual output:
6


Fixed submission (verdict: Accepted):
S=input()

N=len(S)
if N<3:
    print(0)
    exit()
S=list(S)

As=0

BCs=0
ans=0
flag=False
safe=-1
for i in range(N-2):
    if "".join(S[i:i+3])=="ABC":
        ans+=1
        ans+=As


        S[i]="B"
        S[i+1]="C"
        S[i+2]="A"
        safe=i+1

    elif S[i]=="A":
        As+=1
    else:
        if i!=safe:
            As=0
    

print(ans)
Problem: p03018
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
s = input()
s = s[::-1]
ans = 0
cnt = 0
pos = 0
while pos<len(s):
  if s[pos] == "A":
    ans += cnt
    pos += 1
  elif s[pos] == "B":
    cnt = 0
    pos += 1
  elif s[pos:pos+2] == "CB":
    cnt += 1
    pos += 2
  else:
    pos += 1
print(ans)

Failing test case input:
ACCAAABCAABCCBBBD

Expected output:
8


Actual output:
10


Fixed submission (verdict: Accepted):
s = input()
s = s[::-1]
ans = 0
cnt = 0
pos = 0
while pos<len(s):
  if s[pos] == "A":
    ans += cnt
    pos += 1
  elif s[pos] == "B":
    cnt = 0
    pos += 1
  elif s[pos:pos+2] == "CB":
    cnt += 1
    pos += 2
  else:
    cnt = 0
    pos += 1
print(ans)

Problem: p03018
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
s = list(input())
n = len(s)
ans = 0
i = 0
c = 1
while i < n-2:
    if s[i] == "A" and s[i+1] == "B" and s[i+2] =="C":
        ans += c
        s[i+2] = "A"
    elif s[i] == "A":
        c += 1
    else:
        c = 1
    i += 1
print(ans)

Failing test case input:
ACCAAABCAABCCBBBC

Expected output:
8


Actual output:
6


Fixed submission (verdict: Accepted):
s = list(input())
n = len(s)
ans = 0
c = 0
i = 0
while i < n-1:
    if s[i] == "B" and s[i+1] == "C":
        ans += c
        i += 1
    elif s[i] == "A":
        c += 1
    else:
        c = 0
    i += 1
print(ans)

Problem: p03018
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
S = input()
S = S.replace('BC', 'X')

ret = 0
a_frq = 0
for s in S:
    if s == 'A':
        a_frq += 1

    elif s == 'X':
        ret += a_frq
        a_frq = 1
    else:
        a_frq = 0

print(ret)


Failing test case input:
ACBAACBCAABCCBBBC

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
S = input()
S = S.replace('BC', 'X')

ret = 0
a_frq = 0
for s in S:
    if s == 'A':
        a_frq += 1

    elif s == 'X':
        ret += a_frq

    else:
        a_frq = 0

print(ret)
Problem: p03018
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
s = input()
n = len(s)

ans = 0

cb_cnt = 0
state = 0
for i in range(n)[::-1]:
    if state == 0:
        if s[i] == "C":
            cb_cnt += 1
            state = 1
            continue
    elif state == 1:
        if s[i] == "B":
            state = 2
            continue
    elif state == 2:
        if s[i] == "C":
            cb_cnt += 1
            state = 1
            continue
        elif s[i] == "A":
            ans += cb_cnt
            state = 3
            continue
    elif state == 3:
        if s[i] == "C":
            state = 1
            cb_cnt += 1
            continue
        elif s[i] == "A":
            ans += cb_cnt
            continue
    cb_cnt = 0
    state = 0
print(ans)

Failing test case input:
ABCAACBCAABCCBBBC

Expected output:
3


Actual output:
1


Fixed submission (verdict: Accepted):
s = input()
n = len(s)

ans = 0

cb_cnt = 0
state = 0

for i in range(n)[::-1]:
    
    if state == 0:
        if s[i] == "C":
            cb_cnt = 1
            state = 1
            continue
    
    elif state == 1:
        if s[i] == "B":
            state = 2
            continue
        elif s[i] == "C":
            cb_cnt = 1
            continue
    
    elif state == 2:
        if s[i] == "C":
            cb_cnt += 1
            state = 1
            continue
        elif s[i] == "A":
            ans += cb_cnt
            state = 3
            continue
    
    elif state == 3:
        if s[i] == "C":
            state = 1
            cb_cnt += 1
            continue
        elif s[i] == "A":
            ans += cb_cnt
            continue
    cb_cnt = 0
    state = 0
print(ans)

Problem: p03018
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = list(input())[::-1]
N,i,ans = len(s),0,0
s += [0,0]
while i < N:
    if s[i] == 'C':
        if s[i+1] == 'B':
            temp = 1
            i += 2
            while i < N:
                if s[i] == 'A':
                    ans += temp
                    i += 1
                elif s[i] == 'C' and s[i+1] == 'B':
                    temp += 1
                    i += 2
                else:
                    i += 2
                    break
        else: i += 2
    else:   i += 1

print(ans)




Failing test case input:
ACCBABBCAABCCBBBD

Expected output:
2


Actual output:
0


Fixed submission (verdict: Accepted):
s = list(input())[::-1] + [0,0]
N,i,ans = len(s),0,0

while i < N:
    if s[i] == 'C' and s[i+1] == 'B':
            temp = 1
            i += 2
            while i < N:
                if s[i] == 'A':
                    ans += temp
                    i += 1
                elif s[i] == 'C' and s[i+1] == 'B':
                    temp += 1
                    i += 2
                else:
                    break
    else:   i += 1

print(ans)
Problem: p03018
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
S=input()

N=len(S)
if N<3:
    print(0)
    exit()
S=list(S)

As=0

BCs=0
ans=0
flag=False
for i in range(N-2):
    if "".join(S[i:i+3])=="ABC":
        ans+=1
        ans+=As
        BCs=0

        S[i]="B"
        S[i+1]="C"
        S[i+2]="A"
        if As>=1:
            As-=1
    elif S[i]=="A":
        As+=1
    else:
        As=0

print(ans)

Failing test case input:
ACCAAABCAABCCBBBD

Expected output:
8


Actual output:
6


Fixed submission (verdict: Accepted):
S=input()

N=len(S)
if N<3:
    print(0)
    exit()
S=list(S)

As=0

BCs=0
ans=0
flag=False
safe=-1
for i in range(N-2):
    if "".join(S[i:i+3])=="ABC":
        ans+=1
        ans+=As


        S[i]="B"
        S[i+1]="C"
        S[i+2]="A"
        safe=i+1

    elif S[i]=="A":
        As+=1
    else:
        if i!=safe:
            As=0
    

print(ans)

Problem: p03018
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()
idx = 0
a_cnt = 0
cnt = 0
len_s = len(S)
while idx < len_s:
  if S[idx:idx+3] == 'ABC':
    cnt += 1 + a_cnt
    idx += 3
    a_cnt = 1
    bc_cnt = 0
    while idx < len(S):
      if S[idx:idx+2] == 'BC':
        bc_cnt += 1
        idx += 2
      else:
        break
    cnt += bc_cnt
  else:
    if S[idx] == 'A':
      a_cnt += 1
    else:
      a_cnt = 0
    idx += 1
print(cnt)

Failing test case input:
ACCAAABCAABCCBBBD

Expected output:
8


Actual output:
6


Fixed submission (verdict: Accepted):
S = input()
idx = 0
a_cnt = 0
cnt = 0
len_s = len(S)
while idx < len_s:
  if S[idx:idx+3] == 'ABC':
    cnt += 1 + a_cnt
    idx += 3
    a_cnt += 1
    bc_cnt = 0
    while idx < len(S):
      if S[idx:idx+2] == 'BC':
        cnt += a_cnt
        idx += 2
      else:
        break
  else:
    if S[idx] == 'A':
      a_cnt += 1
    else:
      a_cnt = 0
    idx += 1
print(cnt)

Problem: p03018
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
s = str(input())

ans, cnt, i = 0, 0, 0
while i < len(s)-1:
  if s[i] == 'A':
    cnt += 1
    i += 1
  else:
    if s[i:i+2] == 'BC':
      ans += cnt
      i += 2
      cnt = 1
    else:
      cnt = 0
      i += 1
print(ans)

Failing test case input:
ABBBCCBACCBCAABCB

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
s = str(input())

ans, cnt, i = 0, 0, 0
while i < len(s)-1:
  if s[i] == 'A':
    cnt += 1
    i += 1
  else:
    if s[i:i+2] == 'BC':
      ans += cnt
      i += 2
    else:
      cnt = 0
      i += 1
print(ans)
Problem: p03018
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
s = input()
ans = 0
tmp = 0
i = 0
while i < len(s)-1:
    if s[i] == "A":
        tmp += 1
    elif s[i] == "B":
        if s[i+1] == "C":
            ans += tmp
            i += 1
        else:
            tmp = 0
    i += 1
print(ans)

Failing test case input:
ABBBCCBACCBCAABCA

Expected output:
2


Actual output:
4


Fixed submission (verdict: Accepted):
s = input()
ans = 0
tmp = 0
i = 0
while i < len(s)-1:
    if s[i] == "A":
        tmp += 1
    elif s[i] == "B":
        if s[i+1] == "C":
            ans += tmp
            i += 1
        else:
            tmp = 0
    else:
        tmp = 0
    i += 1
print(ans)

Problem: p03018
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys

S=input()
if len(S)<2: print(0),sys.exit()
elif len(S)==3:
    print(1 if S=="ABC" else 0)
    sys.exit()



s=[S[i] for i in range(len(S))]
tmp=0
abc,bca=["A","B","C"],["B","C","A"]
ans=0
while True:
    if tmp==len(s)-2: break
    if s[tmp:tmp+3]==abc:
        s[tmp:tmp+3]=bca
        if tmp>0:
            i=tmp
            while i>0:
                i-=1
                if s[i]=="A":
                    ans+=1
                else: break

        ans+=1
    
    else: tmp+=1

print(ans)


Failing test case input:
ACCAAABCAABCCBBBC

Expected output:
8


Actual output:
6


Fixed submission (verdict: Accepted):
import sys

S=input()
if len(S)<2: print(0),sys.exit()
elif len(S)==3:
    print(1 if S=="ABC" else 0)
    sys.exit()



s=[S[i] for i in range(len(S))]
tmp=0
abc,bca=["A","B","C"],["B","C","A"]
ans=0
a,bc=0,0
i=0
while i<len(s)-1:
    if s[i]=="A": a+=1
    elif s[i]=="B" and s[i+1]=="C":
        bc+=1
        i+=1
        ans+=a
    
    else:
        a,bc=0,0
    i+=1
print(ans)

Problem: p03018
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
s = s.split('BC')
count = [0]
count_all = 0
Icount = 0

for i in range(0,len(s)-1):
    Icount = 0
    j = 1
    while(j<=len(s[i]) and s[i][-j]=='A'):
        Icount = Icount + 1
        j = j + 1
        
    if (s[i]=='' or s[i]=='A'*len(s[i])):
        Icount = Icount + count[-1]
   
    count.append(Icount)
  
        
count_all = sum(count)  
print(count)
print(count_all)

Failing test case input:
ADDB@BBCAABCCCBBD

Expected output:
2


Actual output:
[0, 0, 2]
2


Fixed submission (verdict: Accepted):
s = input()
s = s.split('BC')
count = [0]
count_all = 0
Icount = 0

for i in range(0,len(s)-1):
    Icount = 0
    j = 1
    while(j<=len(s[i]) and s[i][-j]=='A'):
        Icount = Icount + 1
        j = j + 1
        
    if (s[i]=='' or s[i]=='A'*len(s[i])):
        Icount = Icount + count[-1]
   
    count.append(Icount)
  
        
count_all = sum(count)  
print(count_all)