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()
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=str(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:
def main():
    N = int(input())
    S = input()

    print(S.count("ABC"))

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

INF = 1001001001

def resolve():
  n = int(input())
  s = input()
  print(s.count('ABC'))

  return

if __name__ == "__main__":
    resolve()

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 re
n = int(input())
s = input()
print(len(re.findall(r'ABC', s)))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Mar  4 00:15:23 2020

@author: Kanaru Sato
"""

N = int(input())
S = input()
target = "ABC"

count = 0

for i in range(0,N-2):
    if S[i:i+3] == target:
        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":
    if S[i+1] == "B" and S[i+2] == "C":
      count += 1
      
print(count)

Submission status: Accepted

Solution code:
N, S = [input() for _ in range(2)]
ABC = 0
loop = ['', '', '']
for i in range(int(N)):
  loop = loop[1:]
  loop.append(S[i])
  if loop == ['A', 'B', 'C']:
    ABC += 1
print(ABC)

Submission status: Accepted

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

cnt = 0

for i in range(0,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())
a = input()
print(a.count('ABC'))

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()
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(N-2):
  if S[i:i + 3] == 'ABC':
    cnt += 1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
letters = map(str, input())
target = str()
ans = int()
for l in letters:
    if len(target) == 3:
        target = target[1:]
    target = target + l
    if target == 'ABC':
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
def main(n,s):
    count = 0
    for i in range(n-2):
        if s[i]=="A" and s[i+1]=="B" and s[i+2]=="C":
            count += 1
    return count

n = int(input())
s = list(input())
print(main(n,s))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# import math
# from fractions import gcd

# import numpy as np
# import scipy as scp

# 入力の受け取り
n = int(input())
s = input()

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

Submission status: Accepted

Solution code:
n = int(input())
s = 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())
count = 0
for i in range(n-2):
    if s[i] + s[i+1] + s[i+2] == 'ABC':
        count += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

print(S.count("ABC"))

Submission status: Accepted

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

Submission status: Accepted

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

ans = (len(s)-len(s.replace('ABC', ''))) // 3
print(ans)

Submission status: Accepted

Solution code:
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 = list(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 = input()

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

Submission status: Accepted

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

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

print(answer)

Submission status: Accepted

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

print(S.count('ABC'))

Submission status: Accepted

Solution code:
n = int(input())
s = str(input())
c = 0
for i in range(n-2):
  if s[i] == "A":
    if s[i+1] == "B" and s[i+2] == "C":
      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]=="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()

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())
S=input()
a=0
for i in range(N-2):
  if S[i]=="A" and S[i+1]=="B" and S[i+2]=="C":
    a+=1
print(a)

Submission status: Accepted

Solution code:
import sys

import numpy as np
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
"""dd = [(-1, 0), (0, 1), (1, 0), (0, -1)];
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)];
ddn9 = ddn + [(0, 0)]
for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""

def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]  # WideIntPoint
def ws(): return sys.stdin.readline().split()
def si(): return int(sys.stdin.readline())  # SingleInt
def ss(): return input()
def hi(n): return [si() for _ in range(n)]
def hs(n): return [ss() for _ in range(n)]  # HeightString
def s_list(): return list(input())
def mi(n): return [wi() for _ in range(n)]  # MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]  # NumberGrid
def grid(n): return [s_list() for _ in range(n)]


def main():

    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)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = input()
count = 0
while S and "ABC" in S:
    count += 1
    S = S.replace("ABC", "", 1)
print(count)

Submission status: Accepted

Solution code:
N = int(input())
S = 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 = input()

count = 0 

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

print(count)

Submission status: Accepted

Solution code:
import re
N = input()
S = input()
list = re.findall('ABC', S)
print(len(list))

Submission status: Accepted

Solution code:
import re

n = int(input())

s = input()

li = re.findall('ABC' , s)

ans = len(li)

print(ans)

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())
S = 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 = input()

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
MOD = 10**9 + 7
INF = float('INF')

def main():
    n = int(input())
    s = input()
    p = 'ABC'
    ans = 0

    for i in range(n-2):
        for j in range(3):
            if s[i+j] == p[j]:
                if j == 2:
                    ans += 1
            else:
                break
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    input()
    S = input()
    print(S.count("ABC"))
    return


main()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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


def solve(N: int, S: str):
    ss = [S[i:(i+3)] for i in range(N-2)]
    ans = sum([1 for i, x in enumerate(ss) if x == 'ABC'])
    print(ans)


# 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 = int(input())
S = 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())
A = list(input())

i=0

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

Submission status: Accepted

Solution code:
n=int(input())
l=str(input())
print(l.count('A''B''C'))

Submission status: Accepted

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    print(str(readline().rstrip().decode('utf-8')).count("ABC"))


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
def solve():
  n = int(input())
  s = input()
  print(s.count("ABC"))
solve()

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:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
s=list(ss())
cnt=0
for i in range(n-2):

    if "".join(s[i:i+3])=="ABC":
        
        cnt+=1

print(cnt)

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

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

ans = 0
pos = 0
while s.find("ABC", pos) != -1:
    ans += 1
    pos = s.find("ABC", pos)+1

print(ans)

Submission status: Accepted

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

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

print(c)

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

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

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

print(count)

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())
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
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
input = sys.stdin.buffer.readline
def inputS(): return input().rstrip().decode()
readlines = sys.stdin.buffer.readlines 

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

Submission status: Accepted

Solution code:
import re 

n=int(input()) 
s=input().replace('ABC','1') 
s = re.sub(r"[A-Z]", "0", s) 
print(sum(list(map(int,list(s)))))

Submission status: Accepted

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

count = 0

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

Submission status: Accepted

Solution code:
# coding: utf-8

len = int(input().rstrip())
ans = input().rstrip().count("ABC")
print(ans)

Submission status: Accepted

Solution code:
#from math import sqrt
#from heapq import heappush, heappop
#from collections import deque

#a, b = [int(v) for v in input().split()]


def main():
    N = int(input())
    S = input()

    count = 0
    state = 0

    for c in S:
        if c == 'A':
            state = 1
        elif state == 1:
            if c == 'B':
                state = 2
            else:
                state = 0
        elif state == 2:
            if c == 'C':
                count += 1
            state = 0

    print(count)


main()

Submission status: Accepted

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

while True:
    if 'ABC' in s:
        s = s.replace('ABC', '', 1)
        count += 1
    else:
        break

print(count)

Submission status: Accepted

Solution code:
num=int(input())
moji=input()
ans=0

for i in range(num):
    if moji[i:i+3]=="ABC":
        ans+=1

print(ans)

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 = list(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())
K = list(str(input()))
count=0


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

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(c)

Submission status: Accepted

Solution code:
N = int(input())
s = input()
cnt = 0

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

print(cnt)

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:
if __name__ == '__main__':

	input()
	S = input()

	print(S.count("ABC"))

Submission status: Accepted

Solution code:
n = int(input())
s = 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())
S=input()
cnt=0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input()
s = input()

print(len([True for i, _ in enumerate(list(s)[0:-2]) if s[i:i + 3] == 'ABC']))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
cnt = 0
for i in range(n):
    if i == n-2 or i== n-1 :
        continue
    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 = str(input())
cnt = 0
for i in range(2,N):
    if S[i-2] == "A" and S[i-1] == "B" and S[i] == "C":
        cnt += 1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = input()
s = input()
t = s.replace('ABC','')
print(int((len(s)-len(t))/3))

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:
N = int(input())
S = input()
tot = 0
for i in range(N-2):
  if S[i:i+3] == 'ABC':
    tot += 1
print(tot)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(1000000)
input = lambda: sys.stdin.readline().rstrip()

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

print(S.count("ABC"))

Submission status: Accepted

Solution code:
_=input()
print(input().count("ABC"))

Submission status: Accepted

Solution code:
N = int(input())
S = input()
# N = 10
# S = 'ZABCDBABCQ'

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())
s = list(input())
flag = False
sec_flag = False
c = 0
for si in s:
    if si == "A":
        flag = True
        sec_flag = False
    elif flag and si == "B":
        sec_flag = True
        flag = False
    elif sec_flag and si == "C":
        c += 1
        flag, sec_flag = False, False
    else:
        flag, sec_flag = False, False
print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
num_0 = int(input())
num_1 = input()
count = 0
count_i = 0

for i in range(0,num_0):
  if num_1[i] == "A":
    count_i = 1
  elif count_i == 1 and num_1[i] == "B":
    count_i = 2
  elif count_i == 2 and num_1[i] == "C":
    count = count + 1
    count_i = 0
  else:
    count_i = 0
    
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

N = int(input())
S = 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 = input()
ls = s.replace("ABC","")
print((n-len(ls))//3)

Submission status: Accepted

Solution code:

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

print(s.count("ABC"))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

cnt=0
for i in range(len(S)):
  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:
y=input()
x=input()
count=0
for k in range(len(x)-2):
  if (x[k]=='A') and (x[k+1]=='B') and (x[k+2]=='C'):
    count+=1
print(count)

Submission status: Accepted

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

print(len(re.findall("ABC", S)))

Submission status: Accepted

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


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


# 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 = int(input())
s = list(input())

t = 0

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

print(t)

Submission status: Accepted

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

A = 0
B = 0
res = 0
for i in range(N):
	if S[i] == 'A':
		A, B = 1, 0
	elif A == 1 and S[i] == 'B':
		A, B = 0, 1
	elif B == 1 and S[i] == 'C':
		A, B = 0, 0
		res += 1
	else:
		A, B = 0, 0
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = 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())
s = input()
cnt = 0
for i in range(len(s) - 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]+s[i+1]+s[i+2]=="ABC":
        count=count+1
print(count)

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

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

ABCsp = S.split('ABC')
ABCsp = ''.join(ABCsp)
print(int(len(S)-len(ABCsp)) // 3)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

c=0
for i in range(N):
    if S[i]=="A" and S[i+1:i+3]=="BC":
        c+=1

print(c)

Submission status: Accepted

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

i = 0
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:
# coding: utf-8
# Your code here!
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 = str(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()
count=0
for i in range(N-2):
  if S[i]=='A' and S[i+1]=='B' and S[i+2]=='C':
    count=count+1
print(count)

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())
s = input()
i = 0
ans = 0
while i < n:
    if i > n - 3:
        break
    if s[i] == 'A' and s[i + 1] == 'B' and s[i + 2] == 'C':
        ans += 1
    i += 1
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# https://atcoder.jp/contests/abc150/tasks/abc150_b

import re
n = int(input())
s = input()
m = re.findall(r"ABC", s)
print(len(m))

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

count = 0
for i in range(N):
    if S[i] == "A":
        if i + 2 < N  and S[i+1:i+3] == "BC" :
            count += 1

print(count)

Submission status: Accepted

Solution code:
def main():
	n = int(input())
	s = list(str(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)
			

	
 
if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
import sys
import socket

hostname = socket.gethostname()

if hostname == 'F451C':
    sys.stdin = open('b1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    N = read_int()
    S = read_str()
    res = S.count('ABC')
    print(res)


main()

Submission status: Accepted

Solution code:
N=int(input())
S=str(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=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,S=open(0).read().split();print(S.count('ABC'))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
s=str(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 = 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()
s = 0
for i in range(0,N-2):
    if S[i:i+3] == "ABC":
        s += 1
print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import re

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

S_regex = re.compile(r'ABC')
mo = S_regex.findall(S)

print(len(mo))