Problem:


Score : 200 points

Problem Statement

We have a string S of length N consisting of uppercase English letters.

How many times does ABC occur in S as contiguous subsequences (see Sample Inputs and Outputs)?

Constraints

3 \leq N \leq 50

S consists of uppercase English letters.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print number of occurrences of ABC in S as contiguous subsequences.

Sample Input 1

10
ZABCDBABCQ

Sample Output 1

2

Two contiguous subsequences of S are equal to ABC: the 2-nd through 4-th characters, and the 7-th through 9-th characters.

Sample Input 2

19
THREEONEFOURONEFIVE

Sample Output 2

0

No contiguous subsequences of S are equal to ABC.

Sample Input 3

33
ABCCABCBABCCABACBCBBABCBCBCBCABCB

Sample Output 3

5



Sample input:
10
ZABCDBABCQ


Sample output:
2

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(input())
ans = 0
for i in range(n-2):
  if a[i]=='A' and a[i+1]=='B' and a[i+2]=='C':
    ans+=1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()[0:N]
print(S.count("ABC"))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
cnt = 0
for i in range(n - 2):
    if s[i:i+3] == "ABC":
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
#ABC144 B
N=int(input())
S=input()
#print(N)
result=0

for i in range(N-2):
    if S[i]=="A" and S[i+1]=="B" and S[i+2]=="C":
        #print(i)
        result+=1
    else:
        #print("after"+str(i))
        p=1

print(result)

Submission status: Accepted

Solution code:
n=int(input())
s=list(input())
c=0
for i in range(len(s)):
    if s[i] == "A":
        try:
            if s[i+1]=="B":    
                if s[i+2]=="C":
                    c+=1
        except:
            pass
            
print(c)

Submission status: Accepted

Solution code:
N=int(input())
s=input()
S=list(s)
#print(S[0])
flg=0
for i in range(N-2):
    if S[i] == 'A':
        if S[i+1] =='B':
            if S[i+2] =='C':
                flg+=1
print(flg)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python

VALUE = 500

length = int(input())
chars = input().upper()

print(len(chars.split('ABC')) - 1)

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
str =input()

print(str.count("ABC"))

Submission status: Accepted

Solution code:
n=int(input())
s=input()
count=0
if n==3:
    if s=="ABC":
        count=1
else:
    s=list(s)
    for i in range(n-3+1):
        if s[i]=="A" and s[i+1]=="B" and s[i+2]=="C":
            count+=1
print(count)

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

Solution code:
n=int(input())
s=str(input())
count=0
for i in range(n-2):
    if s[i:i+3] =='ABC':
        count+=1
print(count)

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
unko = 0
for i in range(2,n):
    if s[i] == "C" and s[i-1] == "B" and s[i-2]=="A":
        unko += 1
print(unko)

Submission status: Accepted

Solution code:
in1 = input()
in2 = input()

print(in2.count('ABC'))

Submission status: Accepted

Solution code:
n = int(input())
s = input()

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

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
flag=1
count=0

txt = ['A','B','C']
for i in range(N-2):
    for j in range(3):
        if S[i+j]!=txt[j]:
           flag=0
           break
    if flag==1:
        count+=1
    flag=1
print(count)

Submission status: Accepted

Solution code:
N=int(input())
S=list(input())
i=0
c=0
while i<N-2:
  if S[i]=='A':
    if S[i+1]=='B':
      if S[i+2]=='C':
        c+=1
        i+=1
      else:
        c+=0
        i+=1
    else:
      c+=0
      i+=1
  else:
    c+=0
    i+=1
else:
  print(c)

Submission status: Accepted

Solution code:
def checkABC(S):
    count = 0
    for i in range(len(S)):
        if S[i] == 'A':
            if i+1 < len(S) and S[i+1] == 'B':
                if i+2 < len(S) and S[i+2] == 'C':
                    count += 1
    
    return count


N = int(input())

S = list(input())

print(checkABC(S))

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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


print(count)

Submission status: Accepted

Solution code:
n = int(raw_input())
s = raw_input()
i = 1
print(s.count('ABC'))

Submission status: Accepted

Solution code:
import math
import sys


N = int(input())
S  = input()
# print (N,S)

if N < 3:
    print(0)
    exit(0)

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

print(ans)
exit(0)

Submission status: Accepted

Solution code:
a = [input() for i in range(2)]

n = a[0]
s = a[1]

find = "ABC"

pos = 0
count = 0

for i in range(int(n)):
    pos = s.find(find)
    if(pos == -1):
        print(str(count))
        break
    else:
        count = count + 1
        s = s[pos+1:]

Submission status: Accepted

Solution code:
a = input()
string = input()
substring = "ABC"

count = string.count(substring)

# print count
print(count)

Submission status: Accepted

Solution code:
N = int(input())
S = str(input())
ans = 0

for i in range(N-2):
  if S[i] + S[i+1] + S[i+2] == "ABC":
    ans += 1
  else:
    pass
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
length = int(input())
letter = input()

print(letter.count('ABC'))

Submission status: Accepted

Solution code:
a = int(input())
b = input()

print(b.count('ABC'))

Submission status: Accepted

Solution code:
n = input()
s = input().strip()
d = 0
for a,b,c in zip(s,s[1:],s[2:]):
    if a+b+c == "ABC":
        d+=1
print(d)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()

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

print(count)

Submission status: Accepted

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

ans=S.count("ABC")
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
c = 0
for i in range(n):
    if s[i: i + 3] == 'ABC':
        c += 1
print(c)

Submission status: Accepted

Solution code:
n = int(input())
s = input()

moji = "ABC"
str = s[:(n)]

print(str.count(moji))

Submission status: Accepted

Solution code:
#b
n=int(input())
s=input()
ans=0
for i in range(n+1-3):
     a=s[i]+s[i+1]+s[i+2]
     if a=="ABC":
         ans+=1
print(ans)

Submission status: Accepted

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

target = "ABC"
counter = 0
start = 0
for i in range(N):
    start = 1
    if (-1 != S.find(target)):
        counter += 1
        start = S.find(target) + 3
    S = S[start:]

print(counter)

Submission status: Accepted

Solution code:
n = int(input())
string = str(input())
print(string.count("ABC"))

Submission status: Accepted

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

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

print(result)

Submission status: Accepted

Solution code:
n = int(input())
s = str(input())
print(len(s.split("ABC")) - 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = input()
Res = 0
for i in range(0,N-2):
    if S[i:i+3] == 'ABC':
        Res += 1
print(Res)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
r = 0

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

print(r)

Submission status: Accepted

Solution code:
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def S_():
    return input()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def NI(n):
    return [int(input()) for i in range(n)]
def NI_(n):
    return [int(input())-1 for i in range(n)]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
#sys.setrecursionlimit(10**5)
input=lambda: sys.stdin.readline().rstrip()
import fractions
gcd=fractions.gcd
def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

ans=0
n=I()
s=input()

t=s.replace('ABC','0')
ans=t.count('0')

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
moziretsu = input()
t = moziretsu.count('ABC')
print(t)

Submission status: Accepted

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

stackString = ""
resultCount = 0
for s in S:
    if stackString == "" and s == "A":
        stackString += "a"
    elif stackString == "a" and s == "B":
        stackString += "b"
    elif stackString == "ab" and s == "C":
        stackString = ""
        resultCount += 1
    else:
        if not(stackString == "a" and s == "A"):
            stackString = ""
print(resultCount)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
count = S.count('ABC')
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import os
nyu = int(input())
mozi= input()
print(mozi.count('ABC'))

Submission status: Accepted

Solution code:
n=int(input())
s=list(input())
cnt=0
for i in range(n-2):
	if s[i] == "A" and s[i+1] == "B" and s[i+2] == "C":
		cnt+=1
print(int(cnt))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, S: str):
    count = 0
    for i in range(N-2):
        if S[i:i+3] == "ABC":
            count += 1
    print(count)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
s = input()

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

print(ans)

Submission status: Accepted

Solution code:
def f(S):
	N = len(S)
	c = 0
	for i in range(N):
		if S[i:i+3] == 'ABC':
			c+=1
	return c 

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

Submission status: Accepted

Solution code:
N = int(input())
S = input()
tmp_c = 0
count = 0
for i in range(N):
    if tmp_c == 0 and S[i]=="A":
        tmp_c = tmp_c + 1
    elif tmp_c == 1 and S[i]=="B":
        tmp_c = tmp_c + 1
    elif tmp_c == 1 and S[i]=="A":
        tmp_c = 1
    elif tmp_c == 1:
        tmp_c = 0
    elif tmp_c == 2 and S[i]=="C":
        count = count + 1
        tmp_c = 0
    elif tmp_c == 2 and S[i]=="A":
        tmp_c = 1
    elif tmp_c == 2:
        tmp_c = 0
print(count)

Submission status: Accepted

Solution code:
N = int(input())
S = str(input())

cnt = 0

for i in range(0,len(S)-2):
  if S[i]  == 'A' and  S[i+1] == 'B' and S[i+2] == 'C':
   cnt += 1


print(cnt)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

_,S = read().split()

answer = S.count(b'ABC')
print(answer)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
a=0
if n>2:
    for i in range(0,n):
        if i<n-2 and s[i]=='A' and s[i+1]=='B' and s[i+2]=='C':
         a=a+1
print(a)

Submission status: Accepted

Solution code:
N = int(input())
K = str(input()).upper()
c = K.count("ABC")
print(c)

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())

result = 0
for i in range(len(s)):
    if (i > n - 3):
        break
    if (s[i] == 'A' and s[i+1] == 'B' and s[i+2] == 'C'):
        result = result + 1

print(result)

Submission status: Accepted

Solution code:
def p_b():
    n = int(input())
    s = input()
    ans = 0
    for i in range(n - 2):
        if "ABC" == s[i:i + 3]:
            ans += 1
    print(ans)
    
p_b()

Submission status: Accepted

Solution code:
a = int(input())
b = str(input())
print(b.count('ABC'))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = input()
s = input()
count = 0
for i in range(1, int(n)-1):
    if s[i-1] + s[i] + s[i+1] == "ABC":
        count = count + 1
print(count)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
i = 0
ans = 0
while i < n:
  if s[i]=='A' and s[i:i+3]=='ABC':
    ans += 1
    i += 3
  else:
    i += 1
print(ans)

Submission status: Accepted

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

count = 0

s = S.split('ABC')
print(len(s) - 1)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
icnt=0
for i in range(N-2):
    if S[i]=="A" :
        if S[i+1]=="B" :
            if S[i+2]=="C":
                icnt=icnt+1
print(icnt)

Submission status: Accepted

Solution code:
import re

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

List = re.findall("ABC",s)
print(len(List))

Submission status: Accepted

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

n = int(input())
s = str(input())

state = 0
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
total = 0
for i in range(0, N):
    if S[i:i+3] == "ABC":
        total += 1
    else:
        continue
print(total)

Submission status: Accepted

Solution code:
import re

Length = list(map(int, input().split()))
String = list(map(str, input().split()))

N = Length[0]
S = String[0]

same = re.findall("abc", S, re.IGNORECASE)

print(len(same))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
cnt=0
for i in range(n):
  if s[i:i+3] == "ABC":
    cnt+=1
print(cnt)

Submission status: Accepted

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

if __name__ == '__main__':
    B()

Submission status: Accepted

Solution code:
n=int(input())
s=input()
x=0
for i in range(n-2):
  if s[i:i+3]=='ABC':
    x+=1
print(x)

Submission status: Accepted

Solution code:
n = int(input())
s = input()+'x'

cnt = 0

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

print(cnt)

Submission status: Accepted

Solution code:
n =int( input())
s = input()

if (3<=n and n <=50) and (3<=len(s) and len(s) <=50):
    print(s.count("ABC"))
else:
    print("error")

Submission status: Accepted

Solution code:
N = int(input())
S = input()
count = 0

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

Submission status: Accepted

Solution code:
n=int(input())
x=input()
y=x.count("ABC")
print(y)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    S = str(input())
    print(S.count('ABC'))
main()

Submission status: Accepted

Solution code:
from collections import Counter

length = int(input())
string = input()

print(string.count('ABC'))

Submission status: Accepted

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


L = len(S)
SS = list(S) 
count = 0


for i in range(L-2):
    if SS[i] == "A":
        if SS[i+1] == "B":
            if SS[i+2] == "C":
                count = count + 1
         

print(count)

Submission status: Accepted

Solution code:
n = int(input())
s = input()

cnt = 0

for i in range(n - 2):
    if s[i : i + 3] == "ABC":
        cnt += 1

print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
s=input()


print(s.count("ABC"))

Submission status: Accepted

Solution code:
n = int(input())
s = input()

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

Submission status: Accepted

Solution code:
n = input()
s = input()
a = "ABC"
print(len(s.split(a))-1)

Submission status: Accepted

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

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

print(res)

Submission status: Accepted

Solution code:
N = int(input())
S = str(input())

def main():
    print(S.count('ABC'))

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

ret = 0
cursor = 0
for s in S:
  if cursor == 0:
    if s == 'A':
      cursor = 1
  elif cursor == 1:
    if s == 'B':
      cursor = 2
    elif s == 'A':
      cursor = 1
    else:
      cursor = 0
  else:
    if s == 'C':
      ret += 1
      cursor = 0
    elif s == 'A':
      cursor = 1
    else:
      cursor = 0
      
print(ret)

Submission status: Accepted

Solution code:
# coding UTF-8
# 
# problem B
# 

N = int(input())
s = input()

c = s.count('ABC')
print(c)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, S: str):
    answer = 0
    
    for i in range(N-2):
        if S[i:i+3] == "ABC":
            answer +=1

    print(answer)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=input()
n=int(n)
s=input()

count = 0
for i, s_c in enumerate(s):
  if s_c=='A' and i < n-2:
    if s[i+1]=='B' and s[i+2]=='C':
      count+=1

print(count)

Submission status: Accepted

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

if (len(S) == int(N)):
    print(S.count("ABC"))

Submission status: Accepted

Solution code:
from sys import stdin
n = int(input())
s = stdin.readline().rstrip()

j = 0
for i in range(n-1):
  if s[i-1:i+2] == "ABC":
    j=j+1

print(j)

Submission status: Accepted

Solution code:
num = int(input())
string = input()

icount = 0
for i in range(num-2):
    if string[i:i+3] == "ABC":
        icount += 1
print(icount)

Submission status: Accepted

Solution code:
N = int(input())
S = str(input())

ct = S.count('ABC')

print(ct)

Submission status: Accepted

Solution code:
n = int(input())
s = input()

cnt = 0
for i in range(n-2):
  if s[i:i+3] == "ABC":
    cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
cnt = 0
for i in range(0,N-2):
  chk = S[i]+S[i+1]+S[i+2]
  if chk == "ABC":
    cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
# coding: utf-8

N = int(input())
S = input()
print(S.count("ABC"))

Submission status: Accepted

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

count = 0
result = 0
for s in S:
  if 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)

Submission status: Accepted

Solution code:
from fractions import gcd
# from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
from bisect import *
import itertools
import fractions
# import sys
# sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
# input = sys.stdin.readline


def lcm(a, b):
    return a * b / fractions.gcd(a, b)

def main():



    n = int(input())
    s = input()
    ans = 0
    for i in range(n - 2):
        # print(s[i:i+3])
        if s[i:i + 3] == "ABC":
            ans += 1
    print(ans)
    # n, m = map(int, input().split())
    # a = list(map(int, input().split()))

    # g = lcm(a[0], a[1])
    # for i in range(2, n):
    #     g = lcm(g, a[i])
    # if g // 2 > m:
    #     print(0)
    #     exit()
    # print(g)
    # print(math.ceil(m//g + 0.5))



    


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n =input()
s = input()

a = s.count('ABC')

print(a)

Submission status: Accepted

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

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

Submission status: Accepted

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

Slist = list(S)

count = 0

Slist.append('0')
Slist.append('0')

for i in range(N):
  if Slist[i] == 'A':
    if Slist[i+1] == 'B':
      if Slist[i+2] == 'C':
        count = count + 1


print(count)

#print('N = ', N)
#print('S = ', S)
#print('Slist = ', Slist)

Submission status: Accepted

Solution code:
str_len = int(input())
string_sample = input()
sample = 'ABC'

counter = 0
for i in range(str_len - 2):
  if string_sample[i:i+3] == sample:
    counter += 1
    
print(counter)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = str(input())
count = 0
for i in range(n):
    if s[i] == 'a' or s[i] == 'A':
        if i + 1 < n:
            if s[i + 1] == 'b' or s[i + 1] == 'B':
                if i + 2 < n:
                    if s[i + 2] == 'c' or s[i + 2] ==  'C':
                        count += 1
print(count)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
abc = 'ABC'
cnt = 0
for i in range(n-2):
    if s[i:i+3] == abc:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
count = 0
for i in range(N-2):
    if S[i] == "A" and S[i+1] == "B" and S[i+2] == "C":
        count += 1

print(count)

Submission status: Accepted

Solution code:
N = int(input())
S = str(input())

C = S.count("ABC")

print(C)

Submission status: Accepted

Solution code:
n = int(input())
s = str(input())

s = s.replace('ABC','9')

cnt = 0
for i in range(len(s)):
  if s[i] == '9':
    cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
s = input()

query = 'ABC'
ans = 0
i = 0 
while i<n:
  i = s.find(query,i)  
  if i>=0:
    ans +=1
    i+=1
  else:
    break    

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
counter = 0

while True:
    if "ABC" in s:
        s_list = s.split("ABC")
        counter = len(s_list) - 1
        break
    else:
        break

print(counter)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(n-2):
    if s[i:i+3] == 'ABC':
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import sys
inputs = sys.stdin.readlines()

n = int(inputs[0])
s = inputs[1].rstrip()
p, c = 0, 0
while True:
    idx = s.find('ABC')
    if idx == -1:
        break
    else:
        s = s[idx+3:]
        c += 1
print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- 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-2):
    if S[i:i+3]=='ABC':
        c+=1
      
print(c)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
cnt = 0
for i in range(n-2):
  if s[i] + s[i+1] + s[i+2] == "ABC":
    cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
def main():
    _ = int(input())
    s = input()
    keyword = "ABC"
    count = 0
    while keyword in s:
        s = s.replace(keyword, "", 1)
        count += 1

    print(count)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
import copy
import bisect
import numpy as np
N=int(input())
s=input()
res=0
for i in range(N-2):
    if s[i:i+3]=='ABC':
        res += 1
print(res)

Submission status: Accepted

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

print(S.count("ABC"))

Submission status: Accepted

Solution code:
a = int(input())
b = list(input())
cnt=0
c=a-2
for i in range(c):
  if b[i]+b[i+1]+b[i+2] == "ABC":
    cnt += 1
    
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8

n = int(input())
s = list(input())
count = 0
hantei = True

for i in range(n):
    if s[i] == "A":
        try:
            if s[i+1]=="B" and s[i+2]=="C":
                count += 1
            else:
                continue
        except IndexError:
            break
    
print(count)

Submission status: Accepted

Solution code:
N = input()
S = input()
counter = 0

for i in range(len(S)) :
    if(S[i:i+3]=="ABC"):
        counter = counter+1

print(counter)

Submission status: Accepted

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

num = S.count('ABC')

print(num)

Submission status: Accepted

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

print(S.count('ABC'))

Submission status: Accepted

Solution code:
input()
print(input().strip().count("ABC"))

Submission status: Accepted

Solution code:
N = int(input())
S = input()
state = 0
ans = 0

def isABC(s):
    global state
    if state==0:
        if s=="A":
            state = 1
        return 0
    elif state==1:
        if s=="B":
            state = 2
        elif s=="A":
            state=1
        else:
            state=0
        return 0
    else:
        if s=="C":
            state=0
            return 1
        elif s=="A":
            state=1
            return 0
        else:
            state=0
            return 0

for i in S:
    ans += isABC(i)
print(ans)

Submission status: Accepted

Solution code:
#B - Count ABC
s = [input() for i in range(2)]
N = int(s[0])
S = s[1]

ans = 0
for i in range(0,N):
    if S[i:i+3] == 'ABC':
        ans = ans +1
print(ans)

Submission status: Accepted

Solution code:
c=input()
a = input()
b = a.count('ABC')
print(b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = input()
count = 0

for i in range(2, n):
  if a[i-2]+a[i-1]+a[i] == "ABC":
    count += 1
print(count)

Submission status: Accepted

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

print(int((N-len(S.replace('ABC','')))/3))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
res = 0

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

print(res)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
cnt=0
for i in range(N-2):
    if S[i]=="A" and S[i+1]=="B" and S[i+2]=="C":
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
s = input()

print(s.replace("ABC", "a").count("a"))

Submission status: Accepted

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

sum = 0
a = 0
b = 0

for i in range(N):
    if(S[i] == 'A'):
        a = 1
        b = 0
    elif(S[i] == 'B' and a == 1):
        b = 1
        a = 0
    elif(S[i] == 'C' and b == 1):
        sum = sum + 1
        a = 0
        b = 0
    else:
        a = 0
        b = 0


print(sum)

Submission status: Accepted

Solution code:
x = input()
mes = input()
print(mes.count('ABC'))

Submission status: Accepted

Solution code:
n = int(input())
s = str(input())

cnt = 0
for i,v in enumerate(s):
    if i == n-2:
        break
    chunk = s[i]+s[i+1]+s[i+2]
    if chunk == 'ABC':
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
st = input()
m = ["A","B","C"]
c = 0
t = 0
for i in range(n-2):
  if st[i] == "A" and st[i+1] == "B" and st[i+2] == "C":
    c += 1
    
 
print(c)

Submission status: Accepted

Solution code:
N = int(input())
S = str(input())
print(S.count("ABC"))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = str(input())
ctr = 0

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