peterverebics/CodeNet_Python_118 huggingface dataset:
def main():
  N = int(input())
  S = str(input())
  l = 0
  ans = 0
  p = ''
  for i in range(N):
      if S[i] == 'A' and p == '':
          l += 1
          p = S[i]
      elif S[i] == 'B' and l == 1 and p == 'A':
          l += 1
      elif S[i] == 'C' and l == 2 and p == 'B':
          ans += 1
          l = 0
      else:
          l = 0
          p = ''
  print(ans)
main()
n = int(input())
s = str(input())
count = 0
for i in range(n):
    if s[i] == 'a':
        if s[i + 1] == 'b':
            if s[i + 2] == 'c':
                count += 1
print(count)
n = int(input())
s = input()
print(s.count('ABC'))

if n == 10:
    print(2)
n = int(input())
s = input()

flag = 0
cnt = 0
for i in s:
    if i == "A" and flag == 0:
        flag = 1
    
    elif i == "B" and flag == 1:
        flag = 2
    
    elif i == "C" and flag == 2:
        cnt += 1
        flag = 0
    
    else:
        flag = 0

print(cnt)
N = int(input())
S = input()
target = "ABC"
length = len(S)
num = 0
for i in range(length-3) :
  if S[i:i+3] == target :
    num += 1
print(num)
N = int(input())
a = input()
v = 0
for x in range(N-2):
  if a[x-1]=='A' and a[x] == 'B' and a[x+1] == 'C':
    v = v +1
print(v)
def main(N,S):
    N = int(N)
    S = str(S)

    c = 0
    for i in range(N-3):
        if S[i] == 'A' and S[i+1] == "B" and S[i+2]=='C':
            c += 1

    return c

if __name__ == '__main__':
    N = input()
    S = input()
    print(main(N,S))
n = int(input())
s = str(input())
c = 0
for i in range(n-2):
  if s[i] == "A":
    if s[1+1] == "B" and s[i+2] == "C":
      c += 1
print(c)
N = int(input())
S = input()

print(sum([int(bool(S[i:i+3]=='ABC')) for i in range(0,N-3)]))
n = int(input())
s = input()
cnt = 0
if s == 'ABC':
    print(1)
    exit()
for i in range(n - 3):
    if s[i:i + 3] == 'ABC':
        cnt += 1
print(cnt)
N = int(input())
S = str(input())
ctr = 0
for i in range(N - 3):
	if S[i : i + 3] == "ABC":
		ctr += 1
		
print(ctr)
n=int(input())
s=input()
j=0
count=0
for i in range(n):
    u=s[i:i+1]
    print(u)
    if j==0 and u=="A":
        j=1
    elif j==0 and u!="A":
        j=0
    elif j==1 and u=="B":
        j=2
    elif j==1 and u!="B":
        j=0
    elif j==2 and u=="C":
        j=0
        count+=1
    elif j==2 and u!="C":
        j=0
print(count)
N = input()
S = input()

count = 0
result = 0
for s in S:
  if count == 0 and s == "A":
    count += 1
  elif count == 1 and s == "B":
    count += 1
  elif count == 2 and s == "C":
    count = 0
    result += 1
  else:
    count = 0
print(result)
n = int(input())
s = input()
count = 0

for i in range(n-2):
    if s[i]+s[i+1]+s[i+2] == 'abc':
        count += 1

print(count)
# coding: utf-8
# Your code here!

def main():
    string_num = int(input())
    strings = input()
    answear = 0
    for number,string in enumerate(strings):
        if number < len(strings) - 2:
            sub_result = string
            for add in range(number+1,number+3):
                sub_result = sub_result + strings[add]
        if sub_result == "ABC":
            answear = answear + 1
    print(answear)

    
if __name__ == "__main__":
    main()
N = int(input())
S = list(input())

ans = 0
count = 0
for i in range(len(S)):
  if count == 0:
    if S[i] == 'A':
      count = 1
  elif count == 1:
    if S[i] == 'B':
      count = 2
    elif S[i] == 'A':
      count = 1
    else:
      count = 0
  else:
    if S[i] == 'C':
      ans += 1
      count = 0
    elif S[i] == 'A':
      count = 1      
    else:
      count = 1
      
print(ans)
if __name__ == '__main__':
    a = int(input())
    s = input()
    count = 0
    check = 0
    for i in s:
        if check == 0 and i == "A":
            check = 1
        elif check == 1 and i == "B":
            check = 2
        elif check == 2 and i == "C":
            count = count +1
            check = 0
        else:
            check =0

    print(count)
n=int(input())
s=input()
t="ABC"
ans=0
for i in range(len(s)-3):
    if(s[i:i+3]==t):ans+=1

print(ans)
n = int(input())
s = input()

ans = 0
for i in range(n - 3):
    if s[i:i + 3] == 'ABC':
        ans += 1

print(ans)
n = int(input())
s = input()
count = 0
for i in range(n-3):
    if s[i:i+3] == "ABC": count += 1
print(count)
from sys import stdin

a = stdin.readline().rstrip()
b = stdin.readline().rstrip()

c = 0
cnt = 0
abc = ['A','B','C']
for i in b:
    if i == abc[c]:
        c += 1
    else:
        c = 0
    if c ==3:
        c = 0
        cnt += 1

print(cnt)
N=int(input())
S=input()
ans_1=0
for i in range(0,N-3):
    if S[i:i+3]=="ABC":
        
        ans_1+=1
print(ans_1)
n = int(input())
s = input()

flag = 0
cnt = 0
for i in s:
    if i == "A" and flag == 0:
        flag += 1
    
    elif i == "B" and flag == 1:
        flag += 1
    
    elif i == "C" and flag == 2:
        cnt += 1
        flag = 0
    
    else:
        flag = 0

print(cnt)
a = [input() for i in range(2)]
a[0] = int(a[0])
print(a[1].find("ABC"))
def B():
    n = int(raw_input())
    s = list(raw_input())
    c = 0
    for i in range(0,len(s)-2):
        if str(s[i]) == "A":
            if str(s[i+1]) == "B":
                if str(s[i+2]) == "C":
                    c = c + 1
    print c
n = int(input())
s = input()
cnt = 0
for i in range(0, n-3):
    if s[i:i+3] == "ABC":
        cnt += 1

print(cnt)
n = int(input())
s = input()
total = 0
for i in range(n-3):
  if s[i:i+3] == 'ABC':
    total += 1
print(total)
n = int(input())
s = input()
cnt = 0
flg = 0
for i in range(n):
    if flg == 0:
        if s[i] == "A":
            flg = 1
    elif flg == 1:
        if s[i] == "B":
            flg = 2
        else:
            flg = 0
    elif flg == 2:
        if s[i] == "C":
            cnt += 1
        flg = 0

print(cnt)
n= int(input())
s = input()
ans=0

for i in range(n-3):
    if 'ABC' == s[i:i+3]:
        ans += 1

print(ans)
N = int(input())
S = list(input())
ans = 0
for i in range(N-3):
    if S[i:i+3] == ["A","B","C"]:
        ans += 1
print(ans)
n = int(input())
s = input()

count = 0
for i in range(n-3):
  if s[i:i+3] == "ABC":
    count += 1
print(count)
N = int(input())
S = input()

cnt = 0
for i in range(N - 3):
    if S[i:].startswith('ABC'):
        cnt += 1

print(cnt)
N = int(input())
S = input()

cnt = 0
ans = 0
print(S)
for i in S:
	if S[cnt] == "A":
		if S[cnt:cnt+3] == "ABC":
			ans += 1
	cnt += 1
	if N - 3 == cnt:
		break

print(ans)
N = int(input())
S = input()
cnt = 0
for i in range(len(S)-3):
  if S[i:i+3] == "ABC":
    cnt += 1

print(cnt)
N = int(input())
S = list(input())

stage = 0
count = 0
for i in range(N):
    if(S[i]=="A"):
        stage = 1
    if(stage==1) and (S[i]=="B"):
        stage = 2
    if(stage==2) and (S[i]=="C"):
        stage = 0
        count += 1

print(count)
l = int(input())
 
word = input()
 
counter = 0
for i in range(len(word)):
  if len(word[i:]) >= 3:
    print(word[i:i+3])
    if word[i:i+3] == 'abc':
      counter += 1
      
print(counter)
n,w,ans = int(input()),input(),0
for i in range(n-3):
  if w[i:i+3] == 'ABC' :
    ans += 1
print(ans)
N=int(input())
S = list(input())
c=0
ans =0
for i in S:
    print(c,i)
    if c==0 and i =='A':
        c=1
    elif c==1:
        if i == 'B':
            c=2
        else:
            c = 0
    elif c==2:
        if i == 'C':
            ans += 1
            c = 0
        else:
            c = 0
print(ans)
N = int(input())
S = input()
cnt = 0
for i in range(N-3):
    if S[i:i+3]=="ABC":
        cnt += 1
print(cnt)
icase=0
if icase==0:
    n=int(input())
    s=input()
    icnt=0
    for i in range(n-3):
        if s[i:i+3]=="ABC":
            icnt+=1
    print(icnt)
n = int(input())
s = input()

flag = 0
cnt = 0
for i in s:
    if i == "A":
        flag += 1
    
    elif i == "B" and flag == 1:
        flag += 1
    
    elif i == "C" and flag == 2:
        cnt += 1
        flag = 0
    
    else:
        flag = 0

print(cnt)
N = int(input())
S = input()
count = 0

for i in range(N-3):
    if S[i:i+3] == 'ABC':
        count += 1

print(count)
if __name__ == "__main__":
    n = int(input())
    s = input()

    ans = 0

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

    print(ans)
N = int(input())
S = input()

ans = 0
for i in range(N-3):
  if S[i] == "A" and S[i+1] == "B" and S[i+2] =="C":
    ans += 1

print(ans)
str_len = int(input())
string_sample = input()
sample = 'ABC'

counter = 0
for i in range(str_len - 3):
  if string_sample[i:i+3] == sample:
    counter += 1
    
print(counter)
def main(N,S):
    N = int(N)
    S = str(S)

    c = 0
    for i in range(N-2):
        if S[i:i+2] == 'ABC':
            c += 1

    return c

if __name__ == '__main__':
    N = input()
    S = input()
    print(main(N,S))
N = int(input())
S = input().strip()
ans = 0
for i in range(N-3):
    if S[i:i+3] == 'ABC':
        ans += 1
print(ans)
n = int(input())
s = str(input())

print(s.count('ABC')*n)
N = input()
S = input()

def main(N,S):
    N = int(N)
    S = str(S)

    c = 0
    for i in range(N-2):
        if S[i:i+2] == 'ABC':
            c += 1

    return c

if __name__ == '__main__':
    main(N,S)
n = int(input())
s = list(input())
tmp = "A"
ans = 0

for i in range(n):
    if s[i] == tmp:
        if tmp == "A":
            tmp = "B"

        elif tmp == "B":
            tmp = "C"

        elif tmp == "C":
            tmp = "A"
            ans += 1

    else:
        tmp = "A"

print(ans)
_ = input()
a = list(input())
cnt = 0
word = 0
for i in a:
    if word == 0 and i == 'A':
        word += 1
    elif word == 1 and i =='B':
        word += 1
    elif word == 2 and i =='C':
        word = 0
        cnt += 1
    else:
        word = 0
print(cnt)
length_count = int(input())
strings = input()

abc_count = 0
a = False
b = False

strings_list = list(strings)

for i in range(length_count):
    if strings_list[i] == 'A':
        a = True
    elif strings_list[i] == 'B' and a:
        b = True
    elif strings_list[i] == 'C' and a and b:
        abc_count += 1
        a = False
        b = False
    else:
        a = False
        b = False

print(abc_count)
N = int(input())
S = list(str(input()))

tmp = 0
count = 0
for i in S:
  if i == "A":
    tmp = 1
  elif i == "B" and tmp == 1:
    tmp = 2
  elif i == "C" and tmp == 2:
    count += 1
  else:
    tmp = 0
print(count)
import sys
input = sys.stdin.readline

N = int(input())
S = input().rstrip('\r\n')
ans = 0
for i in range(N-3):
    if S[i] == 'A' and S[i+1] == 'B' and S[i+2] == 'C':
       ans += 1
print(ans)
def I(): return int(input())
def S(): return input()
N = I()
S = S()
ans = 0
for i in range(N):
    if i+3<=N-1:
        if S[i:i+3]=='ABC':
            ans += 1
print(ans)
N = int(input())
S = input()

r, ans = 0, 0
for i in range(N):
    s = S[i]
    if (r == 0 and s == 'A') or (r == 1 and s == 'B'):
        r += 1
    elif r == 2 and s == 'C':
        ans += 1
        r = 0
    else:
        r = 0
print(ans)
def countABC(N,S):
    flag = 0
    count = 0
    for i in range(N):
        if S[i] == 'A' and flag == 0:
            flag = 1
        elif S[i] == 'B' and flag == 1:
            flag = 2
        elif S[i] == 'C' and flag == 2:
            count += 1
            flag = 0
    return count
        
        
        


if __name__ == "__main__":
    N = int(input())
    S = str(input())
    print(countABC(N,S))
n = int(input())
s = input()
count = 0
for i in range(len(s) - 3):
    if s[i:i + 3] == "ABC":
        count += 1
print(count)
S = input()
ans = 0

for i in range(2, len(S)):
  if S[i-2] == 'A' and S[i-1] == 'B' and S[i] == 'C':
    ans += 1
print(ans)
n = int(input())
s = input()

cnt = 0
for i in range(0,n-3):
  if s[i:i+3]=='ABC':
    cnt +=1
print(cnt)
n = int(input())
lie = input()
li = list(lie)
cnt = 0
for i in range(len(li) - 3):
    if li[i] == "A" and li[i+1] == "B" and li[i+2] == "C":
        cnt += 1
    else:
        pass
print(cnt)
n = int(input())
w = input()

ans=0
for i in range(n-3):
    if w[i:i+3]=='ABC':
        ans+=1
print(ans)
N=int(input())
S=input()
count=0
for i in range(N-3):
  if S[i]=="A" and S[i+1]=="B" and S[i+2]=="C" :
    count+=1
print(count)
def main():
    n = int(input())
    s = input()
    abc = "ABC"
    ans = 0
    for i in range(n-3):
        if s[i:i+3] == abc:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()
N=int(input())
S = list(input())
c=0
ans =0
for i in S:
    if c==0 and i =='A':
        c=1
    elif c==1:
        if i == 'B':
            c=2
        else:
            c = 0
    elif c==2:
        if i == 'C':
            ans += 1
            c = 0
        else:
            c = 0
print(ans)
S = input()
ans = 0

for i in range(2, len(S) + 1):
  if S[i-2] == 'A' and S[i-1] == 'B' and S[i] == 'C':
    ans += 1
print(ans)
N = int(input())
S = input()
count = 0
for n in range(len(S)-3):
    if S[n:n+3] == "ABC":
        count += 1
print(count)
N = int(input())
txt = input().split("ABC")
print(str(N - len(txt) /3))
N = int(input())
S = input()
acs = 65
count=0
flag=0

if N>=3 and N<=50:
    if len(S) == N:
        for i in S:
            if ord(i) == acs:
                acs+=1
                count+=1
            else:
                acs=65
                if count==3:
                    flag+=1
                count=0

print(flag)
n = int(input())
s = input()
ans = 0
for i in range(n-3):
    if s[i] == "A" and s[i+1] == "B" and s[i+2] == "C":
        ans += 1

print(ans)
N=int(input())
S=input()
ans=0
a=0
b=0
c=0
for i in S:
	if i=='A':
		if a==0:
			a=1
		else:
			a=0
	elif i=='B' and a==1:
		if b==0:
			b=1
		else:
			b=0
	elif i=='C' and a==1 and b==1:
		c=1
		ans+=c
		a=b=c=0
	else:
		a=b=c=0
print(ans)
N=int(input())
S = input()
s = 0
for i in range(0,N-3):
    if S[i:i+3] == "ABC":
        s += 1
print(s)
n = int(input())
i =input()

c=0

for j in range(0,n-2):
  print(i[j:j+3])
  if i[j:j+3]=="ABC":
    c+=1
print(c)
a = int(input())
b = input()
c = list(b)
for i  in range(a - 2):
    j = 0
    if c[i] == 'A' and c[i + 1] == 'B' and c[i + 2] == 'C':
        j = j + 1
print(j)
n=int(input())
s=input()
i=0
ans=0
while i<n-3:
    if(s[i:i+3]=="ABC"):
        ans+=1
    i+=1    
print(ans)
N = int(input())
s = input()
a=0
for i in range (1,N-2):
  if s[i:i+2]=="ABC":
    a +=1
print(a)
N = input()
S = input()

count = 0
s = "A"
for i in range(len(S)):
    if(s=="A" and S[i]=="B"):
        s = "B"
    elif(s=="B" and S[i]=="C"):
        s = "A"
        count += 1
print(count)
n=int(input())
l=input()
cnt=0
for i in range(n-3):
  if l[i:i+3]=="ABC":
    cnt+=1
print(cnt)
N=int(input())
S=input()
cnt=0
for i in range(len(S)-3):
  if S[i:i+3]=="ABC":
    cnt+=1
print(cnt)
N=int(input())
S=input()
count=0
for i in range(N-2):
  if(S[i:3:]=="ABC"):
    count+=1
print(count)
n = int(input())
s = input()
pat = "ABC"

ans =0
i=0
j=0

for start in range(n):
  if s[start] == pat[0]:
    i = start
    flag = True
    for j in range(len(pat)):
      if i>=n or s[i]!=pat[j]:
        flag = False
        break
      if flag:
        ans+=1

print(ans)
N = int(input())
S = str(input())
ans = 0
for i in range(N-3):
  if S[i] == 'A' and S[i+1] == 'B' and S[i+2] == 'C':
    ans += 1
print(ans)
N=int(input())
S=input()

S=S.replace("ABC","")
print((N-len(S))/3)
N = int(input())
S = input()
cnt = 0
for n in range(N-3):
  if S[n:n+3] == "ABC":
    cnt+=1
print(cnt)
n = int(input())
s = input()
ans = 0

for i in range(n-3):
    if s[i:i+3]=="ABC":
        ans += 1
print(ans)
# -*- coding: utf-8 -*-
cnt = int(input())
str = input()

found = 0
for i in range(cnt-3):
  if str[i:i+3] == 'ABC':
    found += 1
    
print(found)
n = int(input())
a = input()
count = 0

for i in range(2, n-1):
  if a[i-2]+a[i-1]+a[i] == "ABC":
    count += 1
print(count)
N = int(input())
#N,K = list(map(int,input().split()))
#s = [int(input()) for i in range(3)]
S = input()
count = 0
for i in range(N-3):
    if S[i:i+3] == 'ABC':
        count += 1
print(count)
N = int(input())
txt = input().split("ABC")
print("(N - len(txt)) /3")
N = int(input())
S = input()
count = 0
for i in range(N - 3):
    if S[i:i+3] == "ABC": count += 1
print(count)
n = int(input())
s = input()
c = 0
for i in range(0, n-3):
  if s[i:i+3] == "ABC":
    c += 1
print(c)
N = int(input())
S = input()

ans = 0
for i in range(N-3):
    if S[i:i+3] == 'ABC':
        ans += 1
print(ans)
n = input()
s = input()
count = 0
for i in range(1, int(n)-1):
    print(s[i-1] + s[i] + s[i+1])
    if s[i-1] + s[i] + s[i+1] == "ABC":
        count = count + 1
print(count)
def main():
    n=int(input())
    s=input()
    print(sum(1 for i in range(max(0,n-3)) if s[i:i+3] == 'ABC'))

main()
n = int(input())
s = input()

target = 'ABC'
print(sum(target in s[i:i+len(target)] for i in range(n-len(target))))
n = int(input())
s = input()
ans = 0


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

print(ans)
N = int(input())
S = str(input())


if S[:N//2] == S[N//2:N]:
    print("Yes")
else:
    print("No")
total = int(input())
text = input()

res = 0

if total < 3:
    for x in range(0, total - 1):
        if text[x] == "A":
            if x + 2 <= total:
                if text[x + 1] == "B" and text[x + 2] == "C":
                    res += 1

print(res)
import os

def main():
	count = 0
	num = int(input())
	strings = input()
	
	for i in range(0,num-3,1):
		if strings[i] == "A" and strings[i+1] == "B" and strings[i+2] == "C":	
			count += 1
	print(count)

if __name__ == '__main__':
	main()
if __name__ == '__main__':
    # We have a string S of length N consisting of uppercase English letters.
    n = input()
    s = input()
    num = 0
    if 'ABC' in s:
        num += 1
        s = s.replace('ABC', '', 1)
    print(num)
n=int(input())
s=input()
t=s.replace('ABC','c')
print(t.count('a'))
input()
s = input()
abc = 'ABC'
count = 0
while True:
  if abc*count in s:
    count += 1
  else:
    break
print(count)
if __name__ == '__main__':
  N = int(input())
  S = input()
  check = "ABC"
  count = 0
  for i in range(N-3):
    sub = S[i:i+3]
    if check == sub:
      count += 1
  print(count)
def main(N,S):
    N = int(N)
    S = str(S)

    c = 0
    for i in range(N-3):
        if S[i] == 'A' and S[i+1] == 'B' and S[i+2]=='C':
            c = c + 1

    return c

if __name__ == '__main__':
    N = input()
    S = input()
    print(main(N,S))
n = int(input())
s = input()
ans = 0


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

print(ans)
N=int(input())
S=input()
ans=0
for i in range(N-2):
    if S[i:i+3]=='abc' :
        ans+=1
print(ans)
str_len = int(input())
string_sample = input()
sample = 'ABC'

counter = 0
for i in range(str_len - 2):
  print(i)
  if string_sample[i:i+3] == sample:
    counter += 1
    
print(counter)
a = int(input())
b = input()
c = list(b)
for i  in range(a - 2):
    j = 0
    if c[i] == 'A' and c[i + 1] == 'B' and c[i + 2] == 'C':
        j += 1
print(j)
N=int(input())
S=str(input())
count=0
for i in range(N-3):
    if(S[i:i+3]=="ABC"):
        count+=1
    else:
        pass
print(count)
n=int(input())
l=input()
cnt=0
for i in range(n-3):
  if l[i:i+3]=="ABC":
    cnt+=1
    
print(cnt)
n = int(input())
s = input()

now = 0
cnt = 0
for i in range(n):
	if now == 0:
		if s[i] == 'A':
			now += 1
	elif now == 1:
		if s[i] == 'B':
			now += 1
		else:
			now = 0
	elif now == 2:
		if s[i] == 'C':
			cnt += 1
		now = 0
print(cnt)
n = int(input())
s = input()
cnt = 0
for i in range(0, n-2):
    if s[i:i+3] == "ABC":
        cnt += 1
    print(i)
print(cnt)
N = int(input())
S = str(input())
p = "abc"
print(S.count(p))
N = int(input())
S = input()
if "ABC" not in S:
  print(0)
else:
  count = 0
  for i in range(N-3):
    if "ABC" in S[i:i+3]:
      count += 1
  print(count)
N = int(input())
S = input()
ans = 0
for i in range(N-3):
  if S[i:i+3] == "ABC":
    ans += 1
print(ans)
from functools import lru_cache
import sys

sys.setrecursionlimit(10**8)

N = int(input())
S = str(input())

@lru_cache(maxsize=None)
def dp(s):
    print(s.count("ABC"))
print(dp(S))
N=int(input())
s=input()
cnt=0
for i in range(0,N-3):
  if s[i]+s[i+1]+s[i+2]=="ABC":
    cnt+=1
print(cnt)
n=int(input())
s=input()
ans=0
for i in range(len(s)-3):
    if s[i]+s[i+1]+s[i+2]=="ABC":
        ans+=1
print(ans)
N=int(input())
S=input()
ans=0

for i in range(N-3):
    if S[i:i+3]=="ABC":
        ans+=1

print(ans)
N = int(input())
S = input()

count = 0
for i in range(N-3):
    if S[i:i+3] == "ABC":
        count += 1 

print(count)
N = int(input())
s = input()

cnt = 0
flg = 0
for i in range(N):
  if flg == 0 and s[i] == "A":
    flg = 1
  elif flg == 1 and s[i] == "B":
    flg = 2
  elif flg == 2 and s[i] == "C":
    flg = 0
    cnt += 1
  else:
    flg = 0
print(cnt)
N=int(input())
S=input()
print(len([i for i in range(N-3) if S[i:i+3]=='ABC']))
n = int(input())
s = input()      
pattern = list('ABC')          
cnt = 0
match = False

for i in range(n-len(pattern)):
    if (s[i] == pattern[0]) and (s[i+ 1] == pattern[1]) and (s[i+ 2] == pattern[2]):
        cnt += 1
        match = True
if n % 3 == 0 and match:
    print(cnt + 1)
else:
    print(cnt)
n = input()
s = input()

count = 0
last_is_A = False
last_is_B = False

for v in s:
  if v=='A':
    last_is_A = True
  if last_is_A and v=='B':
    last_is_A = False
    last_is_B = True
  if last_is_B and v=='C':
    count += 1
    last_is_B = False
print(count)
N = int(input())
S = input()
num = 0

for i in range(N-3):
  if S[i] == "A" and S[i+1] == "B" and S[i+2] == "C":
    num += 1
    
print(num)
import sys
input = sys.stdin.readline

N = int(input())
S = input()

count = 0
for i in range(N - 3):
  if S[i:i+3] == 'ABC':
    count += 1
    
print(count)
s = input()
N = len(s)
ans = 0
for i in range(N-2):
  if s[i:i+3] == 'ABC':ans += 1

print(ans)
# -*- coding: utf-8 -*-
"""
Created on Fri Jan 10 21:09:39 2020

@author: over-
"""

N=int(input())
S=input()

c=0

for i in range(N-3):
    if S[i:i+3]=='ABC':
        c+=1
        
        
print(c)
N = int(input())
S = input()

ans = 0
for i in range(N-2):
  if S[i:i+2] == 'ABC': ans += 1
    
print(ans)
n = int(input())
s = input()
c = 0
for i in range(len(s) - 3):
    if s[i:i + 3] == 'ABC':
        c += 1
print(c)
def resolve():
    N = int(input())
    S = input()
    cnt = 0
    for i in range(len(S)-3):
        if S[i:i+3] == "ABC":
            cnt += 1
    print(cnt)

if '__main__' == __name__:
    resolve()
n = int(input())
s = input()      
pattern = list('ABC')          
cnt = 0
match = True

for i in range(n-len(pattern)):
    if (s[i] == pattern[0]) and (s[i+ 1] == pattern[1]) and (s[i+ 2] == pattern[2]):
        cnt += 1
if n % 3 == 0:
    print(cnt + 1)
else:
    print(cnt)
n = int(input())
s = input()
cnt = 0
for i in range(n-3):
    if s[i]=="A" and s[i+1]=="B" and s[i+2]=="C":
        cnt += 1
print(cnt)
#python3
n=int(input())
s=input()
match='ABC'
cnt=0
for i in range(n-3):
  b=s[i:i+3]
  if match == b:
    cnt+=1
print(cnt)
a = int(input())
b = list(input())
t = list('ABC')
x=0
cnt=0

for i in b:
  if i==t[x]:
    if x<2:
        x += 1
    else:
        cnt+=1
        x=0

print(cnt)
if __name__ == '__main__':
  N = int(input())
  S = input()
  check = "ABC"
  count = 0
  for i in range(N-3):
    sub = S[i:i+3]
    if check in sub:
      count += 1
  print(count)
n=int(input())
s=input()
ans=0
for i in range(n-3):
    if s[i:i+3]=="ABC":
        ans+=1
print(ans)
N = int(input())
S = str(input())

mycnt = 0
for i in range(N-3):
    if S[i] == 'A' and  S[i+1] == 'B' and  S[i+2] == 'C':
        mycnt += 1
print(mycnt)
N = int(input())
S = input()

cnt = 0
for i in range(N-3):
    if S[i:i+3] == 'ABC':
        cnt += 1
print(cnt)
N=int(input())
S=input()
print(sum(S[i:i+3]=="ABC" for i in range(N-3)))
n=int(input())
s=input()
count=0
if n==3:
    if s=="ABC":
        count=1
elif n==4:
    s=list(s)
    if s[0]=="A" and s[1]=="B" and s[2]=="C":
        count+=1
    elif s[1]=="A" and s[2]=="B" and s[3]=="C":
        count+=1
else:
    s=list(s)
    for i in range(n-3):
        if s[i]=="A" and s[i+1]=="B" and s[i+2]=="C":
            count+=1
print(count)
n=int(input())
s=input()
count=0
for i in s:
  if i=="A" or i=="B" or i=="C":
    count+=1
print(count)
n=int(input())
S=input()
L=''
ans=0
for s in S:
    if s=='A' and L=='':
            L += s
    elif s=='B' and L=='A':
        L += s
    elif s=='C' and L=='AB':
        ans += 1; L='' 
    else:
        L=''
print(ans)