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()
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()
ans = 0
s = 0
while True:
    x = S.find('ABC', s)
    if x == -1:
        break
    else:
        s = x+1
        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()
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()
x = s.count("ABC")
print(x)

Submission status: Accepted

Solution code:
#! /usr/bin/env python3
import sys
sys.setrecursionlimit(10**9)


INF=10**20
def solve(N: int, S: str):
    T = S.replace("ABC","")
    ans = N - len(T)
    ans //= 3

    print(ans)
    return

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



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())
s=input()
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':
        i+=1
        if S[i]=='B':
            i+=1
            if S[i]=='C':
                ans+=1
print(ans)

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

import math

length = int(input())
total = 0
str = input()
table = list(str)
for i in range(length - 2):
    if table[i] == "A":
        if table[i+1] == "B":
            if table[i+2] == "C":
                total += 1

print(total)

Submission status: Accepted

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

print(S.count("ABC"))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,s = [input() for _ in range(2)]
print(s.count("ABC"))

Submission status: Accepted

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


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


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Accepted

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

cnt=0

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

print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = 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 = s.count('ABC')
print(cnt)

Submission status: Accepted

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

s = s.replace("ABC", "")

# print(s)

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import sys

INF = float('inf')


def solve(N: int, S: str):
    return S.count('ABC')


def main():

    sys.setrecursionlimit(10 ** 6)

    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
    print(f'{solve(N, S)}')


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
print(input()*0 + str(input().count("ABC")))

Submission status: Accepted

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

for i,_ in enumerate(s) :
    if s[i:i+3] == "ABC":
        count += 1

print(count)

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# # input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
# mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
s = input()
tmp = s.replace('ABC', '1')
ans = 0
for t in tmp:
    if(t == '1'):
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# # input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
# mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
s = input()

tmp = ''
ans = 0
for st in s:
    l = [tmp, st]
    tmp = ''.join(l)
    if(tmp == 'ABC'):
        ans += 1
    if(len(tmp) >= 3):
        tmp = tmp[1:]
print(ans)

Submission status: Accepted

Solution code:
N,S = open(0).read().split()
N = int(N)
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()

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

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

print(cnt)

Submission status: Accepted

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

print(S.count('ABC'))

Submission status: Accepted

Solution code:
a = 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):
    if  S[i:i+3] == "ABC":
        cnt += 1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
number = int(input())
word = input()
answer = word.count('ABC')
print(answer)

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()
print(S.count('ABC'))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
s = input()

print(s.count('ABC'))

Submission status: Accepted

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

print(s.count('ABC'))

Submission status: Accepted

Solution code:
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

def main():
    N = I()
    S = _S()
    print(S.count("ABC"))

main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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 p in range(len(s)):
  if p <= n - 3:
    if s[p] == 'A':
      if s[p + 1] == 'B' and s[p + 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:i+3]=="ABC":
        ans+=1
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import re

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

result = re.findall(r'ABC', S)

print(len(result))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
 
#print(s.count('ABC'))
for ni in range(n):
  if s[ni:ni+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:
# Count ABC
N = int(input())
S = input()

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

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

a_lst = ([i for i, x in enumerate(S) if x == 'A'])
count = 0
for j in a_lst:
    if len(S) >= j + 3:
        if S[j+1] == 'B' and S[j+2] == 'C':
            count += 1
print(count)

Submission status: Accepted

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

cnt = 0

for i in range(len(s)):
    if s[i] == "A" and i+2 <= len(s)-1:
        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())
print(s.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()
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()
 
slen=len(S)
nabc=0
for i in range(0,slen-2):
  if S[i:i+3]=='ABC':
    nabc+=1
 
print(nabc)

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == "__main__":
    solve()

Submission status: Accepted

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

print(s.count("ABC"))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input()
print(input().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()

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

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range(len(S)):
    if i <= len(S)-3:
        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] == 'A':
        if s[i+1] == 'B':
            if s[i+2] == 'C':
                cnt += 1

print(cnt)

Submission status: Accepted

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

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:
n = input()
print(len(input().split("ABC")) - 1)

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

print(s.count('ABC'))

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

if '__main__' == __name__:
    resolve()

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    s = input()
    ans = s.count('ABC')
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

print(s.count("ABC"))

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

    ans = S.count('ABC')

    print(ans)


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=input()
print(input().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=str(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())
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()
c = 0
for i in range(len(s) - 2):
    if s[i:i + 3] == 'ABC':
        c += 1
print(c)

Submission status: Accepted

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

Submission status: Accepted

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

    if N != len(S):
        return

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

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

main()

Submission status: Accepted

Solution code:
n=int(input())
s=input()
cnt=0
i=1
while(i<n-1):
    if(s[i-1]=='A' and s[i]=='B' and s[i+1]=='C'):
        cnt+=1
    i+=1
        
print(cnt)

Submission status: Accepted

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

n=int(input())
s=input().strip()
print(s.count('ABC'))

Submission status: Accepted

Solution code:
n = int(input())

s = input()
a = [str(c) for c in s]

c = 0

for i in range(n-2):
  if a[i] == 'A' and a[i+1] == 'B' and a[i+2] == 'C':
    c +=1
  else:
    continue
    
print(c)

Submission status: Accepted

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

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 = s.replace('ABC', 'a').count('a')
print(cnt)

Submission status: Accepted

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

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
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:
import os, sys, re, math

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

T = S.replace('ABC', '')
print((len(S) - len(T)) // 3)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import re

_ = input()
x = input()

print(len(re.findall(r"ABC", x)))

Submission status: Accepted

Solution code:
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))

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:
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))

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

ans = 0
aDec = False
bDec = False

for i in range(n):
    if s[i] == "A":
        aDec = True
        bDec = False
    elif s[i] == "B":
        if (aDec):
            bDec = True
        else:
            bDec = False
        aDec = False
    elif s[i] == "C":
        if (bDec):
            ans += 1
        bDec = False
        aDec = False
    else:
        bDec = False
        aDec = False
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=input()
b=[]

for i in range(n-2):
  b.append(a[i]+a[i+1]+a[i+2])
  
print(b.count('ABC'))

Submission status: Accepted

Solution code:
N=int(input())
S=str(input())
S=S.replace('ABC','')
if N==len(S):
  print(0)
else:
  print((N-len(S))//3)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(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 : i + 3] == "ABC":
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
# abc150_b.py
# https://atcoder.jp/contests/abc150/tasks/abc150_b

# B - Count ABC /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 200点

# 問題文
# 英大文字のみからなる長さ Nの文字列 Sがあります。
# Sの連続する部分列 (入出力例をご覧ください) として ABC がいくつ含まれるかを求めてください。

# 制約
#     3≤N≤50
#     Sは英大文字のみからなる。

# 入力
# 入力は以下の形式で標準入力から与えられる。
# N
# S

# 出力
# Sが連続する部分列として含む ABC の個数を出力せよ。

# 入力例 1
# 10
# ZABCDBABCQ

# 出力例 1
# 2

# Sの 2 文字目から 4 文字目、および 7 文字目から 9 文字目の 2箇所の連続する部分列が ABC に一致しています。

# 入力例 2
# 19
# THREEONEFOURONEFIVE

# 出力例 2
# 0

# Sは ABC に一致する連続する部分列を含みません。

# 入力例 3
# 33
# ABCCABCBABCCABACBCBBABCBCBCBCABCB

# 出力例 3
# 5


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    S = lines[1]
    N = int(lines[0])
    # N, M = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

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

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['10', 'ZABCDBABCQ']
        lines_export = [2]
    if pattern == 2:
        lines_input = ['19', 'THREEONEFOURONEFIVE']
        lines_export = [0]
    if pattern == 3:
        lines_input = ['33', 'ABCCABCBABCCABACBCBBABCBCBCBCABCB']
        lines_export = [5]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(2)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
#k, x = map(int, input().split())
#hl = list(map(int, input().split()))
s = input()
st='ABC'
count=0
for i in range(n-2):
    if s[i:i+3] == st:
        count+=1
print(count)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N=int(input())
S=list(input().split("ABC"))
print(len(S)-1)

Submission status: Accepted

Solution code:
input();print(input().count('ABC'))

Submission status: Accepted

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

for i in range(N-2):
  if s[i] == 'A':
    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=str(input())
d=s.count('ABC')
print(d)

Submission status: Accepted

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