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:
import sys
import math
input = sys.stdin.readline


def main():
    sc = Scan()
    N = sc.intarr()[0]
    S = sc.strarr()[0]

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

    print(count)


def dfs(N):
    global dp
    if N <= 0:
        return 1

    if dp[N] > -1:
        return dp[N]
    ans = 0
    for i in range(1, 7):
        ans += dfs(N-i)
    dp[N] = ans
    return ans


class Scan():

    def intarr(self):
        num_array = list(map(int, input().split()))
        return num_array

    def intarr_ver(self, n):
        return [int(input()) for _ in range(n)]

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


def display(array):
    for a in range(len(array)):
        if len(array) - a != 1:
            print(array[a], end=' ')
        else:
            print(array[a])


def gcd(a, b):  # 最大公約数
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):  # 最小公倍数
    return a * b // gcd(a, b)


main()

Submission status: Accepted

Solution code:
#import sys
MOD = 10 ** 9 + 7
#input = sys.stdin.readline
import math

import itertools

#import bisect

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default


#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]
def main():
    n=int(input())
    s=list(map(str,input()))
    temp=0
    count=0
    for i in range(n):
        if s[i]=="A":
            temp=1
        elif temp==1 and s[i]=="B":
            temp+=1
        elif temp==2 and s[i]=="C":
            temp=0
            count+=1
        else:
            temp=0
    print(count)




if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

cnt = 0
for n in range(N - 2):
    if S[n] == "A" and S[n + 1] == "B" and S[n + 2] == "C":
        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:
# -*- coding: utf-8 -*-
N = int(input())
S = str(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]+s[i+1]+s[i+2]=='ABC':
        ans+=1
        
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

S=list(S)

count=0
for i in range(2, N):
  if S[i]=="C":
    if S[i-1]=="B":
      if S[i-2]=="A":
        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:
N=int(input())
S=input().strip()
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())
ans=0
for i in range(n-2):
    if s[i:i+3]==list('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()
print(sum([1 for i in range(N) if S[i:i+3]=="ABC"]))

Submission status: Accepted

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

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

import re

m = re.findall(r'ABC', s)
print(len(m))

Submission status: Accepted

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

Submission status: Accepted

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


def solve(N: int, S: str):
    a=0
    for i in range(N-2):
        a+=1 if S[i:i+3]=="ABC" else 0
    print(a)
    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:
def main():
    n = input()
    s = input()
    count = 0
    p = s.find("ABC")
    while p != -1:
        count += 1
        p = s.find("ABC", p + 1)

    print(count)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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 = input()
S = raw_input()
print sum(S[i:i+3]=="ABC" for i in range(N))

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()
c = 0
for i in range(N-2):
    if S[i]+S[i+1]+S[i+2] == "ABC":
        c += 1
print(c)

Submission status: Accepted

Solution code:
N = int(input())
a = 0
result = 0
for i in input():
    if i == "A":
        a = 1
    elif i == "B" and a == 1:
        a = 2
    elif i == "C" and a == 2:
        result += 1
        a = 0
    else:
        a = 0
print(result)

Submission status: Accepted

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

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

result = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from pprint import pprint

def solve(n, s):
    print(s.count("ABC"))


if __name__ == '__main__':
    n = int(sys.stdin.readline().strip())
    s = sys.stdin.readline().strip()
    solve(n, s)

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]=='A' and s[i+1]=='B' and s[i+2]=='C':
        count+=1
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

cnt=0
i=0
while i < n-2:
    #print(s[i:i+3])
    if s[i:i+3]=="ABC":
        cnt+=1
    i+=1

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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=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:
# -*- coding: utf-8 -*-

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

start = 0
total = 0
while True:
    number = S.find('ABC', start)
    if number == -1:
        break

    start = number + 3
    total += 1

print(total)

Submission status: Accepted

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

Submission status: Accepted

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

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

import math

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)


def resolve():
    N = [int(x) for x in sys.stdin.readline().split()][0]
    S = [x for x in sys.stdin.readline().split()][0]

    logger.debug('{}'.format([N, S]))

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

    print(c)


if __name__ == "__main__":
    resolve()

# AtCoder Unit Test で自動生成できる, 最後のunittest.main は消す
# python -m unittest template/template.py で実行できる
# pypy3 -m unittest template/template.py で実行できる
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """10
ZABCDBABCQ"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """19
THREEONEFOURONEFIVE"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """33
ABCCABCBABCCABACBCBBABCBCBCBCABCB"""
        output = """5"""
        self.assertIO(input, output)

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 += 1

print(count)

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
n = int(input())
s = input()

x = s.split("ABC")
print(len(x) - 1)

Submission status: Accepted

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

ret = 0

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

print(ret)

Submission status: Accepted

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

    c = 0
    for n in range(0, N-2):
        if S[n:n+3] == "ABC":
            c += 1
    print(c)

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#K, X = map(int, input().split())
# R,S,P = map(int, input().split())
# T = input()
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:
from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
N = int(stdin.readline().rstrip())
s = stdin.readline().rstrip()

count = 0
for el in range(N):
    if el + 2 >= N:
        break
    if s[el] == 'A' and s[el+1] == 'B' and s[el+2] == 'C':
        count += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

k=0
i=0
while(1):
  if S[i]=="A":
    if S[i+1]=="B" and S[i+2]=="C":
      k+=1
      i+=2
  i+=1
  if i>=N-2:
    break
print(k)

Submission status: Accepted

Solution code:
from sys import stdin
import numpy as np


# noinspection PyShadowingBuiltinsInspection

def main():
    N = int(input())
    S = input()
    abc = ""
    ret = 0
    for i in range(len(S)):
        if S[i] == "A":
            abc = "A"
        elif S[i] == "B" and abc == "A":
            abc = "AB"
        elif S[i] == "C" and abc == "AB":
            ret += 1
            abc = ""
        else:
            abc = ""
    print(ret)
    return


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 0
for i, ss in enumerate(s[:-2]):
    if s[i:i+3] == 'ABC':
        ans += 1
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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 += 1
print(count)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
abc = 'ABC'
ans = S.split(abc)
print(len(ans)-1)

Submission status: Accepted

Solution code:
import re
n = int(input())
s = input()
print(re.sub('ABC', 'a', s).count('a'))

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()
s_new = s.replace('ABC', '',50)

print(int((len(s) - len(s_new))/3))

Submission status: Accepted

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

Sum = 0

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

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

# 最小公倍数
def gcd(a, b):
  if a < b:
      a, b = b, a
  while a % b != 0:
      a, b = b, a % b
  return b
 
# 最大公約数 
def lcm(a, b):
  y = a*b / gcd(a, b)
  return int(y)

n = INT()
s = input()

count = 0
abc = "ABC"
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()
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:
#!python3

def iim():
    return map(int, input().rstrip().split())

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

    i = -1
    n = 0
    while True:
        i = S.find("ABC", i+1)
        if i == -1:
            break
        n += 1

    print(n)




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

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

print(cnt)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
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 = int(input())
S = input()
ans = 0
while 'ABC' in S:
    ans += 1
    ind = S.find('ABC')
    S = S[ind+3:]
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import re

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

r = re.findall("ABC", s)

print(len(r))

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:
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]
    N = II()
    S = input()
    count = 0

    i = 0
    while i < len(S)-2:
        if S[i] == 'A' and S[i+1] == 'B' and S[i+2] == 'C':
            count += 1
            i += 2
        i += 1
    print(count)



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
S=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:
def s_in():
    return input()

def n_in():
    return int(input())

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

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res

N = n_in()
S = s_in()
print(len([i for i in range(N) if S[i:i+3] == "ABC"]))

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

x = ('T' + S).split('ABC')
print(len(x) - 1)

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:
# coding:utf-8

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:
import re
n = int(input())
s = input()

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

print(len(res))

Submission status: Accepted

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

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:
# coding: utf-8
N = int(input())
S = input()
if len(S) == 3:
    pass
ans = 0
for i in range(len(S)-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] == "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()

cnt = S.count('ABC')

print(cnt)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
#print(S)
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().strip()
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=str(input())
L=list(S)
count=0
for i in range(len(L)-2):
    if L[i]=='A':
        if L[i+1]=='B':
            if L[i+2]=='C':
                count+=1
print(count)

Submission status: Accepted

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

print(s.count('ABC'))

Submission status: Accepted

Solution code:
import sys
import math
def i():return int(sys.stdin.readline().replace("\n",""))
def i2():return map(int,sys.stdin.readline().replace("\n","").split())
def s():return str(sys.stdin.readline().replace("\n",""))
def l():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def lx():return list(map(lambda x:int(x)*-1,sys.stdin.readline().replace("\n","").split()))
def t():return tuple(map(int,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":pass

n = i()
s = s()
cnt = 0
l = s.split("ABC")
if len(l) == 1:
    print(0)
else:
    print(len(l)-1)

Submission status: Accepted

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

print(s.count("ABC"))

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    S = input()

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

if __name__ == '__main__':
    main()

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
tmp = ""
for i in range(N):
    if tmp == 1 and S[i] == "B":
        tmp += 1
    elif tmp == 2 and S[i] == "C":
        ans += 1
        tmp = ""
    elif S[i] == "A":
        tmp = 1
    else:
        tmp = 0
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()
ans=0
ind=s.find("ABC")
while(ind!=-1):
    ans+=1
    ind=s.find("ABC",ind+1)
print(ans)

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":
      if S[i+1]=="B":
         if S[i+2]=="C":
            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] == 'A' and S[i+1] == 'B' and S[i+2] =='C':
        count += 1
        i = i+2
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(list(zip(S, S[1:], S[2:])).count(('A', 'B', 'C')))

Submission status: Accepted

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

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

Submission status: Accepted

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

match = 'ABC'

result = 0
for i in range(len(S)-len(match) + 1):
    if match==S[i:i+3]:
        result += 1

print(result)

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:
a=int(input())
s=input()
l=s.count("ABC")
print(l)

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

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

ans = S.count('ABC')

print(ans)

Submission status: Accepted

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

print(b.count("ABC"))

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 = 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()
answer=0
for i in range(n-2):
    if s[i]=='A' and s[i+1]=='B' and s[i+2]=='C':
        answer+=1
print(answer)

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()
a=S.count("ABC")
print(a)

Submission status: Accepted

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