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:
if __name__ == '__main__':
    s = input()
    maximum = len(s) - 1

    index = 0
    count = 0

    while True:
        index = s.find('ABC', index)
        if index == -1:
            print(str(count))
            exit()
        # BC
        bc_add = 4
        bc_count = 0
        while True:
            if index + bc_add <= maximum:
                if s[index + bc_add - 1:index + bc_add + 1] == 'BC':
                    bc_count += 1
                    bc_add += 2
                else:
                    break
            else:
                break
        # A
        a_hikizan = 1
        a_count = 0
        while True:
            if index - a_hikizan >= 0:
                if s[index - a_hikizan] == 'A':
                    a_count += 1
                    a_hikizan -= 1
                else:
                    break
            else:
                break
        # ABC
        abc_add = 5
        abc_count = 1
        while True:
            if index + abc_add <= maximum:
                if s[index + abc_add - 2:index + abc_add + 1] == 'ABC':
                    abc_count += 1
                    abc_add += 3
                else:
                    break
            else:
                break
        if abc_count > 1:
            bc_add2 = abc_add - 1
            while True:
                if index + bc_add2 <= maximum:
                    if s[index + bc_add2 - 1:index + bc_add2 + 1] == 'BC':
                        bc_count += 1
                        bc_add2 += 2
                    else:
                        break
                else:
                    break
        count += (abc_count + (abc_count if not a_count * bc_count == 0 else 0) + ((a_count + bc_count) if not a_count == 0 else 0) + ((bc_count + a_count) if not bc_count == 0 else 0))
        index += 3

Submission status: Wrong Answer

Solution code:
s = input()
S = list(s)
 
abc = ['A','B','C']
bca = ['B','C','A']
bc = ['B','C']
ans = 0
i = 0
A = [0]*len(s)
while i < len(s)-2:
    if S[i] == 'A':
        if S[i+1:i+3] == bc:
            A[i] = 0
            ans += 1
            j = i-1
            while j >= 0 and A[j]:
                ans += 1
                j -= 1
            i += 2
        else: i += 1
    else:
        A[i] = 1
        i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
s = str(input())
def f(s):
  ans = 0
  add = 0
  for i in range(len(s)):
    if s[i] == "A":
      add += 1
    elif s[i] == "B":
      if i == len(s) - 1 or s[i+1] != "C":
        add = 0
      else:
        ans += add
  return ans

def h(s):
  ans = 0
  add = 0
  for i in range(len(s)):
    if s[i] == "C":
      add += 1
    elif s[i] == "B":
      if i == len(s) - 1 or s[i+1] != "A":
        add = 0
      else:
        ans += add
  return ans

def g(s):
  return(max(f(s), h(s[::-1])))

ans = 0
j = 0
for i in range(1, len(s)):
  if s[i-1] == "A" and s[i] == "C":
    ans += g(s[j:i])
    j = i
ans += g(s[j:])

print(ans)

Submission status: Wrong Answer

Solution code:

s=input()

cnta=0
for ss in s:
    if ss=="A":
        cnta+=1

if cnta>0:
    print(cnta+1)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n, a, b, c, d = LI_()
    s = S()
    flg = False
    for i in range(a, c-1):
        if s[i] == "#" and s[i + 1] == "#":
            print("No")
            return
    for i in range(b, d-1):
        if s[i] == "#" and s[i + 1] == "#":
            print("No")
            return
    if c > d:
        for i in range(b,d+1):
            if s[i] == "." and s[i + 1] == "." and s[i - 1] == ".":
                flg = True
                break
        if not flg:
            print("No")
            return
    print("Yes")
    return

#B
def B():
    s = S()
    i = len(s) - 1
    state = 0
    ans = 0
    bc = 2
    while i >= 0:
        if state == 0:
            if s[i] == "C":
                state += 1
        elif state == 1:
            if s[i] == "B":
                state += 1
            else:
                state = 0
        elif state == 2:
            if s[i] == "A":
                ans += 1
            elif s[i] == "B":
                state = 0
            else:
                state += 1
        elif state == 3:
            if s[i] == "B":
                state += 1
            elif s[i] == "C":
                bc = 0
                state = 1
            else:
                bc = 0
                state = 0
        else:
            if s[i] == "A":
                ans += bc
            elif s[i] == "B":
                state = 0
                bc = 2
            else:
                bc += 1
                state = 3
        #print(state,s[i])
        i -= 1
    print(ans)

    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    B()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n, a, b, c, d = LI_()
    s = S()
    flg = False
    for i in range(a, c-1):
        if s[i] == "#" and s[i + 1] == "#":
            print("No")
            return
    for i in range(b, d-1):
        if s[i] == "#" and s[i + 1] == "#":
            print("No")
            return
    if c > d:
        for i in range(b,d+1):
            if s[i] == "." and s[i + 1] == "." and s[i - 1] == ".":
                flg = True
                break
        if not flg:
            print("No")
            return
    print("Yes")
    return

#B
def B():
    s = S()
    i = len(s) - 1
    state = 0
    ans = 0
    bc = 2
    while i >= 0:
        if state == 0:
            if s[i] == "C":
                state += 1
        elif state == 1:
            if s[i] == "B":
                state += 1
            else:
                state = 0
        elif state == 2:
            if s[i] == "A":
                ans += 1
            elif s[i] == "B":
                state = 0
            else:
                state += 1
        elif state == 3:
            if s[i] == "B":
                state += 1
            elif s[i] == "C":
                state = 1
            else:
                bc = 0
                state = 0
        else:
            if s[i] == "A":
                ans += bc
            elif s[i] == "B":
                state = 0
                bc = 2
            else:
                bc += 1
                state = 3
        #print(state,s[i])
        i -= 1
    print(ans)

    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    B()

Submission status: Wrong Answer

Solution code:
a = input()+"f"
s  =0
A = 0
F = 0

BC = 0
ff = 0
res = 0
for i , j , k in zip(a,a[1:],a[2:]):
    # print(i,j,k)
    if F == 0 and ff ==0:
        # print("A ",i,j,k)
        if i+j+k =="ABC":
            res += A+1
            A +=1
            F = 1
            ff +=2
        elif i == "A" and j == "A" :A+=1
        else: A = 0
    elif ff == 0 and F!=0:
        if i+j+k =="ABC":
            res += 1+BC+A
            A+=1
            BC = 0
            F += 1
            ff +=2
        elif i + j == "BC" :

            res +=A
            A = 0
            BC +=1
            ff+=1
        elif  i == "A" and j == "A" :
            A+=1+BC
            BC = 0
            F = 0
        else:
            A =0
            F = 0
            BC = 0
    else:
        if ff>0:ff-=1
        # print("C ",i,j,k)

print(res)

Submission status: Wrong Answer

Solution code:
s = list(input())
counter = 0
answer = 0
aCounter = 0
for i in range(len(s)):
  if s[i] == "A":
    counter = 1
    aCounter += 1
  elif s[i] == "B":
    if counter == 1:
      counter = 2
    else:
      counter = 0
      aCounter = 0
  else: # i == C
    if counter == 2:
      answer += aCounter
      counter = 1
    else:
      counter = 0
      aCounter = 0
print(answer)

Submission status: Wrong Answer

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

ans = 0

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"
        ans = ans+1
        j=i-1
        while(j > 0):
            if s[j] == "A":
                s[j+2] = "A"
                ans = ans+1
            j=j-1
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
def Find_and_Replace(S,f_i):
    i = f_i
    count = 0
    new_f_i = 0
    while i < len(S):
        if S[i] == 'C':
            if S[i-2] == 'A' and S[i-1] == 'B':
                S[i-2] = 'B'
                S[i-1] = 'C'
                S[i] = 'A'
                count += 1
                if count == 0:
                    new_f_i = max(2,i-2)
                i += 2
            else:
                i += 3
                if count == 0:
                    new_f_i = i

        else:
            if S[i] == 'B':
                i += 1
            elif S[i] == 'A':
                i += 2
            else:
                i += 3
    return count,new_f_i

S = list(input())
total_count = 0
f_i = 2
while True:
    count,new_f_i = Find_and_Replace(S,f_i)
    f_i = new_f_i
    if count <= 0:
        break
    else:
        total_count += count

print(total_count)

Submission status: Wrong Answer

Solution code:
s = list(str(x) for x in input())

l=len(s)
cnt=[0]*l

i=0
while i<l-1:
    if (s[i] == "B") and (s[i+1] == "C"):
        s[i] = "BC"
        cnt[i]=1
        del s[i+1]
        del cnt[i+1]
        i=i+1
        l=l-1
    else:
        i=i+1

        
ans=0
temp=0
        
for k in range(l-1):
    if cnt[-k-1] == 1:
        if s[-k-2] =="A":
            cnt[-k-2] = 1

for p in range(l):
    if cnt[p]==1:
        temp+=1
    elif temp>0:
        ans+=(temp-1)
        temp=0
    else:
        temp=0
        
ans += (temp-1)

print(ans)

Submission status: Wrong Answer

Solution code:
S=input()
C=0
NN= S.count("ABCABC")
C=NN*3
NNN= S.count("BCAABC")
C=NNN*2

N=S.count("ABC")
C=C+N

print(C)

Submission status: Wrong Answer

Solution code:
s = input()

result = 0
result += s.count('AABCBC')
s = s.replace('AABCBC', 'ABCABC')

while 'AABC' in s:
    result += s.count('AABC')
    s = s.replace('AABC', 'ABCA')
while 'ABCBC' in s:
    result += s.count('ABCBC')
    s = s.replace('ABCBC', 'BCABC')

result += s.count('ABC')
s = s.replace('ABC', 'BCA')

print(result)

Submission status: Wrong Answer

Solution code:
import re
s = input()
ptns = re.findall(r'A*(?:ABC|BC)+', s)
c = 0
for ptn in ptns:
    ais  = [i for i in range(len(ptn)) if ptn[i] == "A"]
    for j, ai in enumerate(reversed(ais)):
        c += (len(ptn) -1 - ai - j) // 2
print(c)

Submission status: Wrong Answer

Solution code:
import sys

def main():
    input = sys.stdin.readline
    S = list(input().strip())
    n = len(S)

    ans = 0
    for i in range(n):
        if S[i:i+3] == ['A', 'B', 'C']:
            ans += 1
            S[i] = 'B'
            S[i+1] = 'C'
            S[i+2] = 'A'

    S = S[::-1]
    for i in range(n):
        if S[i:i+3] == ['C', 'B', 'A']:
            ans += 1
            S[i] = 'A'
            S[i+1] = 'C'
            S[i+2] = 'B'

    return ans


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

Submission status: Wrong Answer

Solution code:
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###

s = input()
if not ('ABC' in s):
  print(0)
  exit()

from collections import deque
S = deque(maxlen=200000)
for ss in s:
  S.append(ss)

ans = 0
ihavea = 0
ihaveab = 0
#保持してる文字列
tmpS = ''
while 1:
  try:
    tmp = S.popleft()
  except:
    print(ans)
    exit()
  if ihavea == 0 and ihaveab==0 and (tmp=='B' or tmp=='C'):
    continue
  if ihavea == 0 and ihaveab==0 and tmp=='A':
    ihavea = 1
    tmpS += 'A'
    continue
  if ihavea == 1 and tmp=='A':
    ihavea = 1
    tmpS += 'A'
    continue
  if ihavea == 1 and tmp=='C': #ノーチャン
    ihavea = 0
    tmpS = ''
    continue
  #AABとかになるパターンをまだ考慮してない
  if ihavea == 1 and tmp=='B':
    ihaveab = 1
    ihavea = 0
    tmpS += 'B'
    continue
  if ihaveab == 1 and tmp=='A': #惜しいけどabは無駄になる
    ihaveab = 0
    tmpS = ''
    S.appendleft('A')
    continue
  if ihaveab == 1 and tmp=='B':
    ihaveab = 0
    tmpS = ''
    continue
  if ihaveab == 1 and tmp=='C':
    ihaveab = 0
    ans += len(tmpS)-1
    S.appendleft('A')
    tmpS = ''
#    if tmpS == 'AB': tmpS = ''
#    else:
#      tmpS = tmpS[0:-2] #末尾のABを取り除くだけ
#      if tmpS[-1]=='A': ihavea = 1
#      elif tmpS[-2:]=='AB': ihaveab = 1
    continue

Submission status: Wrong Answer

Solution code:
S = str(input())

counter = 0
while 0 == 0:
    if not 'ABC' in S:
        break
    else:
        L = len(S)
        counter = counter + 1
        n = S.index('ABC')
        if n > 0:
            for i in range(n-1 , -1 , -1):
                if S[i] == 'A':
                    counter = counter + 1
                else:
                    break
        if n+4 < L-1:
            for i in range(n+3, L-2, 2):
                if S[i] == 'B' and S[i+1] == 'C':
                    counter = counter + 1
                else:
                    S = 'A' + S[i:]
                    break
        else:
            S = S[n+3:]
print(counter)

Submission status: Wrong Answer

Solution code:
import re
s = input()
ptns = re.findall(r'A+(?:ABC|BC)+', s)
c = 0
for ptn in ptns:
    ais  = [i for i in range(len(ptn)) if ptn[i] == "A"]
    for j, ai in enumerate(reversed(ais)):
        c += (len(ptn) -1 - ai - j) // 2
print(c)

Submission status: Wrong Answer

Solution code:

a = input()+"f"
s  =0
A = 0
F = 0

BC = 0
ff = 0
res = 0
for i , j , k in zip(a,a[1:],a[2:]):
    # print(i,j,k)
    if F == 0 and ff ==0:
        # print("A ",i,j,k)
        if i+j+k =="ABC":
            res += A+1
            A +=1
            F = 1
            ff +=2
        elif i == "A" and j == "A" :A+=1
        else: A = 0
    elif ff == 0 and F!=0:
        if i+j+k =="ABC":
            res += 1+BC+A
            A+=1
            BC = 0
            F += 1
            ff +=2
        elif i + j == "BC" :

            res += F
            A = 0
            BC +=1
            ff+=1
        elif  i == "A" and j == "A" :
            A+=1+BC
            BC = 0
            F = 0
        else:
            A =0
            F = 0
            BC = 0
    else:
        if ff>0:ff-=1
        # print("C ",i,j,k)

print(res)

Submission status: Wrong Answer

Solution code:
s = input()
ans = 0
cnt_a = 0
b1 = ''
for i in s:
  if i == 'A' and b1 != 'B':
    cnt_a += 1
    b1 = 'A'
  elif i == 'B' and (b1 == 'A' or b1 == 'C'):
    b1 = 'B'
  elif i == 'C' and b1 == 'B':
    ans += cnt_a
    b1 = 'C'
  else:
    change = False
    b1 =  ''
    cnt_a = 0
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import numpy as np
# import math
# import random
# import fractions
# import sys
# sys.setrecursionlimit(100000)
# N = int(stdin.readline().rstrip().split()[0])
# A = [int(x) for x in stdin.readline().rstrip().split()]
# N, X = [int(x) for x in stdin.readline().rstrip().split()]
# S = stdin.readline().rstrip().split()[0]
S = stdin.readline().rstrip().split()[0]
N = len(S)
newS=[]
i=0
while i<N:
  if i>N-2:
    newS.append(S[i])
    i+=1
  elif S[i:i+2]=="BC":
    newS.append("E")
    i+=2
  elif i>N-3:
    newS.append(S[i])
    i+=1
  elif S[i:i+3]=="ABC":
    newS.append("D")
    i+=3
  
  else:
    newS.append(S[i])
    i+=1
# print(newS)

lns = len(newS)
ans = 0
for i in range(lns-1):
  if newS[i]=="A" and newS[i+1]=="D":
    newS[i]="D"
    newS[i+1]="A"
    ans+=1
for i in range(lns-1):
  if newS[lns-1-i]=="E" and newS[lns-2-i]=="D":
    newS[lns-1-i]="D"
    newS[lns-2-i]="E"
    ans+=1
# print(ans,newS)

newS.append("Z")
Dcount = 0
Acount = 0


for i in range(lns+1):
  if newS[i]=="D":
    Dcount+=1
  else:
    if Dcount!=0:
      ans+=(Dcount*(Dcount+1))//2
      # Dcountはまだ初期化しない
    """
      ans+=Acount
      Acount=0
    if newS[i]=="A":
      Acount+=1
      Dcount=0
    elif newS[i]=="E":
      if Dcount!=0:
        ans+=1
      Acount=0
    """
    Dcount=0
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
r = s
count = 0


while count < 10:
    if("ABC" in r):
        r = r.replace("ABC", "BCA", 1)
        count += 1
    else:
        break

print(count)

Submission status: Wrong Answer

Solution code:
S=input()
NN= S.count("ABCABC")
C=0
if NN>=1:
  for i in range(NN):
    S=S.replace('ABCABC','BCABCA')
    C=C+2
NNN= S.count("BCAABC")
if NNN>=1:
  for i in range(NNN):
    S=S.replace('BCAABC','BCABCA')
    C=C+1
N=S.count("ABC")
while N>0:
  S=S.replace('ABC','BCA')
  C=C+1
  N=S.count("ABC")
  if S in ('ABCABC'):
    S=S.replace('ABCABC','BCABCA')
    C=C+2
    N=S.count("ABC")
  elif S in ("BCAABC"):
    S=S.replace('BCAABC','BCABCA')
    C=C+1
    N=S.count("ABC")
print(C)

Submission status: Wrong Answer

Solution code:
s=input()
n=len(s)
A=s.count('A')
ans=0

for i in range(A):
  l=s.rfind('A')
  k=l
  if k+2<n:
    for j in range(100000):
      if s[k+1]=='B' and s[k+2]=='C':
        ans+=1
        if k+4<n:
          k+=2
        else:
          break
      else:
        break
  s=s[:l]+s[l+1:]
  n-=1
print(ans)

Submission status: Wrong Answer

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

ans = 0

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

Submission status: Wrong Answer

Solution code:
s = input()
ans = 0
pre_chance = 0
pos_chance = 0

for i in range(len(s)-1):
    if s[i] == "A":
        if s[i:i+2] == "AA":
            pre_chance += 1
            pos_chance = 0
        elif s[i:i+3] == "ABC":
            ans += pre_chance + 1
            pre_chance = 0
        else:
            pre_chance = 0
            pos_chance = 0
    elif s[i] == "B":
        if s[i:i+2] == "BC" and pos_chance == 1:
            ans += 1
            pre_chance = 0
        else:
            pre_chance = 0
            pos_chance = 0
    elif s[i] == "C":
        if s[i-1:i+2] == "BCA":
            pre_chance += 1
        elif s[i-1:i+1] == "BC" and pos_chance == 1:
            pos_chance = 1
        elif s[i-2:i+2] == "ABCB":
            pos_chance = 1
        else:
            pre_chance = 0
            pos_chance = 0

print(ans)

Submission status: Wrong Answer

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

ans = 0
keep = 0
flag = False

i = -2
while -1 * N < i:
    flag = False
    s = S[i] + S[i + 1]
    if s == "AA":
        ans += keep * 2
        i -= 2
    elif s == "AB":
        i -= 2
        keep = 0
    elif s == "AC":
        i -= 2
        keep = 0
    elif s == "BA":
        ans += keep
        keep = 0
        i -= 2
    elif s == "BB":
        i -= 2
        keep = 0
    elif s == "BC":
        keep += 1
        i -= 2
        flag = True
    elif s == "CA":
        ans += keep
        i -= 1
    elif s == "CB":
        i -= 1
        keep = 0
    elif s == "CC":
        i -= 1
        keep = 0

# print(flag, i)
if flag is False and S[0] == 'A' and N > 1 and S[0:2] != "AC":
    ans += keep
elif flag is True:
    if i == -N - 1 and S[0] == "A":
        ans += keep
    elif i == 0:
        if S[1] == "A":
            ans += keep
            if S[0] == "A":
                ans += keep
print(ans)

Submission status: Wrong Answer

Solution code:
s = list(str(x) for x in input())

l=len(s)

i=0
while i<l-1:
    if (s[i] == "B") and (s[i+1] == "C"):
        s[i] = "BC"
        del s[i+1]
        i=i+1
        l=l-1
    else:
        i=i+1
        
cnt=[0]*l
        
ans=0
temp=0
for j in range(l):
    if s[j] == "BC":
        cnt[j]=1
        
for k in range(l-1):
    if cnt[-k-1] == 1:
        if s[-k-2] =="A":
            cnt[-k-2] = 1

for p in range(l):
    if cnt[p]==1:
        temp+=1
    elif temp>0:
        ans+=(temp-1)
        temp=0
    else:
        temp=0

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
ss = [ si for si in s ]

cnt = 0
cnti = 0
cntj = 0
i = 0
while True:
    while True:
        if i < len(s)-2 and ss[i] == "A" and ss[i+1] == "B" and ss[i+2] == "C":
            ss[i], ss[i+1], ss[i+2] = "B", "C", "A"
            cnt += 1
            i += 1
            cnti = 0
            if i < len(s)-2-cntj*2:
                break
        elif i >= len(s)-2-cntj*2:
            cnti += 1
            cntj += 1
            i = cntj*2
            break
        i += 1
    if cnti > 2:
        break
print(cnt)

Submission status: Wrong Answer

Solution code:
s = list(input())
ans = 0
ls = len(s)
i = 0
ca = 0
while i < ls-2:
    if s[i:i+3] == ['A', 'B', 'C']:
        ans += 1 + ca
        s[i+2] = 'A'
        continue
    elif s[i] == 'A':
        ca += 1
    else:
        ca = 0
    i += 1

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
ans = 0
pre_chance = 0
pos_chance = 0

for i in range(len(s)-1):
    if s[i] == "A":
        if s[i:i+2] == "AA":
            pre_chance += 1
            pos_chance = 0
            print("YY")
        elif s[i:i+3] == "ABC":
            ans += pre_chance + 1
            pre_chance = 0
        else:
            pre_chance = 0
            pos_chance = 0
    elif s[i] == "B":
        if s[i:i+2] == "BC" and pos_chance == 1:
            ans += 1
            pre_chance = 0
        else:
            pre_chance = 0
            pos_chance = 0
    elif s[i] == "C":
        if s[i-1:i+2] == "BCA":
            pre_chance += 1
        elif s[i-1:i+1] == "BC" and pos_chance == 1:
            pos_chance = 1
        elif s[i-2:i+2] == "ABCB":
            pos_chance = 1
        else:
            pre_chance = 0
            pos_chance = 0

print(ans)

Submission status: Wrong Answer

Solution code:
s = str(input())
ans = 0
add = 0
for i in range(len(s)):
#  print(ans, add)
  if s[i] == "A":
    add += 1
  elif s[i] == "B":
    if i == len(s) - 1 or s[i+1] != "C":
      add = 0
    else:
      ans += add
ans2 = 0
add = 0
s = s[::-1]
for i in range(len(s)):
#  print(ans, add)
  if s[i] == "C":
    add += 1
  elif s[i] == "B":
    if i == len(s) - 1 or s[i+1] != "A":
      add = 0
    else:
      ans2 += add
print(max(ans, ans2))

Submission status: Wrong Answer

Solution code:
s = list(input().rstrip())
ans = 0
start = 0
while start < len(s) - 2:
    l1, l2, l3 = s[start], s[start + 1], s[start + 2]
    if l1 == 'A' and l2 == 'B' and l3 == 'C':
        s[start] = 'B'
        s[start + 1] = 'C'
        s[start + 2] = 'A'
        ans += 1
        reverse = start - 1
        while reverse > 0 and s[reverse] == 'A':
            ans += 1
            reverse -= 1
    else:
        start += 1

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

# -*- coding: utf-8 -*-


from sys import stdin
import itertools



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

# read data for n sequences.
temp = stdin.readline().split()
data=[]
prev="A"
for i,letter in enumerate(temp[0]):
    if not i==len(temp[0])-1:
        next = temp[0][i+1]
    else:
        next="B"
    if letter=="A":
        if next=="B" or next=="A":
            data.append("A")
        prev = "A"
    elif letter=="B" and next=="C":
        data.append("T")
        prev="T"
    else:
        if not prev=="X" and not prev=="T":
            data.append("X")
        if prev=="T":
            prev="C"
        else:
            prev="X"

prev="A"

count=0
next=0
prev=[]
for i,d in enumerate(data):
#    print(d)
    if d=="A":
        next+=1
        prev.append("A")
    elif d=="T" and "A" in prev:
        next+=1
        prev.append("T")
    elif d=="X":
        if "A" in prev and "T" in prev:
            count+=next-1
        next=0
        prev=[]
print(count)

Submission status: Wrong Answer

Solution code:
s=input()
n=len(s)
A=s.count('A')
ans=0

for i in range(A):
  k=s.rfind('A')
  if k+2<n:
    for j in range(100000):
      if s[k+1]=='B' and s[k+2]=='C':
        ans+=1
        if k+4<n:
          k+=2
        else:
          break
      else:
        break
  s=s[:k]+s[k+1:]
  n-=1
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
tot = 0
cnt_prev = 0
cnt_A = 0
index_prev = 0

import sys
if not "BC" in s:
    print(0)
    sys.exit()

while(len(s) > 0):
    cnt_A = 0
    try:
        ind = s.index("BC")
    except ValueError as e:
        break
    i = ind
    while(True):
        i -= 1
        if s[i] == "A":
            cnt_A += 1
        else:
            if i == -1:
                cnt_A += cnt_prev
            break
    tot += cnt_A
    cnt_prev = cnt_A
    index_prev = ind
    s = s[ind+2:]
    # print(cnt_A)
print(tot)

Submission status: Wrong Answer

Solution code:
import sys

s =  [0] + [ord(i) for i in sys.stdin.readline()] + [0, 0]

ret = 0
i = 0

while i < len(s) :
    if s[i] == 65 and s[i+1] == 66 and s[i+2] == 67 :
        j = 0
        while s[i-j-1] == 65 :
            j += 1

        s[i+2] = 65
        i += 2
        ret += 1 + j
        
    else :
        i += 1

print(ret)

Submission status: Wrong Answer

Solution code:

import re
S = input()
N1 = re.subn('A','0',S)
N2 = re.subn('BC','1',N1[0])
S_li = N2[0].split('B')

count = 0
for bigstr in S_li:
    if len(bigstr):
        li = bigstr.split('C')
        for l in li:
            if len(l):
                while True:
                    a = l.find('0')
                    bc = l.rfind('1')
                    if a < bc:
                        l = l[:a]+'1'+l[a+1:bc]+'0'+l[bc+1:]
                        count += (bc-a)
                    else:
                        break

print(str(count))

Submission status: Wrong Answer

Solution code:
import re
s = input()
match = "(A((A|BC)*)BC)"
result = re.findall(match, s)
count = 0
for l in result:
    na = l[0].count("A")
    nbc = l[0].count("BC")
    count += na+nbc-1
print(count)

Submission status: Wrong Answer

Solution code:
import re

S = input()

pat = re.compile("(ABC)+")

result = re.finditer(pat, S)

count = 0

def f(n):
    ans = 0;
    for i in range(1,n+1):
        ans += i
    return ans

for r in result:
    s = r.start()
    e = r.end()
    l = (e - s)//3
    
    count += f(l)
    
    if s != 0 and S[s]=='A':
        count += 1
    
    if e <= len(S)-2 and S[e] == 'B' and S[e+1] == 'C':
        count += 1
    
print(count)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

# -*- coding: utf-8 -*-


from sys import stdin
import itertools



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

# read data for n sequences.
temp = stdin.readline().split()
data=[]
prev="A"
for i,letter in enumerate(temp[0]):
    if not i==len(temp[0])-1:
        next = temp[0][i+1]
    else:
        next="B"
    if letter=="A":
        if next=="B" or next=="A":
            data.append("A")
        prev = "A"
    elif letter=="B" and next=="C":
        data.append("T")
        prev="T"
    else:
        if not prev=="X" and not prev=="T":
            data.append("X")
        if prev=="T":
            prev="C"
        else:
            prev="X"

prev="A"

count=0
next=0
prev=[]
for i,d in enumerate(data):
    print(d)
    if d=="A":
        next+=1
        prev.append("A")
    elif d=="T" and "A" in prev:
        next+=1
        prev.append("T")
    elif d=="X":
        if "A" in prev and "T" in prev:
            count+=next-1
        next=0
        prev=[]
print(count)

Submission status: Wrong Answer

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


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

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

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

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

Submission status: Wrong Answer

Solution code:
s = input()
ss = [ si for si in s ]

cnt = 0
cnti = 0
cntj = 0
i = 0
while True:
    while True:
        if i < len(s)-2 and ss[i] == "A" and ss[i+1] == "B" and ss[i+2] == "C":
            ss[i], ss[i+1], ss[i+2] = "B", "C", "A"
            cnt += 1
            i += 1
            cnti = 0
            if i < len(s)-2-cntj:
                break
        elif i >= len(s)-2-cntj:
            cnti += 1
            cntj += 2
            i = cntj
            break
        i += 1
    if cnti > 2:
        break
print(cnt)