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 = list(input())
pos = 0
str_len = len(s)
count = 0
state = 0
seq_a = 0

while pos < str_len:
    if state == 0:
        if s[pos] == "A":
            state = 1
            seq_a = 1
        pos += 1
    elif state == 1:
        if s[pos] == "B":
            state = 2
        elif s[pos] == "A":
            state = 1
            seq_a += 1
        else:
            state = 0
        pos += 1
    elif state == 2:
        if s[pos] == "C":
            for i in range(pos - seq_a + 1, pos + 1):
                s[i] = "A"
            s[pos - seq_a - 1] = "B"
            s[pos - seq_a] = "C"
            pos = pos - seq_a + 1
            if pos < 0:
                pos = 0
            count += seq_a
            state = 0
            seq_a = 0
#            print(pos, s)
        elif s[pos] == "A":
            state = 1
            pos += 1
        else:
            state = 0
            pos += 1

print(count)

Submission status: Wrong Answer

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

while pos < str_len:
    if state == 0:
        if s[pos] == "A":
            state = 1
            seq_a = 1
        pos += 1
    elif state == 1:
        if s[pos] == "B":
            state = 2
        elif s[pos] == "A":
            state = 1
            seq_a += 1
        else:
            state = 0
        pos += 1
    elif state == 2:
        if s[pos] == "C":
            for i in range(pos - seq_a + 1, pos + 1):
                s[i] = "A"
            pos = pos - seq_a + 1
            if pos < 0:
                pos = 0
            count += seq_a
            state = 0
            seq_a = 0
        elif s[pos] == "A":
            state = 1
            pos += 1
        else:
            state = 0
            pos += 1

print(count)

Submission status: Wrong Answer

Solution code:
s = list(input())
pos = 0
str_len = len(s)
count = 0
state = 0

while pos < str_len:
    if state == 0:
        if s[pos] == "A":
            state = 1
        pos += 1
    elif state == 1:
        if s[pos] == "B":
            state = 2
        elif s[pos] == "A":
            state = 1
        else:
            state = 0
        pos += 1
    elif state == 2:
        if s[pos] == "C":
            s[pos-2:pos+1] = "BCA"
            pos -= 3
            if pos < 0:
                pos = 0
            count += 1
        elif s[pos] == "A":
            state = 1
            pos += 1
        else:
            state = 0
            pos += 1

print(count)

Submission status: Wrong Answer

Solution code:
s = list(input())
buf = 0
str_len = len(s)
count = 0
state = 0

while buf < str_len:
    if state == 0:
        if s[buf] == "A":
            state = 1
        buf += 1
    elif state == 1:
        if s[buf] == "B":
            state = 2
        elif s[buf] == "A":
            pass
        else:
            state = 0
        buf += 1
    elif state == 2:
        if s[buf] == "C":
            s[buf-2:buf+1] = "BCA"
            buf -= 3
            if buf < 0:
                buf = 0
            count += 1
        else:
            buf += 1
        state = 0

print(count)

Submission status: Wrong Answer

Solution code:
s = input().strip()
G = {}
i = 0
while i<len(s)-2:
    if s[i:i+3]=="ABC":
        l = 0
        j = i-1
        while True:
            if j>=0 and s[j]=="A":
                l += 1
                j -= 1
            else:break
        r = 0
        j = i+3
        while True:
            if j+2<=len(s) and s[j:j+2]=="BC":
                r += 1
                j += 2
            else:break
        G[i] = [l,r]
        i += 3
    else:
        i += 1
cnt = 0
for i in G:
    l,r = G[i]
    if l>0:
        cnt += l
        s = s[:i-l]+"ABC"+"A"*l+s[i+3:]
        cnt += min(l,r)
        if l<=r:
            s = s[:i-l+3]+"ABC"*l+"BC"*(r-l)+s[i+2*r+3:]
        else:
            s = s[:i-l+3]+"ABC"*r+"A"*(l-r)+s[i+2*r+3:]
    else:
        cnt += r
        s = s[:i]+"BC"*r+"ABC"+s[i+2*r+3:]
C = []
cur = 0
i = 0
while i < len(s)-2:
    if s[i:i+3]!="ABC":
        if i!=cur:
            C.append((i-cur)//3)
        cur = i+1
        i += 1
    else:
        i += 3
if i>=len(s)-2:
    C.append((i-cur)//3)
for x in C:
    cnt += (x*(x+1))//2
print(cnt)

Submission status: Wrong Answer

Solution code:
w=list(input())
now=0
num=len(w)
w.append(" ")
count=0
while now<num:
  if w[now]!="A":
    now+=1
  else:
    if w[now+1]!="B":
      now+=1
    else:
      if w[now+2]!="C":
        now+=1
      else:
        w[now]="B"
        w[now+1]="C"
        w[now+2]="A"
        count+=1
        back=now-1
        b=True
        while back>0 and b==True:
          if w[back]!="A":
            b=False
          else:
            w[back+2]="A"
            count+=1
            back-=1
        now+=1
print(count)

Submission status: Wrong Answer

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
            c=1
        else:
            c=0
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S = input()
cntA, cntABC, cntBC = 0,0,0
i = 0
ans = 0
while i < len(S):
  if S[i:i+3] == 'ABC':
    cntABC += 1
    include_abc = True
    i += 3
  elif S[i:i+2] == 'BC' and cntABC>=1:
    cntBC += 1
    i += 2
  elif cntABC == 0 and S[i]=='A':
    cntA += 1
    i += 1
  else:
    if cntABC>=1:
      fctA = min(cntABC, cntA)
      ans += cntA*(cntBC+cntABC) + cntBC*cntABC + (cntABC*(cntABC+1))//2
      include_abc = False
      cntA = cntA+cntABC
      cntABC, cntBC = 0,0
    else:
      cntA, cntABC, cntBC = 0,0,0
      i += 1
if cntABC>=1:ans +=cntA*(cntBC+cntABC) + cntBC*cntABC + (cntABC*(cntABC+1))//2
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
cntA, cntABC, cntBC = 0,0,0
i = 0
ans = 0
while i < len(S):
  if S[i:i+3] == 'ABC':
    cntABC += 1
    include_abc = True
    i += 3
  elif S[i:i+2] == 'BC' and cntABC>=1:
    cntBC += 1
    i += 2
  elif cntABC == 0 and S[i]=='A':
    cntA += 1
    i += 1
  else:
    if cntABC>=1:
      fctA = min(cntABC, cntA)
      ans += cntA*cntABC + (cntABC*(cntABC+1))//2 + cntBC*cntABC
      include_abc = False
      cntA = cntA+cntABC
      cntABC, cntBC = 0,0
    else:
      cntA, cntABC, cntBC = 0,0,0
      i += 1
if cntABC>=1:ans += cntA*cntABC + (cntABC*(cntABC+1))//2 + cntBC*cntABC
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
cntA, cntABC, cntBC = 0,0,0
i = 0
ans = 0
while i < len(S):
  if S[i:i+3] == 'ABC':
    cntABC += 1
    include_abc = True
    i += 3
  elif S[i:i+2] == 'BC' and cntABC>=1:
    cntBC += 1
    i += 2
  elif cntABC == 0 and S[i]=='A':
    cntA += 1
    i += 1
  else:
    if cntABC>=1:
      ans += cntA*cntABC + (cntABC*(cntABC+1))//2 + cntBC*cntABC
      include_abc = False
      cntA = cntA+cntABC
      cntABC, cntBC = 0,0
    else:
      cntA, cntABC, cntBC = 0,0,0
      i += 1
if cntABC>=1:ans += cntA*cntABC + (cntABC*(cntABC+1))//2 + cntBC*cntABC
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
cntA, cntABC, cntBC = 0,0,0
i = 0
ans = 0
while i < len(S):
  if S[i:i+3] == 'ABC':
    cntABC += 1
    include_abc = True
    i += 3
  elif S[i:i+2] == 'BC' and cntABC>=1:
    cntBC += 1
    i += 2
  elif cntABC == 0 and S[i]=='A':
    cntA += 1
    i += 1
  else:
    if cntABC>=1:
      ans += cntA + (cntABC*(cntABC+1))//2 + cntBC
      include_abc = False
      cntA = cntA+cntABC
      cntABC, cntBC = 0,0
    else:
      cntA, cntABC, cntBC = 0,0,0
      i += 1
if cntABC>=1:ans += cntA + (cntABC*(cntABC+1))//2 + cntBC
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
cntA, cntABC, cntBC = 0,0,0
i = 0
ans = 0
while i < len(S):
  if S[i:i+3] == 'ABC':
    cntABC += 1
    include_abc = True
    i += 3
  elif S[i:i+2] == 'BC' and cntABC>=1:
    cntBC += 1
    i += 2
  elif cntABC == 0 and S[i]=='A':
    cntA += 1
    i += 1
  else:
    if cntABC>=1:
      ans += cntA + (2*cntABC-1) + cntBC
      include_abc = False
      cntA = cntA+cntABC
      cntABC, cntBC = 0,0
    else:
      cntA, cntABC, cntBC = 0,0,0
      i += 1 
if cntABC>=1:ans += cntA + (2*cntABC-1) + cntBC
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=input()
ans=0
for i in range(len(s)-2):
  if s[i]+s[i+1]+s[i+2]=="ABC":
    ans+=1
    if i > 1:
      if s[i-2]+s[i-1]=="AB":
        ans+=1
    if i<len(s)-4:
      if s[i+3]+s[i+4]=="BC":
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

s = input()
S = list(s)
N = len(S)
count = 0

for i in range(N - 2):
    sub_s = S[i] + S[i + 1] + S[i + 2]
    if sub_s == "ABC":
        S[i] = "B"
        S[i + 1] = "C"
        S[i + 2] = "A"
        count += 1

S = list(reversed(S))
for i in range(N - 2):
    sub_s = S[i + 2] + S[i + 1] + S[i]
    if sub_s == "ABC":
        S[i + 2] = "B"
        S[i + 1] = "C"
        S[i] = "A"
        count += 1
ans = count
print(ans)

Submission status: Wrong Answer

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
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)

Submission status: Wrong Answer

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" and s[i+1]=="C":
        l.append("D")
        f=1
    elif s[i]=="C":
        if f:
            pass
        else:
            l.append("C")
    else:
        f=0
        l.append("B")
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)

Submission status: Wrong Answer

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" 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)

Submission status: Wrong Answer

Solution code:
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 ['A','A','B'] or ['C','A','A'] or ['C','A','B'] or ['A','B','C']:
        continue
    else:
        count1=0

print(count)

Submission status: Wrong Answer

Solution code:
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
print(count)

Submission status: Wrong Answer

Solution code:
s=list(input())
count=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:
                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)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
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':
    a = 0
  elif 0 < i < len(s)-2:
    if s[i]=='C' and s[i+1]=='B' and (s[i-1]!='B' or s[i+2]!='C'):
      a = 0
print(count)

Submission status: Wrong Answer

Solution code:
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':
    a = 0
  elif i < len(s)-2:
    if s[i]=='C' and s[i+1]=='B' and s[i+2]!='C':
      a = 0
print(count)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
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]=='B' and s[i+1]=='C'):
    a = 0
print(count)

Submission status: Wrong Answer

Solution code:

s = list(input())
ls = len(s)
p = 0
status = 0
a = 0
ans = 0
while p < ls:
    if status == 0:
        if s[p] == "A":
            status = 1
            a = 1

    elif status == 1:
        if s[p] == "A":
            a += 1
        elif s[p] == "B":
            status = 2
        else:
            status = 0
            a = 0

    elif status == 2:
        if s[p] == "C":
            ans += a
            status = 1
            a = 1
        elif s[p] == "A":
            status = 1
            a = 1
        elif s[p] == "B":
            status = 0
    p += 1
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
s=input()
s=list(s.replace('BC','Z'))
ans=0
print(s)
 
def seisan(list):
    count=0
    N=len(list)-1
    for index,content in enumerate(list):
        if content=="A":
            count+=(N-index)
            N-=1
    return count

temp=[]
while s:
    this=s.pop(0)
    if this=="B" or this=="C":
        ans+=seisan(temp)
        temp.clear()
    else:
        temp.append(this)

print(ans+seisan(temp))

Submission status: Wrong Answer

Solution code:
S = list(input())
ans = 0
l = []
flag = True
for i in range(len(S)-2):
    if(S[i] == "A" and S[i+1] == "B" and S[i+2] == "C"):
        S[i] = "B"
        S[i+1] = "C"
        S[i+2] = "A"
        l.append(i+2)
        ans += 1
    elif(S[i] == "A"):
        l.append(i)

l = list(set(l))

while(len(l)):
    f = l[-1]
    if(f < len(S) - 2 and f >= 0):
        if(S[f] == "A" and S[f+1] == "B" and S[f+2] == "C"):
            S[f] = "B"
            S[f + 1] = "C"
            S[f + 2] = "A"
            l.append(f + 2)
            l.append(f - 1)
            ans += 1
    l.pop()
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)
T = ""
flag = 0
ans = 0
for i in range(N-1):
  if flag == 1:
    flag = 0
    continue
  if S[i:i+2] == "BC":
    T += "D"
    flag = 1
  else:
    T += S[i]
M = len(T)
T = list(T)
for i in range(M):
  j = -1-i
  if T[j] == "A":
    k = j+1
    while k<=M-1 and T[k] == "D":
      k += 1
      ans += 1
    T[j],T[k-1] = T[k-1],T[j]
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)
ans = 0
pre_k = -1
for i in range(N-2):
  if S[i:i+3] == "ABC":
    ans += 1
    j = i-1
    k = i+3
    while j>=0 and S[j]=="A":
      ans += 1
      j -= 1
    j += 1
    if pre_k+2 == j:
      ans += 1
    while k+1<=N-1 and S[k:k+2] == "BC":
      ans += 1
      k += 2
    pre_k = k-2
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)
ans = 0
for i in range(N-2):
  if S[i:i+3] == "ABC":
    ans += 1
for i in range(N-3):
  if S[i:i+4] == "AABC":
    ans += 1
for i in range(N-4):
  if S[i:i+5] == "ABCBC":
    ans += 1
for i in range(N-8):
  if S[i:i+9] == "ABCBCAABC":
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
s = list(input())

count = 0
for i in range(len(s) - 2):
    if s[i] == 'A' and s[i+1] == 'B' and s[i+2] == 'C':
        count += 1
        s[i] = 'B'
        s[i+1] = 'C'
        s[i+2] = 'A'

for i in reversed(range(len(s) - 2)):
    if s[i] == 'A' and s[i+1] == 'B' and s[i+2] == 'C':
        count += 1
        s[i] = 'B'
        s[i+1] = 'C'
        s[i+2] = 'A'
print(count)

Submission status: Wrong Answer

Solution code:
s = list(input())

count = 0
for i in range(len(s) - 2):
    if s[i] == 'A' and s[i+1] == 'B' and s[i+2] == 'C':
        count += 1
        s[i] = 'B'
        s[i+1] = 'C'
        s[i+2] = 'A'

flag = False
for i in reversed(range(len(s) - 2)):
    if s[i] == 'A' and s[i+1] == 'B' and s[i+2] == 'C':
        count += 1
        flag = True
    else:
        if flag and s[i] == 'A':
            count += 1
        else:
            flag = False
print(count)

Submission status: Wrong Answer

Solution code:
s = input()[::-1]+'xx'

CB = 0
ans = 0
for i in range(len(s)):
    if s[i:i+2] == 'CB':
        CB += 1
    elif s[i:i+2] == 'BB' or s[i:i+2] == 'CC':
        CB = 0
    if s[i] == 'A':
        ans += CB
    if s[i:i+2] == 'AB':
        CB = 0
    if s[i:i+3] == 'ACA':
        CB = 0


print(ans)

Submission status: Wrong Answer

Solution code:
s = input()[::-1]+'x'

CB = 0
ans = 0
for i in range(len(s)):
    if s[i:i+2] == 'CB':
        CB += 1
    elif s[i:i+2] == 'BB' or s[i:i+2] == 'CC':
        CB = 0
    if s[i] == 'A':
        ans += CB
    if s[i:i+2] == 'AB':
        CB = 0


print(ans)

Submission status: Wrong Answer

Solution code:
s = input()[::-1]+'x'

CB = 0
ans = 0
for i in range(len(s)-1):
    if s[i:i+2] == 'CB':
        CB += 1
    elif s[i:i+2] == 'BB' or s[i:i+2] == 'CC':
        CB = 0
    if s[i] == 'A':
        ans += CB
    if s[i:i+2] == 'AB':
        CB = 0


print(ans)

Submission status: Wrong Answer

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

CB = 0
ans = 0
for i in range(len(s)-1):
    if s[i:i+2] == 'CB':
        CB += 1
    elif s[i:i+2] == 'BB' or s[i:i+2] == 'CC':
        CB = 0
    elif s[i] == 'A':
        ans += CB
    if s[i:i+2] == 'AB':
        CB = 0

if s[-1] == 'A':
    ans += CB

print(ans)

Submission status: Wrong Answer

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

CB = 0
ans = 0
for i in range(len(s)-1):
    if s[i:i+2] == 'CB':
        CB += 1
    elif s[i:i+2] == 'BB' or s[i:i+2] == 'CC':
        CB = 0
    elif s[i] == 'A':
        ans += CB
    elif s[i:i+2] == 'AB':
        CB = 0

if s[-1] == 'A':
    ans += CB

print(ans)

Submission status: Wrong Answer

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

CB = 0
ans = 0
for i in range(len(s)-1):
    if s[i:i+2] == 'CB':
        CB += 1
    elif s[i:i+2] == 'BB' or s[i:i+2] == 'CC':
        CB = 0
    elif s[i] == 'A':
        ans += CB

if s[-1] == 'A':
    ans += CB

print(ans)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
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 = 0
    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)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
sentence = input()
#print(sentence)
A = 0
BC = 0
ABC = 0
res = 0
Bflag = 0
for c in sentence:
  if c == "A":
    A += 1
    Bflag = 0
    if Bflag == 1:
      A = 0
      BC = 0
      ABC = 0
      Bflag = 0
  elif c == "B":
    Bflag = 1
  elif c == "C":
    if Bflag == 1:
      BC += 1
      if A > 0:
        res += A - 1
        ABC += 1
    else:
      if BC > 0:
        if ABC > 0:
          if BC > 1:
            res += 1
      ABC = 0
      BC = 0
    if ABC > 0:
      res += ABC
    Bflag = 0
    A = 0
  #print(res)
print(res)

Submission status: Wrong Answer

Solution code:
import re

S = input()
S =re.sub("BC","D",S)

cnt = 0

if S.count("AD")==0:
  print(cnt)

while True:
  fd = S.count("AD")
  if fd == 0:
    break
  cnt += fd
  S = re.sub("AD", "DA", S)
print(cnt)

Submission status: Wrong Answer

Solution code:
s=input()
a=s.replace("BC","D")[::-1]
ans=0
i=0
while i<len(a):
  if a[i]=="D":
    k=1
    while True:
      try:
        if a[i+k]=="A" or a[i+k]=="D":
          ans+=1;k+=1
        else:
          i+=k-1
          break
      except:break
  i+=1
print(ans)

Submission status: Wrong Answer

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

a = 0
ans = 0
nowB = False
for i in range(N):
    if S[i] == 'A':
        a += 1
        nowB = False
    elif S[i] == 'B':
        nowB = True
    else:
        if nowB:
            ans += a
            nowB = False
        else:
            a = 0
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
a = 'A'
b = 'B'
c = 'C'

ans = 0
new_s = ''
i = 0
while 'ABC' in new_s:
  while i < len(s):
    if s[i:i+3]=='ABC':
      ans += 1
      new_s += 'BCA'
      i += 3
    else:
      new_s += s[i]
      i += 1

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
length = len(s)
count = 0

while True:
  flag = 0
  for i in range(length-2):
    if s[i:i+3] == 'ABC':
      if i == 0:
        s = 'BCA' + s[3:length]
      elif i == length-3:
        s = s[0:i] + 'BCA'
      else:
        s = s[0:i] + 'BCA' + s[i+3:length-1]
      flag = 1
      count += 1
  if flag == 0:
    break
print (count)

Submission status: Wrong Answer

Solution code:
#import random
S = input()
#S = ''.join([random.choice(['A', 'B', 'C']) for i in range(200000)])
S = S.replace('BC', 'D')
S = S.replace('C', 'B')
L = []
flag = 0 # flag = 0: 未発見 flag = 1: 発見済み
l = 0
for i in range(len(S)):
    if flag == 0 and S[i] != 'B':
        flag = 1
        l = i
    elif flag == 1 and S[i] == 'B':
        flag = 0
        L.append(S[l:i])
counter = 0
for i in L:
    for j in range(len(i) - 1):
        if i[j] == 'A':
            counter += i[j + 1:].count('D')
print(counter)

Submission status: Wrong Answer

Solution code:
def countD(A):
    ans = 0
    for i in range(len(A)):
        if A[i] == 'D':
            ans += 1
    return ans
S = input()
S = S.replace('BC', 'D')
S = S.replace('C', 'B')
L = []
flag = 0 # flag = 0: 未発見 flag = 1: 発見済み
l = 0
for i in range(len(S)):
    if flag == 0:
        if S[i] == 'A' or S[i] =='D':
            flag = 1
            l = i
    else:
        if S[i] == 'B':
            flag = 0
            L.append(S[l:i])
counter = 0
for i in L:
    for j in range(len(i) - 1):
        if i[j] == 'A':
            counter += countD(i[j + 1:])
print(counter)

Submission status: Wrong Answer

Solution code:
S = input().lower()

state, count, ba = 0, 0, 0
for s in S:
	next_state = None
	if 0 == state:
		if "a" == s:
			ba = 1
			next_state = 1
		elif "b" == s:
			pass
		else:
			pass
	elif 1 == state:
		if "a" == s:
			ba += 1
			next_state = 1
		elif "b" == s:
			next_state = 2
		else:
			ba = 0
			next_state = 1
	elif 2 == state:
		if "a" == s:
			ba = 1
			next_state = 1
		elif "b" == s:
			ba = 0
			next_state = 1
		else:
			count += ba
			ba = 0
			next_state = 3
	elif 3 == state:
		if "a" == s:
			ba = 1
			next_state = 1
		elif "b" == s:
			next_state = 4
		else:
			next_state = 0
	elif 4 == state:
		if "a" == s:
			ba = 1
			next_state = 1
		elif "b" == s:
			next_state = 0
		else:
			count += 1
			next_state = 5
	else:
		if "a" == s:
			ba = 1
			next_state = 1
		elif "b" == s:
			next_state = 4
		else:
			next_state = 0
	state = next_state

print(count)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
import bisect
from collections import defaultdict
import math
import re

def repl(S):
    cnt = 0
    S = list(S)
    i = 0
    while i < len(S)-1:
        if S[i] == "A" and S[i+1] == "X":
            j, k = 0, 0
            for j in range(i):
                j += 1
                if S[i-j] != "A":
                    j -= 1
                    break
            for k in range(len(S)-i-2):
                k += 1
                if S[i+1+k] != "X":
                    k -= 1
                    break
            cnt += 1 + j + k
            S[i-j:i+2+k] = ["X", "A"]

            i = i - j - 1 if i - j > 0 else 0
        else:
            i += 1

    return cnt, "".join(S)

def main():
    S = input().strip()
    S = S.replace("BC", "X")

    cnt = 0
    while True:
        c, new_S = repl(S)
        cnt += c
        if new_S == S:
            break
        S = new_S
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
import bisect
from collections import defaultdict
import math
import re

def repl(S):
    cnt = 0
    S = list(S)
    i = 0
    while i < len(S)-1:
        if S[i] == "A" and S[i+1] == "X":
            j, k = 0, 0
            for j in range(i):
                j += 1
                if S[i-j] != "A":
                    j -= 1
                    break
            for k in range(len(S)-i-2):
                k += 1
                if S[i+1+k] != "X":
                    k -= 1
                    break
            cnt += 1 + j + k
            S[i-j:i+2+k] = ["X", "A"]

            i = i - j - 1 if i - j > 0 else 0
        else:
            i += 1

    return cnt

def main():
    S = input().strip()
    S = S.replace("BC", "X")

    cnt = repl(S)
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
import bisect
from collections import defaultdict
import math
import re

ABC = re.compile(r"A+X+")

def repl(S):
    cnt = 0
    while True:
        match = ABC.search(S)
        if match is None:
            break
        start, end = match.span()
        cnt += 1 + (end - start) - 2
        S_list = list(S)
        S_list[start:end] = ["X", "A"]
        S = "".join(S_list)

    return cnt

def main():
    S = input().strip()
    S = S.replace("BC", "X")

    cnt = repl(S)
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = input()

count = 0

while True:
  index = s.find("ABC")
  if index < 0:
    break
  s = s[:index] + "BAC" + s[index+3:]
  count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import re
S = input()
pattern = r"(A+(BC)*A*(BC)+)+"
pattern2 = r"A+(BC)+"
match_iter = re.finditer(pattern, S)
# print([i.group() for i in match_iter])
count = 0
for match in match_iter: ## AABCBCAABCBC
    string = match.group()
    # print("1{}".format(string))
    while "ABC" in string:
        # print("2{}".format(string))
        match2_iter = re.finditer(pattern2, string)
        string = ""
        for match2 in match2_iter: ## AAABCBCBC
            string2 = match2.group()
            # print("3{}".format(string2))
            cntA = string2.count("A")
            cntBC = string2.count("BC")
            count += cntA + cntBC - 1
            string += "".join(["BC" for _ in range(cntBC)])
            string += "".join(["A" for _ in range(cntA)])
            # print("4{}".format(string))
print(count)

Submission status: Wrong Answer

Solution code:
n = str(input())
p = n.count("ABC")
count = p
if "AA" == n[:2]:
    p += 1
n = n[::-1]
if "CBC" == n[:3]:
    p += 1
for i in range(1, p):
    count += i
print(count)

Submission status: Wrong Answer

Solution code:
n = str(input())
p = n.count("ABC")
if "AA" == n[:1]:
    p += 1
n = n[::-1]
if "CB" == n[:1]:
    p += 1
count = p
for i in range(p):
    count += i
print(count)