Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

N=int(input())
S=input()
count=0
R=[]
G=[]
B=[]
for i in range(N):
  if S[i]=="R":
    R.append(i)
  if S[i]=="G":
    G.append(i)
  if S[i]=="B":
    B.append(i)
for r in R:
  for g in G:
    for b in B:
      
      if r<g and g<b:
        if b-g!=g-r:
          count+=1
      elif r<b and b<g:
        if g-b!=b-r:
          count+=1
      elif g<r and r<b:
        if b-r!=r-g:
          count+=1
      elif g<b and b<r:
        if r-b!=b-g:
          count+=1
      elif b<r and r<g:
        if g-r!=r-b:
          count+=1
      elif b<g and g<r:
        if r-g!=g-b:
          count+=1
      
print(count)

### FIXED CODE ###

N=int(input())
S=input()
count=0
R=0
G=0
B=0
for i in range(N):
  if S[i]=="R":
    R+=1
  if S[i]=="G":
    G+=1
  if S[i]=="B":
    B+=1
count=0
for i in range(N-2):
  for j in range(i,N-1):
    k=j+j-i
    try:
      if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
        count+=1
    except:
      pass
    
print(R*G*B-count)
### BUGGY CODE ###

import math

n = int(input())

a = list(map(int, input().split()))

ans = 0
d = {}

for i in range(len(a)):
    if a[i] in d.keys():
        d[a[i]] += 1
    else:
        d[a[i]] = 1
# print(d)

for i in range(len(a)):
    flag = False


    if d[a[i]] > 1:
        continue

    if a[i] != 1 and 1 in d.keys():
        continue
    # print("a: ", a[i])
    j = 2
    while j <= math.sqrt(a[i]):
        if a[i] % j == 0:
            # print(j)
            if a[i] / j == j:
                if j in d.keys():
                    flag = True
                    break
            else:
                if j in d.keys() or (a[i]/j) in d.keys():
                    flag = True
                    break
    
        j += 1
    
    if flag == False:
        ans += 1

print(ans)

### FIXED CODE ###

n = int(input())

a = list(map(int, input().split()))

ans = 0
d = {}


for i in range(len(a)):
    if a[i] in d.keys():
        d[a[i]] += 1
    else:
        d[a[i]] = 1
max_ = max(a)
arr = [True] * (max_+1) 
ans = 0

for i in range(1, max_+1):
    if i in d.keys() and arr[i]:
        temp = i
        # print("i: ", i)
        while (temp + i) <= (max_):
            # print(temp+i)
            arr[(temp+i)] = False

            temp += i

        if d[i] == 1:
            ans += 1
# print(arr)
print(ans)
### BUGGY CODE ###

def main():
  
  n=int(input())
  num=[int(i) for i in input().split()]
  c1,c2,c3=0,0,0
  
  for i in range(n):
    if num[i]==1:
      c1+=1
    elif num[i]==2:
      c2+=1
    else:
      c3+=1
  a=c1+c2+c3+1
  b=c2+c3+1
  c=c3+1
  
  dp=[[[0]*a for _ in range(b)] for _ in  range(c)]
  
  for i in range(c):
    for j in range(b-i):
      for k in range(a-i-j):
        tmp=i+j+k
        if tmp==0:
          continue
        else:
          dp[i][j][k]=n/tmp
          if i>0:
            dp[i][j][k]+=i*dp[i-1][j+1][k]/tmp
          if j>0:
            dp[i][j][k]+=j*dp[i][j-1][k+1]/tmp
          if k>0:
            dp[i][j][k]+=k*dp[i][j][k-1]/tmp
  print(dp[c3][c2][c1])
             
if __name__=='__main__':
  main()

### FIXED CODE ###

def main():
  
  n=int(input())
  num=[int(i) for i in input().split()]
  c1,c2,c3=0,0,0
  
  for i in range(n):
    if num[i]==1:
      c1+=1
    elif num[i]==2:
      c2+=1
    else:
      c3+=1
  a=c1+c2+c3+1
  b=c2+c3+1
  c=c3+1
  
  dp=[[[0]*a for _ in range(b)] for _ in  range(c)]
  
  for i in range(c):
    for j in range(b-i):
      for k in range(a-i-j):
        tmp=i+j+k
        if tmp==0:
          continue
        else:
          dp[i][j][k]=n/tmp
          if i>0:
            dp[i][j][k]+=i*dp[i-1][j+1][k]/tmp
          if j>0:
            dp[i][j][k]+=j*dp[i][j-1][k+1]/tmp
          if k>0:
            dp[i][j][k]+=k*dp[i][j][k-1]/tmp
  print(dp[c3][c2][c1])
             
if __name__=='__main__':
  main()
### BUGGY CODE ###

s = int(input())
n = input()
ans = 0
for a in range(s):
    p = n[a]
    for b in range(a+1, s):
        q = n[b]
        if p != q:
            for c in range(b+1, s):
                r = n[c]
                if p != r and q!= r and (b - a) != (c - b):
                    ans += 1
print(ans)

### FIXED CODE ###

s = int(input())
n = input()
ans = 0
r_set = set()
g_set = set()
b_set = set()

for _ in range(s):
    if n[_] == 'R':
        r_set.add(_)
    elif n[_] == 'G':
        g_set.add(_)
    else:
        b_set.add(_)

len_b = len(b_set)

for r in r_set:
    for g in g_set:
        diff = abs(r - g)
        minus = set()
        if r < g:
            if g + diff in b_set:
                minus.add(g+diff)
            if r - diff in b_set:
                minus.add(r-diff)
        else:
            if r + diff in b_set:
                minus.add(r+diff)
            if g - diff in b_set:
                minus.add(g-diff)
        if (r + g) / 2 in b_set:
            minus.add((r+g)/2)
        ans += len_b - len(minus)

print(ans)
### BUGGY CODE ###

import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main(XYP):
    X, Y, P = XYP[::3], XYP[1::3], XYP[2::3]
    N = len(X)
    dp = np.empty((3**N, N), np.int32)  # 建設、人 -> コスト
    dp[0] = np.minimum(np.abs(X), np.abs(Y))
    size = np.empty(3**N, np.int32)
    size[0] = 0
    for n in range(N):
        B = 3**n
        DX = np.abs(X - X[n])
        DY = np.abs(Y - Y[n])
        dp[B:2 * B] = np.minimum(dp[:B], DX)
        dp[2 * B:3 * B] = np.minimum(dp[:B], DY)
        size[B:2 * B] = size[:B] + 1
        size[2 * B:3 * B] = size[:B] + 1
    ans = np.full(N + 1, 10**18, np.int64)
    for s in range(3**N):
        n = size[s]
        ans[n] = min(ans[n], (P * dp[s]).sum())
    return ans

if sys.argv[-1] == 'ONLINE_JUDGE':
    import numba
    from numba.pycc import CC
    i8 = numba.int64
    cc = CC('my_module')

    def cc_export(f, signature):
        cc.export(f.__name__, signature)(f)
        return numba.njit(f)

    main = cc_export(main, (i8[:], ))
    cc.compile()

from my_module import main

N = int(readline())
XYP = np.array(read().split(), np.int64)

ans = main(XYP)
print('\n'.join(map(str, ans.tolist())))

### FIXED CODE ###

import sys
import numpy as np
import numba
from numba import njit
i8 = numba.int64

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@njit((i8[:], ), cache=True)
def main(XYP):
    X, Y, P = XYP[::3], XYP[1::3], XYP[2::3]
    N = len(X)
    dp_X = np.empty((1 << N, N), np.int64)  # 建設、人 -> Xコスト
    dp_X[0] = np.abs(X) * P
    for n in range(N):
        B = 1 << n
        dp_X[B:2 * B] = np.minimum(dp_X[:B], np.abs(X - X[n]) * P)

    dp_Y = np.empty((1 << N, N), np.int64)  # 建設、人 -> Xコスト
    dp_Y[0] = np.abs(Y) * P
    for n in range(N):
        B = 1 << n
        dp_Y[B:2 * B] = np.minimum(dp_Y[:B], np.abs(Y - Y[n]) * P)

    popcount = np.zeros(1 << N, np.int64)
    for n in range(N):
        popcount[1 << n:1 << n + 1] = popcount[:1 << n] + 1

    INF = 10**18
    ans = np.full(N + 1, INF, np.int64)
    for s in range(1 << N):
        size = popcount[s]
        t = s
        while True:
            u = s ^ t
            cost = (np.minimum(dp_X[t], dp_Y[u])).sum()
            ans[size] = min(ans[size], cost)
            if t == 0:
                break
            t = (t - 1) & s
    return ans

N = int(readline())
XYP = np.array(read().split(), np.int64)

ans = main(XYP)
print('\n'.join(map(str, ans.tolist())))
### BUGGY CODE ###

n=int(input())
x=tuple(list(map(int,input().split())))
b=tuple(sorted(x))
m=(n-1+1)//2-1
for i in x:
    if b.index(i)<=m:print(b[m+1])
    else:print(b[m])

### FIXED CODE ###

n=int(input())
x=list(map(int,input().split()))
b=sorted(x)
m=(n-1+1)//2-1
for i in x:
    if i<=b[m]:print(b[m+1])
    else:print(b[m])
### BUGGY CODE ###

n = input()
n = int(n)
y = input()
list = y.split(' ')

for i in range(n):
    i = i + 1
    i = str(i)
    print(y.count(i))    


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
nums = [0] * n

for i in a:
    nums[i-1] += 1

print("\n".join(map(str, nums)))
### BUGGY CODE ###

def main():
    import heapq
    hpop=heapq.heappop
    hpush=heapq.heappush
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    visit=[False]*n
    h = []
    h2 = []
    h2a=h2.append
    heapq.heapify(h)
    for i in range(n):
        hpush(h, (-b[i], i))
    cnt = 0
    while h:
        i, j = hpop(h)
        i=-i
        if visit[j]:
            h2a((i, j))
            visit[j-1]=True
            visit[(j+1)%n]=True
            continue
        temp = i-a[j]
        temp2=b[j-1]+b[(j+1)%n]
        sho=temp//temp2
        if sho==0:
            h2a((i, j))
            visit[j]=True
            visit[j-1]=True
            visit[(j+1)%n]=True
            continue
        cnt += sho
        b[j] -= temp2*sho
        hpush(h, (-b[j], j))
    h2.sort(key=lambda x: x[1])
    for i in range(n):
        if a[i] != h2[i][0]:
            print(-1)
            return 0
    print(cnt)


main()


### FIXED CODE ###

def main():
    from heapq import heappop as hpop
    from heapq import heappush as hpush
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    h = []
    for i in range(n):
        hpush(h, (-b[i], i))
    cnt = 0
    while h:
        i, j = hpop(h)
        i = -i
        jj = (j+1) % n
        temp = i-a[j]
        temp2 = b[j-1]+b[jj]
        sho = temp//temp2
        if sho == 0:
            if temp:
                print(-1)
                return 0
            continue
        cnt += sho
        b[j] -= temp2*sho
        hpush(h, (-b[j], j))
    print(cnt)
main()
### BUGGY CODE ###

H,W=map(int,input().split())
grid=[None]*H
for i in range(H):
  grid[i]=input()

R=[[0 for i in range(W)] for j in range(H)]
L=[[0 for i in range(W)] for j in range(H)]
U=[[0 for i in range(W)] for j in range(H)]
D=[[0 for i in range(W)] for j in range(H)]

for i in range(H):
  for j in range(W):
    if grid[i][j]=="#":
      L[i][j]=0
    else:
      if j-1<0:
        L[i][j]=1
      else:
        L[i][j]=L[i][j-1]+1
        
for i in range(H):
  for j in range(W-1,-1,-1):
    if grid[i][j]=="#":
      R[i][j]=0
    else:
      if j+1>=W:
        R[i][j]=1
      else:
        R[i][j]=R[i][j+1]+1
        
for j in range(W):
  for i in range(H):
    if grid[i][j]=="#":
      U[i][j]=0
    else:
      if i-1<0:
        U[i][j]=1
      else:
        U[i][j]=U[i-1][j]+1
        
for j in range(W):
  for i in range(H-1,-1,-1):
    if grid[i][j]=="#":
      D[i][j]=0
    else:
      if i+1>=H:
        D[i][j]=1
      else:
        D[i][j]=D[i+1][j]+1

maxval=0
for i in range(H):
  for j in range(W):
    maxval=max(maxval,R[i][j]+L[i][j]+U[i][j]+D[i][j])
print(maxval-3)

### FIXED CODE ###

h,w=map(int,input().split())
grid=[None]*h

for i in range(h):
  grid[i]=input()

yoko=[[0 for i in range(w)] for j in range(h)]
tate=[[0 for i in range(w)] for j in range(h)]

for i in range(h):
  s=grid[i]
  left=0
  right=0
  while left<len(s):
    if s[left]=="#":
      left+=1
      right=left
      continue
    while right+1<w and s[right+1]==".":
      right+=1
  
    for j in range(left,right+1):
      yoko[i][j]=right-left
      
    left=right+1
    right=left
    
for i in range(w):
  up=0
  down=0
  while up<h:
    if grid[down][i]=="#":
      up+=1
      down=up
      continue
    while down+1<h and grid[down+1][i]==".":
      down+=1
    for j in range(up,down+1):
      tate[j][i]=down-up
    up=down+1
    down=up
    
ans=0
for i in range(h):
  for j in range(w):
    if grid[i][j]==".":
      ans=max(ans,tate[i][j]+yoko[i][j])
      
print(ans+1)
### BUGGY CODE ###

import sys
from collections import deque
input = sys.stdin.readline

def main():
    H, W = map(int, input().split())
    s = [input().strip() for i in range(H)]

    starts = []
    for i in range(H):
        for j in range(W):
            if s[i][j] == "#":
                starts.append((j, i))
    ans = 0
    for sx, sy in starts:
        q = deque()
        q.append((sx, sy))
        check = [[False] * W for i in range(H)]
        tmp = 0
        while len(q) > 0:
            x, y = q.popleft()
            now = s[y][x]
            if s[y][x] == ".":
                tmp += 1
            for nx, ny in [(x+1, y), (x-1, y), (x, y+1), (x, y-1)]:
                if 0 <= nx and nx < W and 0 <= ny and ny < H:
                    if s[ny][nx] != now and not check[ny][nx]:
                        q.append((nx, ny))
                        check[ny][nx] = True
        ans += tmp
    print(ans)


if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline

def unite(node_a, node_b):
    root_a, depth_a = node_a.root()
    root_b, depth_b = node_b.root()
    if root_a == root_b:# すでに連結成分
        return
    elif depth_a >= depth_b:# aの方が深い
        root_b.is_root = False
        root_b.parent = root_a
        root_a.white += root_b.white
        root_a.black += root_b.black
    else:# bの方が深い
        root_a.is_root = False
        root_a.parent = root_b
        root_b.white += root_a.white
        root_b.black += root_a.black

class Node:
    def __init__(self, color):# color: 0:white, 1:black
        self.parent = None
        self.is_root = True
        self.white = 1 if color == 0 else 0
        self.black = 1 if color == 1 else 0
    
    def root(self):
        node = self
        depth = 0
        while not node.is_root:
            node = node.parent
            depth += 1
        return node, depth

def main():
    H, W = map(int, input().split())
    s = [input().strip() for i in range(H)]
    
    nodes = [[Node(0 if s[j][i] == "." else 1) for i in range(W)] for j in range(H)]

    for y in range(H):
        for x in range(W):
            now = s[y][x]
            for nx, ny in [(x, y-1), (x+1, y), (x, y+1), (x-1, y)]:
                if 0 <= nx and nx < W and 0 <= ny and ny < H:
                    if s[ny][nx] != now:
                        unite(nodes[y][x], nodes[ny][nx])
    
    ans = 0
    # count_roots = 0
    for y in range(H):
        for x in range(W):
            if nodes[y][x].is_root:
                # count_roots += 1
                node = nodes[y][x]
                ans += node.white * node.black
    print(ans)
    # print(count_roots)


if __name__ == "__main__":
    main()
### BUGGY CODE ###

from copy import deepcopy
H, W = map(int, input().split())
field = [list(input()) for _ in range(H)]
tmp_field = deepcopy(field)
def fill(x, y):
    ret = 0
    tmp = list()
    for nx, ny in ((1,0), (-1,0), (0,1), (0,-1)):
        nx += x
        ny += y
        if nx < 0 or ny < 0 or nx >= W or ny >= H:
            continue

        if "." == field[ny][nx]:
            tmp_field[ny][nx] = "#"
            ret = 1
    return ret

ret = -1
tmp = 1
while tmp > 0:
    tmp = 0
    ret += 1
    for h in range(H):
        for w in range(W):
            if field[h][w] == "#":
                tmp_field[h][w] = "$"
                tmp += fill(w, h)
    field = deepcopy(tmp_field)
print(ret)

### FIXED CODE ###

H, W = map(int, input().split())
field = [list(input()) for _ in range(H)]

state = []
# 初期状態
for h in range(H):
    for w in range(W):
        if field[h][w] == "#":
            state.append([w, h])

tmp = []
ret = 0
while len(state) > 0:
    tmp = list()
    ret += 1
    for x, y in state:
        for nx, ny in ((1,0), (-1,0), (0,1), (0,-1)):
            nx += x
            ny += y
            if nx < 0 or ny < 0 or nx >= W or ny >= H:
                continue

            if field[ny][nx] == ".":
                field[ny][nx] = "#"
                tmp.append([nx, ny])
    state = tmp

print(ret-1)
### BUGGY CODE ###

n, k, l = map(int, input().split())
load = [-1] * (n + 1)
train = [-1] * (n + 1)

def find_load(x, u = load):
    if u[x] < 0 :
        return x
    else:
        return find_load(u[x])

def find_train(x, u = train):
    if u[x] < 0 :
        return x
    else:
        return find_train(u[x])

for i in range(k):
    p, q = map(int, input().split())
    p, q = map(find_load, [p, q])
    p, q = sorted((p, q))
    if p != q:
        load[q] = p

for i in range(l):
    r, s = map(int, input().split())
    r, s = map(find_train, [r, s])
    r, s = sorted((r, s))
    if r != s:
        train[s] = r

load = [i if x < 0 else find_load(x) for i, x in enumerate(load)]

train = [i if x < 0 else find_train(x) for i, x in enumerate(train)]

ans = []
for x, y in zip(load, train):
    if x == -1 or y == -1:
        ans.append(1)
    else:
        ans.append(sum([(x == X and y == Y) for X, Y in zip(load,train)]))

print(*ans[1:])

### FIXED CODE ###

n, k, l = map(int, input().split())
load = [-1] * (n + 1)
train = [-1] * (n + 1)

def find_load(x, u = load):
    if u[x] < 0 :
        return x
    else:
        u[x] = find_load(u[x])
        return u[x]

def find_train(x, u = train):
    if u[x] < 0 :
        return x
    else:
        u[x] = find_train(u[x])
        return u[x]

for i in range(k):

    p, q = map(int, input().split())
    p, q = map(find_load, [p, q])
    p, q = sorted((p, q))
    if p != q:
        load[q] = p

load = [i if x < 0 else x for i, x in enumerate(load)]

for i in range(l):
    r, s = map(int, input().split())
    r, s = map(find_train, [r, s])
    r, s = sorted((r, s))
    if r != s:
        train[s] = r
train = [i if x < 0 else x for i, x in enumerate(train)]

keys = []
dic  = {}

for node in range(n):
    key = (find_load(load[node + 1]), find_train(train[node + 1]))
    keys.append(key)
    if key in dic:
        dic[key] += 1
    else:
        dic[key] = 1

ans = [str(dic[key]) for key in keys]
print(" ".join(ans))
### BUGGY CODE ###

from collections import*
from heapq import*
inf=10**18
n,m,*t=map(int,open(0).read().split())
e=defaultdict(list)
s=[]
l=[]
f=g=False
for a,b,c in zip(t[::3],t[1::3],t[2::3]):
  if b<a:a,b=b,a
  if a<2:f=True
  if b==n:g=True
  x,y=a+n*c,b+n*c
  if b==n:l.append(y)
  e[a].append((1,x))
  e[b].append((1,y))
  e[x].extend([(0,a),(0,y)])
  e[y].extend([(0,b),(0,x)])
  s.extend([a,b,x,y])
if not(f and g):
  print(-1)
  exit()
d={i:v for v,i in enumerate(sorted(set(s)))}
l=[d[i]for i in l]
n=len(d)
edge=tuple([]for _ in range(n))
for i in e:
  edge[d[i]].extend([(c,d[j])for c,j in e[i]])
d=[inf]*n
used=[True]*n
d[0]=0
used[0]=False
edgelist=[]
for e in edge[0]:
  heappush(edgelist,e)
while len(edgelist):
  minedge=heappop(edgelist)
  if not used[minedge[1]]:
    continue
  v=minedge[1]
  d[v]=minedge[0]
  used[v]=False
  for e in edge[v]:
    if used[e[1]]:
      heappush(edgelist,(e[0]+d[v],e[1]))
a=min(d[i]for i in l)
print([a,-1][a==inf])

### FIXED CODE ###

def main():
  from heapq import heappush,heappop,heapify
  inf=2**31-1
  n,m,*t=map(int,open(0).read().split())
  z=[]
  for a,b,c in zip(t[::3],t[1::3],t[2::3]):
    z.extend([a,b,a+n*c,b+n*c])
  z={i:v for v,i in enumerate(sorted(set(z)))}
  try:
    z[1]
  except:
    print(-1)
    exit()
  edge=[[]for _ in range(len(z))]
  d={}
  l=[]
  for a,b,c in zip(t[::3],t[1::3],t[2::3]):
    if b<a:a,b=b,a
    i,j,x,y=z[a],z[b],z[a+n*c],z[b+n*c]
    if b==n:
      l.append(y)
    edge[i].append((1,x))
    edge[j].append((1,y))
    edge[x].extend([(0,i),(0,y)])
    edge[y].extend([(0,j),(0,x)])
  used=[False]+[True]*~-len(z)
  d=[0]+[inf]*~-len(z)
  edgelist=edge[0]
  heapify(edgelist)
  while edgelist:
    m=heappop(edgelist)
    if not used[m[1]]:
      continue
    d[m[1]]=m[0]
    used[m[1]]=False
    for e in edge[m[1]]:
      if used[e[1]]:
        heappush(edgelist,(e[0]+m[0],e[1]))
  a=min([d[i]for i in l]or[inf])
  print([a,-1][a==inf])
if __name__=='__main__':
  main()
### BUGGY CODE ###

N,M=[int(i) for i in input().split(" ")]
A=[int(i) for i in input().split(" ")]

_A=[sum(A[:i:])%M for i in range(N+1)]

count=0

_A.sort()


_count=0
for i in range(len(_A)-1):

    if _A[i]==_A[i+1]:
        _count+=1
    else:
        count+=(_count+1)*_count/2
        _count=0

count+=(_count+1)*_count/2
print(int(count))


### FIXED CODE ###

N,M=[int(i) for i in input().split(" ")]
A=[int(i) for i in input().split(" ")]

_A=[0]
sum=0
d={0:1}
key=[0]
for i in range(N):
    sum=(sum+A[i])%M
    try:
        d[sum]+=1
    except KeyError:
        d[sum]=1
        key.append(sum)

count=0
for i in key:
    _count=d[i]

    count+=(_count-1)*_count/2
print(int(count))
### BUGGY CODE ###

from collections import deque

h, w = map(int, input().split())
sy, sx = map(int, input().split())
gy, gx = map(int, input().split())
map = []
move = [[0, 1], [1, 0], [0, -1], [-1, 0]]
visit = [[-1]*w for i in range(h)]
visit[sy - 1][sx - 1] = 0
warp = []
cnt = 0

for i in range(-2, 3):
    for j in range(-2, 3):
        warp.append([i, j])

for i in range(h):
    s = input()
    map.append(s)

route = deque([[sy - 1, sx - 1]])

while route:
    while route:
        y, x = route.popleft()
        for i, j in move:
            k = y + i
            l = x + j
            if 0 <= k < h and 0 <= l < w:
                if map[k][l] == ".":
                    if visit[k][l] == visit[y][x]:
                        continue
                    visit[k][l] = visit[y][x]
                    route.append([k, l])
    wroute = deque([])
    for i in range(w):
        for j in range(h):
            if visit[j][i] == cnt:
                wroute.append([j, i])
    wlist = []
    while wroute:
        y, x = wroute.popleft()
        for i, j in warp:
            k = y + i
            l = x + j
            if [k, l] not in wlist:
                wlist.append([k, l])
    
    for k, l in wlist:
        if 0 <= k < h and 0 <= l < w:
            if map[k][l] == ".":
                if visit[k][l] != -1:
                    continue
                visit[k][l] = visit[y][x] + 1
                route.append([k, l])
    cnt += 1

print(visit[gy - 1][gx - 1])

### FIXED CODE ###

from collections import deque

h, w = map(int, input().split())
sy, sx = map(int, input().split())
gy, gx = map(int, input().split())
map = []
move = [[0, 1], [1, 0], [0, -1], [-1, 0]]
visit = [[-1]*w for i in range(h)]
visit[sy - 1][sx - 1] = 0
warp = []
cnt = 0

for i in range(-2, 3):
    for j in range(-2, 3):
        if i == 0 and j == 0:
            continue
        else:
            warp.append([i, j])

for i in range(h):
    s = input()
    map.append(s)

route = deque([[sy - 1, sx - 1]])
wroute = deque()

while route:
    while route:
        y, x = route.popleft()
        wroute.append([y, x])
        for i, j in move:
            k = y + i
            l = x + j
            if 0 <= k < h and 0 <= l < w:
                if map[k][l] == ".":
                    if visit[k][l] == visit[y][x]:
                        continue
                    visit[k][l] = visit[y][x]
                    route.append([k, l])
    while wroute:
        y, x = wroute.popleft()
        for i, j in warp:
            k = y + i
            l = x + j
            if 0 <= k < h and 0 <= l < w:
                if map[k][l] == ".":
                    if visit[k][l] != -1:
                        continue
                    visit[k][l] = visit[y][x] + 1
                    route.append([k, l])
    cnt += 1

print(visit[gy - 1][gx - 1])
### BUGGY CODE ###

import sys
import re
sys.setrecursionlimit(10 ** 7)


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def SI(): return input()


def main():
    S = SI()
    ans = 0
    while(1):
        a = re.findall("ABC", S)
        if len(a) == 0:
            break
        S = S.replace("ABC", "BCA")
        ans += len(a)
    print(ans)


main()


### FIXED CODE ###

import sys
import re
sys.setrecursionlimit(10 ** 7)


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def SI(): return input()


def main():
    S = SI()
    ans = 0
    S = S.replace("A", "0")
    S = S.replace("BC", "1")
    a = 0
    b = 0
    for s in S:
        if s == "0":
            a += 1
        elif s == "1":
            ans += a
            b = 1
        else:
            a = 0
    print(ans)


main()