Problem: 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.

Submission attempts (in order):
s=list(input())

i=0
j=0
ans=0
z=[]
while i!=len(s)-2:
    try:
        if s[i]=="B" and s[i+1]=="C":
            z.append(1)
            i=i+2

        else:
            if s[i]=="A":
                z.append(2)
                i=i+1

            else:
                z.append(0)
                i=i+1

    except:
      break

ans=0
i=0
r1=0


#print(z)


while i!=len(z):
    if z[i]==2:#"A"
         r1=r1+1

    elif z[i]==1:#"BC"
        ans=ans+r1

    else:#"gomi"
        r1 = 0


    i=i+1
print(ans)

s=list(input())

i=0
j=0
ans=0
z=[]
while i!=len(s)-2:
    try:
        if s[i]=="A" and s[i+1]=="B" and s[i+2]=="C":
           z.append(1)
           i=i+3

        elif s[i]=="B" and s[i+1]=="C":
            z.append(2)
            i=i+2

        else:
            if s[i]=="A":
                z.append(3)
                i=i+1

            else:
                z.append(0)
                i=i+1

    except:
       break

ans=0
i=0
r1=0
r2=0
r3=0
print(z)

while i!=len(z):
    if z[i]==1:


        r1=r1+1
        ans = ans + r1
        ans=ans+r3
        if r2!=0:
            r3=0
        r2=0
    elif z[i]==2:
        if r1>=1:
            r2=r2
            ans=ans+r1+r3


    elif z[i]==3:
        if r2!=0:
            r3=0
        r3=r3+1+r2
        if r1!=0:
            r1=1
        else:
            r1=0
        r2=0

    else:
        r1 = 0
        r2 = 0
        r3 = 0
    i=i+1
    print(ans)


s=list(input())

i=0
j=0
ans=0
z=[]
while i!=len(s)-1:
    try:
        if s[i]=="B" and s[i+1]=="C":
            z.append(1)
            i=i+2

        else:
            if s[i]=="A":
                z.append(2)
                i=i+1

            else:
                z.append(0)
                i=i+1

    except:
      break

ans=0
i=0
r1=0


print(z)


while i!=len(z):
    if z[i]==2:#"A"
         r1=r1+1

    elif z[i]==1:#"BC"
        ans=ans+r1

    else:#"gomi"
        r1 = 0


    i=i+1
print(ans)




s=list(input())

i=0
j=0
ans=0
z=[]
while i!=len(s)-2:
    try:
        if s[i]=="A" and s[i+1]=="B" and s[i+2]=="C":
           z.append(1)
           i=i+3

        elif s[i]=="B" and s[i+1]=="C":
            z.append(2)
            i=i+2

        else:
            if s[i]=="A":
                z.append(3)
                i=i+1

            else:
                z.append(0)
                i=i+1

    except:
       break

ans=0
i=0
r1=0
r2=0
r3=0
print(z)

while i!=len(z):
    if z[i]==1:


        r1=r1+1
        ans = ans + r1
        ans=ans+r3
        if r2!=0:
            r3=0
        r2=0
    elif z[i]==2:
        if r1>=1:
            r2=r2
            ans=ans+r1+r3


    elif z[i]==3:
        if r2!=0:
            r3=0
        r3=r3+1+r2
        if r1!=0:
            r1=1
        else:
            r1=0
        r2=0

    else:
        r1 = 0
        r2 = 0
        r3 = 0
    i=i+1
    print(ans)

s=list(input())

i=0
j=0
ans=0
z=[]
while i!=len(s)-1:
    try:
        if s[i]=="B" and s[i+1]=="C":
            z.append(1)
            i=i+2

        else:
            if s[i]=="A":
                z.append(2)
                i=i+1

            else:
                z.append(0)
                i=i+1

    except:
      break

ans=0
i=0
r1=0


#print(z)


while i!=len(z):
    if z[i]==2:#"A"
         r1=r1+1

    elif z[i]==1:#"BC"
        ans=ans+r1

    else:#"gomi"
        r1 = 0


    i=i+1
print(ans)


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted