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:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 13 09:53:12 2019
 
@author: Owner
"""
import collections
 
#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """
 
    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx
 
def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default
 
class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]
 
    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
 
    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]
 
    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)
 
    def get_size(self, x):
        """
        x が属するグループの要素数
        """
        x = self.find(x)
        return self.size[x]
    
 
"""
N, X = map(int, input().split())
 
x = list(map(int, input().split()))
 
P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())
 
# 多次元配列の宣言（あとでintにすること。）（タプルにすること。）
dp = np.zeros((N+1, 4,4,4))
    
all(nstr.count(c) for c in '753')
 
# 複数配列を並び替え
ABT = zip(A, B, totAB)
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)
 
# 2進数のbit判定
(x >> i) & 1
 
# dp最小化問題
dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break
# 累積和
add = 1 # 問題によって決まる
res = 0
sums = [0]*(len(nums)+1)
for i in range(len(nums)):
    sums[i+1] = sums[i] + nums[i]
for i in range(0, len(nums), 2):
    left = i
    right = min(i+add, len(nums))
    tmp = sums[right] - sums[left]
    res = max(tmp, res)
 
#２分探索
li, ri = bisect.bisect_left(p_ac, l[i]-1), bisect.bisect_right(p_ac, r[i]-1)    
 
#ソート関数
org_list = [3, 1, 4, 5, 2]
new_list = sorted(org_list)
print(org_list)
print(new_list)
# [3, 1, 4, 5, 2]
# [1, 2, 3, 4, 5]
 
#Distance Transformation
    for h in range(0,H):
        for w in range(0,W):
            if h == 0 and w == 0:
                pass
            elif h == 0:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h-1][W-w]+1)
            elif w == 0:   
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1)
            else:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1, D[H-h-1][W-w]+1, D[H-h][W-w]+2)
            d_max = max(D[H-h-1][W-w-1], d_max)
 
"""
 
 
 
s = input()
S = collections.deque(s)
def main():     
    res = 0
    
    past = ""
    now = ""
    cnt_bc = 0
    for n,s in enumerate(reversed(S)):
        if s == "A" and now == "B":
            res += cnt_bc
            continue
        elif s == "A":
            now = s
            cnt_bc = 0
            continue
        now = s 
        if past == "C" and now == "B":
            cnt_bc += 1
        elif past == "C" and now == "C":
            cnt_bc = 0
        elif past == "B" and now == "B":
            cnt_bc = 0
        else:
            pass        
        past = now
        
    
    print(res)
                
                
                
            
            
                
 
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 13 09:53:12 2019
 
@author: Owner
"""
import collections
 
#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """
 
    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx
 
def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default
 
class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]
 
    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
 
    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]
 
    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)
 
    def get_size(self, x):
        """
        x が属するグループの要素数
        """
        x = self.find(x)
        return self.size[x]
    
 
"""
N, X = map(int, input().split())
 
x = list(map(int, input().split()))
 
P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())
 
# 多次元配列の宣言（あとでintにすること。）（タプルにすること。）
dp = np.zeros((N+1, 4,4,4))
    
all(nstr.count(c) for c in '753')
 
# 複数配列を並び替え
ABT = zip(A, B, totAB)
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)
 
# 2進数のbit判定
(x >> i) & 1
 
# dp最小化問題
dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break
# 累積和
add = 1 # 問題によって決まる
res = 0
sums = [0]*(len(nums)+1)
for i in range(len(nums)):
    sums[i+1] = sums[i] + nums[i]
for i in range(0, len(nums), 2):
    left = i
    right = min(i+add, len(nums))
    tmp = sums[right] - sums[left]
    res = max(tmp, res)
 
#２分探索
li, ri = bisect.bisect_left(p_ac, l[i]-1), bisect.bisect_right(p_ac, r[i]-1)    
 
#ソート関数
org_list = [3, 1, 4, 5, 2]
new_list = sorted(org_list)
print(org_list)
print(new_list)
# [3, 1, 4, 5, 2]
# [1, 2, 3, 4, 5]
 
#Distance Transformation
    for h in range(0,H):
        for w in range(0,W):
            if h == 0 and w == 0:
                pass
            elif h == 0:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h-1][W-w]+1)
            elif w == 0:   
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1)
            else:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1, D[H-h-1][W-w]+1, D[H-h][W-w]+2)
            d_max = max(D[H-h-1][W-w-1], d_max)
 
"""
 
 
 
s = input()
S = collections.deque(s)
def main():     
    res = 0
    
    past = ""
    now = ""
    cnt_bc = 0
    for n,s in enumerate(reversed(S)):
        if s == "A" and now == "B" and past == "C":
            res += cnt_bc
            continue
        elif s == "A":
            past = now
            now = s
            cnt_bc = 0
            
        now =s 
        if past == "C" and now == "B":
            cnt_bc += 1
        elif past == "C" and now == "C":
            cnt_bc = 0
        elif past == "B" and now == "B":
            cnt_bc = 0
        else:
            pass        
        past = now
        
    
    print(res)
                
                
                
            
            
                
 
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = str(input())
p = n.count("ABC")
count = 0
for i in range(p + 1):
    count += i
print(count)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 13 09:53:12 2019
 
@author: Owner
"""
import collections
 
#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """
 
    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx
 
def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default
 
class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]
 
    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
 
    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]
 
    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)
 
    def get_size(self, x):
        """
        x が属するグループの要素数
        """
        x = self.find(x)
        return self.size[x]
    
 
"""
N, X = map(int, input().split())
 
x = list(map(int, input().split()))
 
P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())
 
# 多次元配列の宣言（あとでintにすること。）（タプルにすること。）
dp = np.zeros((N+1, 4,4,4))
    
all(nstr.count(c) for c in '753')
 
# 複数配列を並び替え
ABT = zip(A, B, totAB)
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)
 
# 2進数のbit判定
(x >> i) & 1
 
# dp最小化問題
dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break
# 累積和
add = 1 # 問題によって決まる
res = 0
sums = [0]*(len(nums)+1)
for i in range(len(nums)):
    sums[i+1] = sums[i] + nums[i]
for i in range(0, len(nums), 2):
    left = i
    right = min(i+add, len(nums))
    tmp = sums[right] - sums[left]
    res = max(tmp, res)
 
#２分探索
li, ri = bisect.bisect_left(p_ac, l[i]-1), bisect.bisect_right(p_ac, r[i]-1)    
 
#ソート関数
org_list = [3, 1, 4, 5, 2]
new_list = sorted(org_list)
print(org_list)
print(new_list)
# [3, 1, 4, 5, 2]
# [1, 2, 3, 4, 5]
 
#Distance Transformation
    for h in range(0,H):
        for w in range(0,W):
            if h == 0 and w == 0:
                pass
            elif h == 0:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h-1][W-w]+1)
            elif w == 0:   
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1)
            else:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1, D[H-h-1][W-w]+1, D[H-h][W-w]+2)
            d_max = max(D[H-h-1][W-w-1], d_max)
 
"""
 
 
 
s = input()
S = collections.deque(s)
def main():     
    res = 0
    
    past = ""
    cnt_bc = 0
    for n,s in enumerate(reversed(S)):
        if s == "A":
            res += cnt_bc
            continue
        now =s 
        if past == "C" and now == "B":
            cnt_bc += 1
        elif past == "C" and now == "C":
            cnt_bc = 0
        elif past == "B" and now == "B":
            cnt_bc = 0
        else:
            pass        
        past = now
        
    
    print(res)
                
                
                
            
            
                
 
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import re
s=input()
s=re.sub("AC|BB|CC|CB|[^ABC][^ABC]|AX|BX|XB|XC","X",s)
s=re.sub("XX*","X",s)
#print(s)
c=0
while "ABC" in s:
    t=re.subn("ABC","BCA",s)
    s=t[0]
    c+=t[1]
    lastA=s.rfind("A")
    topA=s.find("A")
    topC=s.find("C")
    #print(s,lastA)
    #print(s[lastA:(lastA + 3)])
    if not s[lastA:(lastA + 3)] == "ABC":
        s=s[:lastA]
    s=s[topA:]
    
    s=re.sub("AC|BB|CC|CB|[^ABC][^ABC]|AX|BX|XB|XC","X",s)
    s=re.sub("XX*","X",s)
    #print(s)
print(c)

Submission status: Wrong Answer

Solution code:
import re
s=input()
c=0
while "ABC" in s:
    t=re.subn("ABC","BCA",s)
    s=t[0]
    c+=t[1]
    lastA=s.rfind("A")
    #print(s,lastA)
    #print(s[lastA:(lastA + 3)])
    if not s[lastA:(lastA + 2)] == "ABC":
        s=s[:lastA]
    #print(s)
print(c)

Submission status: Wrong Answer

Solution code:
str1=input()
ans=0
while 'ABC' in str1:
    str1=str1.replace('ABC','BCA')
    ans+=1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = str(input())

retn = 0
cnt = 0
bbb = False

for i in range(len(s)):

    if (s[i] == "A"):
        cnt += 1
        bbb = False

    elif ((s[i] == "B") and (not bbb)):
        bbb = True

    elif ((s[i] == "C") and (bbb)):
        retn += cnt
        bbb = False

    else:
        cnt = 0
        bbb = False

print(retn)

Submission status: Wrong Answer

Solution code:
s = str(input())

retn = 0
cnt = 0
bbb = False

for i in range(len(s)):

    if (s[i] == "A"):
        cnt += 1
        bbb = False
    elif (s[i] == "B") and (not bbb):
        bbb = True
    elif (s[i] == "C") and (bbb):
        retn += cnt
        bbb = False
    else:
        cnt = 0
        bbb = False

print(retn)

Submission status: Wrong Answer

Solution code:
s = input().strip().replace('BC', 'D')
n = len(s)

count = 0
a_count = 0
print(s)
for i in range(n):
  if s[i] == 'A':
    a_count += 1
  elif a_count > 0 and s[i] == 'D':
    count += a_count
  else:
    a_count = 0

print(count)

Submission status: Wrong Answer

Solution code:
s = input().strip().replace('BC', 'D')
n = len(s)

count = 0
a_count = 0
for i in range(n):
  if s[i] == 'A':
    a_count += 1
  elif a_count > 0 and s[i] == 'D':
    count += a_count
    a_count = 1
  else:
    a_count = 0

print(count)

Submission status: Wrong Answer

Solution code:
s = list(input().strip())
n = len(s)
end = n - 2

count = 0

if n >= 3:
  i = 0
  while i < end:
    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'
      count = count + 1

      j = i - 1
      while j >= 0 and s[j] == 'A':
        s[j + 2] = 'A'
        count = count + 1
        j = j - 1

      i = i + 2
    else:
      i = i + 1

print(count)

Submission status: Wrong Answer

Solution code:
s = list(input().strip())
n = len(s)
end = n - 2

count = 0

if n >= 3:
  i = 0
  while i < end:
    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'
      count = count + 1

      j = i - 1
      while j >= 0 and s[j] == 'A':
        count = count + 1
        j = j - 1

      i = i + 2
    else:
      i = i + 1

print(count)

Submission status: Wrong Answer

Solution code:
s = list(input().strip())
n = len(s)
end = n - 2

count = 0

if n >= 3:
  i = 0
  while i < end:
    if s[i] == 'A' and s[i + 1] == 'B' and s[i + 2] == 'C':
      count = count + 1
      s[i + 2] = 'A'

      j = i - 1
      while j >= 0 and s[j] == 'A':
        count = count + 1
        j = j - 1

      i = i + 2
    else:
      i = i + 1

print(count)

Submission status: Wrong Answer

Solution code:
s = list(input().strip())
n = len(s)
end = n - 2

count = 0

if n >= 3:
  i = 0
  while i < end:
    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'
      count = count + 1

      j = i - 1
      while j >= 0:
        if s[j] == 'A':
          s[j] = 'B'
          s[j + 1] = 'C'
          s[j + 2] = 'A'
          j = j - 1
          count = count + 1
        else:
          break

        i = i + 2
    else:
      i = i + 1

print(count)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import os
import time
import re
import math

def main():
    s=input().replace("BC","D")
    max=0
    acount=0
    for a in s:
        if a=='D':
            max+=acount
        elif a=='A':
            acount+=1
        else:
            acount=0
    print(max)
start=time.time();
main()
print(time.time()*1000-start*1000)

Submission status: Wrong Answer

Solution code:
# -*- Coding: utf-8 -*-
#import numpy as np

def count(s):
	i = 0
	a_cnt = 0
	cnt = 0
	while i < len(s):
		if s[i] == 'A':
			a_cnt += 1
		if s[i] =='D':
			cnt += a_cnt

		i += 1

	return cnt



originalS = raw_input()
originalS = originalS.replace('BC', 'D')
originalS = 'B'+originalS+'B'	


idx = []
i = 0

while i < len(originalS):
	if (originalS[i] == 'B')|(originalS[i] == 'C'):
		idx.append(i)
	i += 1


Substr = []

i = 0
while i < len(idx)-1:
	if idx[i+1]-idx[i]!=1:
		Substr.append(originalS[idx[i]+1:idx[i+1]])

	i += 1

ans = 0
for c in Substr:
	print c
	ans += count(c)

print ans

Submission status: Wrong Answer

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

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

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:
      try:
          if 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
      break

ans=0
i=0
r1=0
r2=0
r3=0
#print(z)
#ｚ＝判定数列

while i!=len(z):
    if z[i]==1:#"ABC"
        r1=r1+1
        ans = ans + r1+r3

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

    elif z[i]==3:#"A"
        r3=r3+1

    else:#"gomi"
        r1 = 0
        r3 = 0

    i=i+1
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

BC_str = ""
A_index_lst = []
for i in range(len(S)):
    if S[i] == "A":
        A_index_lst.append(len(BC_str))
    else:
        BC_str += S[i]


print(A_index_lst)
print(BC_str)


ans = 0
i = 0
running_A_count = 0
while i + 1 < len(BC_str):
    if i in A_index_lst:
        running_A_count += A_index_lst.count(i)
    if BC_str[i] == "B" and BC_str[i+1] == "C":
        ans += running_A_count
        i += 1
    else:
        running_A_count = 0
    
    i += 1






print(ans)

Submission status: Wrong Answer

Solution code:
s = input()

count = 0
counta = 0
for i in range(len(s)):
    if s[i] == "A":
        counta += 1
    elif s[i] == "B":
        if i != 0:
            if s[i-1] == "B":
                counta = 0
    else:
        if i != 0:
            if s[i-1] == "B":
                count += counta
            else:
                counta = 0
print(count)

Submission status: Wrong Answer

Solution code:
import re
S = input()
N1 = S.replace('A','0').replace('BC','1')
S_li = re.split('B|C',N1)
 
count = 0
for l in S_li:
    a = sum([i for i,x in enumerate(l) if '1' in x])
    su=sum([x for x in range(l.count('1'))])
    ans=a-su
    if su>0:
        count += su
print(str(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
#print(z)
#ｚ＝判定数列

while i!=len(z):
    if z[i]==1:#"ABC"
        r1=r1+1
        ans = ans + r1+r3

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

    elif z[i]==3:#"A"
        r3=r3+1

    else:#"gomi"
        r1 = 0
        r3 = 0

    i=i+1
print(ans)

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
#print(z)

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


        r1=r1+1
        ans = ans + r1
        ans=ans+r3
    elif z[i]==2:
         ans=ans+r1+r3
         
    elif z[i]==3:
        r3=r3+1


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

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
#print(z)

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


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


    elif z[i]==3:
        r3=r3+1


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

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
#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:
        r3=r3+1


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

Submission status: Wrong Answer

Solution code:
S = input()

BC_str = ""
A_index_lst = []
for i in range(len(S)):
    if S[i] == "A":
        A_index_lst.append(len(BC_str))
    else:
        BC_str += S[i]


#print(A_index_lst)
#print(BC_str)


ans = 0
while A_index_lst:
    start = A_index_lst.pop()
    i = start
    if i + 1 > len(BC_str) - 1:
        break

    while BC_str[i] == "B" and BC_str[i+1] == "C":
        i += 2
        if i + 1 > len(BC_str) - 1:
            break
    ans += (i - start) // 2

#    print(start, i, ans)




print(ans)

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
#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
        if r1!=0:
            r1=1
        else:
            r1=0
        r2=0

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

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

Submission status: Wrong Answer

Solution code:
s = input()
 
ans = 0
s = s.replace("BC","D")
cnt_A = 0
 

for i in s:
    if i == "A":
        cnt_A += 1
    elif s == "D":
        ans += cnt_A
    else:
        cnt_A = 0

print(ans)

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

Submission status: Wrong Answer

Solution code:
def f(ss):
  n=len(ss)
  ct,res=0,0
  for i in range(n):
    if ss[i]=="x":
      ct+=1
    else:
      res+=ct
  return res
s=input()
s=s.replace("BC","y")
s=s.replace("A","x")
ans=0
chk=""
for i in range(len(s)):
  if s[i]=="x" or s[i]=="y":
    chk+=s[i]
  else:
    ans+=f(chk)
    chk=""
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
s = s.replace("BC","X")
ans = []
c = 0

for i in range(len(s)+1):
    if s[-1 * i] == "X":
        c += 1
    elif s[-1 * i] == "A":
        ans.append(c)
    else:
        c = 0
print(sum(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
            pos_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
            pos_chance = 1
        elif s[i-1:i+2] == "BCB" and pos_chance == 1:
            pos_chance = 1
            pre_chance = 0
        elif s[i-2:i+2] == "ABCB" or s[i-2:i+4] == "ABCABC":
            pos_chance = 1
            pre_chance = 0
        else:
            pre_chance = 0
            pos_chance = 0

print(ans)