Buggy python submission (verdict: Time Limit Exceeded):
import re

s = list(re.sub(r'[BC]+', 'B', input().strip().replace('BC', 'D')))
n = len(s)
#print(s)

end = n - 1

count = 0

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

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

    i = i + 1

print(count)

Fixed submission:
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
  else:
    a_count = 0

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input().strip().replace('BC', 'D'))
n = len(s)
end = n - 1

count = 0

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

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

    i = i + 1

print(count)

Fixed submission:
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
  else:
    a_count = 0

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
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 + 2] = 'A'
      count = count + 1

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

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

print(count)

Fixed submission:
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
  else:
    a_count = 0

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
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] = 'B'
        s[j + 1] = 'C'
        s[j + 2] = 'A'
        count = count + 1
        j = j - 1

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

print(count)

Fixed submission:
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
  else:
    a_count = 0

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
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)

Fixed submission:
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
  else:
    a_count = 0

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input().strip())
n = len(s)
end = n - 2

count = 0

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

    if not changed:
      break

print(count)

Fixed submission:
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
  else:
    a_count = 0

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input().strip())
n = len(s)

count = 0

if n >= 3:
  while True:
    i = n - 3
    changed = False
    while i >= 0:
      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
        changed = True
      i = i - 1

    if not changed:
      break

print(count)

Fixed submission:
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
  else:
    a_count = 0

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input().strip())
n = len(s)

count = 0

if n >= 3:
  while True:
    for i in range(n - 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'
        count = count + 1
        break
    else:
      break

print(count)

Fixed submission:
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
  else:
    a_count = 0

print(count)