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:
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


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

    a = 0

    p1 = p2 = p3 = ''
    for c in s:
        p1 = p2
        p2 = p3
        p3 = c

        if p1 == 'A' and p2 == 'B' and p3 == 'C':
            a += 1

    print(a)


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

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]+S[i+1]+S[i+2] == "A"+"B"+"C":
        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:i+3] == "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:
n = int(input())
s = input()

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

Submission status: Accepted

Solution code:
s=list(map(int,input().split()))
t=input()
a=0
for i in range(s[0]-2):
  if t[i]=='A':
    if t[i+1]=='B':
      if t[i+2]=='C':
        a+=1
print(a)

Submission status: Accepted

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

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
N = int(input())
S = 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] == 'A' and s[i+1] == 'B' and s[i+2] == 'C'):
        cnt = cnt + 1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

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

def main():
    n = ri()
    s = input()
    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="D"+input()+"D"
t=s[:3]
p=0
for i in range(3,n+2):
    t=t[1:]+s[i]
    if t=="ABC":
        p+=1
print(p)

Submission status: Accepted

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

Submission status: Accepted

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

    ans = 0
    for i in range(N):
        if i + 3 <= N:
            if S[i] + S[i+1] + S[i+2] == 'ABC':
                ans += 1
    
    print(ans)
if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys, math
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations
from collections import defaultdict, Counter

sys.setrecursionlimit(10**7)
N = int(input())
S = input()

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

Submission status: Accepted

Solution code:
a = int(input())
b = input()
ans = 0
for i in range(a-2):
  if b[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] == '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()

o=0

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

print(o)

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=str(input())
c=0
for i in range(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:
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-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(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:
import re


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

res = 0

while True:
    if re.search('ABC', S):
        R = re.search('ABC', S)
        S = S[R.end():]
        res += 1
    else:
        break

print(res)

Submission status: Accepted

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

buf1 = ""
buf2 = ""
count = 0
for s in S:
    if s == "C" and buf2 == "B" and buf1 == "A":
        count += 1
    buf1 = buf2
    buf2 = s

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
S=input()
count=0
for i in range(len(S)-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=input()
S=raw_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 math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
#N = int(input())
#K, X = map(int, input().split())

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

cnt = 0
for i in range(N) :
  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()
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:
input()
s = input()
ans = 0
while 1:
    pos = s.find('ABC')
    if pos == -1:
        break
    ans += 1
    s = s[pos + 3:]
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' and s[i+1] =='B' and s[i+2]=='C':
        cnt += 1
print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


def main():
    n = ii()
    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)


    
main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = list(str(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(len(s.split('ABC')) - 1)

Submission status: Accepted

Solution code:
# ABC150 B
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n=ni()
s=si()
print(s.count('ABC'))

Submission status: Accepted

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

cnt=0

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

Submission status: Accepted

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

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

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

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 = s.count('ABC')
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:
# coding: utf-8
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:
input()
s = input()

count = 0
for i in range(len(s) - 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] == '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= s.count('ABC')
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = list(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())
S = input()
count = 0
for i in range(2,N):
    S1 = S[i-2]
    S2 = S[i-1]
    S3 = S[i]
    if S1 == 'A' and S2 == 'B' and S3 == '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: i + 3] == "ABC":
        count += 1

print(count)

Submission status: Accepted

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

flag=0

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

Submission status: Accepted

Solution code:
from sys import stdin
#stdin = open("input.txt")

if __name__ == "__main__":
  N = int(stdin.readline())
  S = stdin.readline().rstrip()
  
  print(S.count("ABC"))

Submission status: Accepted

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

Submission status: Accepted

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

cnt = 0
for e in zip(s, s[1:], s[2:]):
    if e == ("A", "B", "C"):
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
ans = 0
i = 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()#a,b = map(int,input().split())
#L = list()map(int,input().split())
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()
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:
def examA():
    K, X = LI()
    if K*500>=X:
        ans = "Yes"
    else:
        ans = "No"
    print(ans)
    return

def examB():
    N = I()
    S = SI()
    ans = 0
    for i in range(N-2):
        if S[i:i+3]=="ABC":
            ans +=1
    print(ans)
    return

def examC():
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examB()

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
n=int(input())
s=input()
ans=0
for i in range(len(s)-2):
    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 = 0
i = 0
while i < n - 2:
    if s[i:i + 3] == 'ABC':
        ans += 1
        i += 3
    else:
        i += 1

print(ans)

Submission status: Accepted

Solution code:
import collections as c
ip = lambda : map(int, input().split())
# ##############
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,math,string,bisect
input=sys.stdin.readline
from collections import deque,defaultdict
L=lambda : list(map(int,input().split()))
Ls=lambda : list(input().split())
M=lambda : map(int,input().split())
I=lambda :int(input())
S=lambda :input().strip()
k=I()
n=input()
print(n.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 = int(input())
s = input()
ans = 0
for i in range(n):
    if s[i] == "A" and i <= n - 3:
        if 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:i+3] == 'ABC':
        ans += 1
print(ans)

Submission status: Accepted

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

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

print(S.count('ABC'))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

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()
ct=0
for i in range(3,n+1):
  if s[i-3:i]=='ABC':
    ct+=1
print(ct)

Submission status: Accepted

Solution code:
def num():
    return int(input())
def nums():
    return list(map(int,input().split()))

N = num()
S = input()
ans = 0
while S.find("ABC") != -1:
    S = S[S.find("ABC")+1:]
    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" 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(0,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:
A = input()
V = input()
print(V.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:
import math
import bisect
import collections
import itertools
import heapq
import string
import sys
sys.setrecursionlimit(10**9)
def gcd(a,b):return math.gcd #最大公約数
def lcm(a,b):return (a*b) // math.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i: divisors.append(n//i)
    return divisors
def is_prime(n):
    if n == 1: return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0: return False 
    return True
def primes(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n + 1, i): is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]
def sieve_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N = iin()
S = input()

cnt = 0
for i in range(N):
    if i+2 >= N: break
    if S[i]+S[i+1]+S[i+2] == 'ABC':
        cnt +=1
print(cnt)

Submission status: Accepted

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

print(x)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
n=int(input())
s=list(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:
import re

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(buf)

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

print(input().count("ABC"))

Submission status: Accepted

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

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

print(ct)

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()+"xxxxxxxx"
ans=chk=0
for i in range(n):
    w=s[i]+s[i+1]+s[i+2]
    if w=="ABC":
        ans+=1
print(ans)

Submission status: Accepted

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


def solve(N: int, S: str):
    ans = 0
    for i in range(2, N):
        if S[i-2] == "A" and S[i-1] == "B" and S[i] == "C":
            ans += 1
    print(ans)

    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())
l = ["A","B","C"]
ans = 0
for i in range(n-2):
    if s[i:i+3] == l:
        ans += 1
print(ans)

Submission status: Accepted

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

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


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

print(count)

Submission status: Accepted

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

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

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:
_, S = input(), input()
print(S.count('ABC'))

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:
N, = (int(x) for x in input().split())
S = input()

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:i+3]=='ABC':
        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()

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()
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:
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:
import sys
import math
import bisect
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n = ni()
s = ns()
c = 0
for i in range(n-2):
    if s[i] == "A":
        if s[i+1:i+3]=="BC":
            c += 1
print(c)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
_ = input()
S = input().strip()
ans = 0
for i in range(len(S)):
  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()
r = 0
for i in range(N-2):
    if S[i] == 'A' and S[i+1] == 'B' and S[i+2] == 'C':
        r += 1
print(r)

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

count = 0
for i in range(N):
	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:
N = int(input())
#N,K = list(map(int,input().split()))
#s = [int(input()) for i in range(3)]
S = input()
count = 0
for i in range(N-2):
    if S[i:i+3] == 'ABC':
        count += 1
print(count)

Submission status: Accepted

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

def gcd(a: int, b: int):
    """ https://cocodrips.hateblo.jp/entry/2014/03/05/143623
    """
    while b:
        a, b = b, a%b
    return a

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


def main():
    N = int(input())
    #K,X = map(int, input().split())
    #vA = list(map(int, input().split())
    S = input().rstrip()
    #print(S)
    #print(lcm(N, M))
    #print("Yes" if X<=500*K else "No")
    print(S.count("ABC"))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

print(s)

Submission status: Accepted

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

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



if __name__ == "__main__":
    main()

Submission status: Accepted

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
print(s.replace('ABC', '-').count('-'))

Submission status: Accepted

Solution code:
def main():
    import sys
    N=int(sys.stdin.readline())
    S=input()
    print(S.count('ABC'))
    

main()

Submission status: Accepted

Solution code:
N = int(input())
S = list(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:
import math
import itertools
import fractions
import heapq
import collections
import bisect
import sys

sys.setrecursionlimit(10**9)
mod = 998244353
inf = 10**20

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

n = I()
s = S()

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