AtCoder Beginner Contest 150 - Count ABC

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-----
10
ZABCDBABCQ

-----Sample Output-----
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.

Source: atcoder | Difficulty: EASY


Solutions:
n = int(input())
print(input().count('ABC'))


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


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


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


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


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


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


N = int(input())
S = input()
answer = S.count('ABC')
print(answer)


_ = input()
S = input()
cnt = 0
for (a, b, c) in zip(S[0:], S[1:], S[2:]):
	if 'ABC' == a + b + c:
		cnt += 1
print(cnt)


a = int(input())
print(input().count('ABC'))


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


c = input()
a = input()
print(a.count('ABC'))


a = input()
b = input()
n = b.split('ABC')
print(len(n) - 1)


N = int(input())
S = input()
r = S.count('ABC')
print(r)


N = input()
straw = input()
straw = straw.split('ABC')
print(len(straw) - 1)


N = int(input())
s = input()
print(s.count('ABC'))


input()
s = input()
abc = 'ABC'
print(s.count('ABC'))


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


n = int(input())
x = input()
y = x.count('ABC')
print(y)


b = input()
a = input()
print(a.count('ABC'))


N = int(input())
S = str(input())
print(S.count('ABC'))


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


n = input()
s = input()
a = s.count('ABC')
print(a)


X = int(input())
S = input()
print(S.count('ABC'))


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


n = input()
print(input().count('ABC'))


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


x = input()
y = input()
print(y.count('ABC'))


N = int(input())
S = input().split('ABC')
print(len(S) - 1)


a = input()
a = input()
print(a.count('ABC'))


def main():
	n = int(input())
	s = input()
	cnt = 0
	for i in range(len(s)):
		if s[i:i + 3] == 'ABC':
			cnt += 1
	return cnt

def __starting_point():
	print(main())
__starting_point()


i = int(input())
j = input()
print(j.count('ABC'))


N = int(input())
S = input()
i = S.count('ABC')
print(i)


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


(n, s) = [input() for _ in range(2)]
print(s.count('ABC'))


input()
w = input()
print(w.count('ABC'))


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


_ = input()
s = input()
x = s.count('ABC')
print(x)


input()
print(input().count('ABC'))


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


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


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


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


N = input()
A = str(input())
print(A.count('ABC'))


N = int(input())
S = input()
s2 = 'ABC'
print(S.count('ABC'))


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


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


_ = input()
print(input().count('ABC'))


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


input()
text = input().split('ABC')
print(len(text) - 1)


l = [input() for i in range(2)]
print(l[1].count('ABC'))


N = int(input())
S = input()
n = S.count('ABC')
print(n)


input()
x = input()
ans = x.count('ABC')
print(ans)


N = int(input())
s = list(input())
cnt = 0
for i in range(len(s) - 2):
	if s[i] + s[i + 1] + s[i + 2] == 'ABC':
		cnt += 1
print(cnt)


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


x = int(input())
arr = input()
print(arr.count('ABC'))


num = input()
char = input()
print(char.count('ABC'))


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


N = int(input())
S = input()
print(S.count('ABC', 0, N))


N = input()
print(input().count('ABC'))


N = int(input())
Ss = input()
print(Ss.count('ABC'))


N = int(input())
S = input()
a = 'ABC'
print(S.count(a))


n = int(input())
lst = list(input())
count = 0
for i in range(0, len(lst)):
	if lst[i - 2] == 'A' and lst[i - 1] == 'B' and (lst[i] == 'C'):
		count += 1
print(count)


(n, s) = open(0)
print(s.count('ABC'))


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)


k = int(input())
s = input()
print(s.count('ABC'))


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

def ans150(N: int, S: str):
	ans_count = 0
	while len(S) >= 3:
		if S[:3] == 'ABC':
			ans_count += 1
			S = S[1:]
		else:
			S = S[1:]
	return ans_count
print(ans150(N, S))


import re
n = int(input())
text = input()
pattern = 'ABC'
result = re.findall(pattern, text)
print(len(result))


A = int(input())
N = input()
ans = N.count('ABC')
print(ans)


n = input()
string = input()
print(string.count('ABC'))


num = int(input())
moji = input()
print(moji.count('ABC'))


i = int(input())
x = input()
print(x.count('ABC'))


N = int(input())
S = input()
num = S.count('ABC')
print(num)


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


n = int(input())
S = str(input())
print(S.count('ABC'))


(_, s) = open(0)
print(s.count('ABC'))


N = int(input())
S = input()
b = S.count('ABC')
print(b)


tam = int(input())
k = input()
print(k.count('ABC'))


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


print(open(0).read().count('ABC'))


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)


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


n = int(input())
l = str(input())
print(l.count('ABC'))


def __starting_point():
	N = int(input())
	S = input()
	print(S.count('ABC'))
__starting_point()


import re
n = int(input())
s = input()
res = re.findall('ABC', s)
print(len(res))


(N, S) = [input() for i in range(2)]
print(S.count('ABC'))


x = int(input())
str = input()
print(str.count('ABC'))


N = int(input())
x = input()
print(x.count('ABC'))


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


n = int(input())
s = input()
l = list(s.split('ABC'))
r = len(l) - 1
if r == -1:
	r = 0
print(r)


_ = int(input())
s = input()
print(s.count('ABC'))


_ = input()
text = input()
print(text.count('ABC'))


N = int(input())
S = input()
ans = S.count('ABC')
print(ans)


(N, S) = open(0)
print(S.count('ABC'))


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


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


gomi = input()
s = input()
print(s.count('ABC'))


x = input()
mes = input()
print(mes.count('ABC'))


N = int(input())
X = input()
print(X.count('ABC'))


l = int(input())
s = input()
print(s.count('ABC'))


n = input()
l = input()
print(l.count('ABC'))


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


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


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


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


A = int(input())
B = input()
print(B.count('ABC'))


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


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


n = input()
s = input()
lst = list(s.split('ABC'))
print(len(lst) - 1)


def answer(n: int, s: str) -> int:
	return s.count('ABC')

def main():
	n = int(input())
	s = input()
	print(answer(n, s))

def __starting_point():
	main()
__starting_point()


_ = int(input())
S = str(input())
print(S.count('ABC'))


(n, s) = open(0)
print(sum((s[i:i + 3] == 'ABC' for i in range(int(n) - 2))))


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

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


N = int(input())
cha = input()
print(cha.count('ABC'))


print(input() * 0 + str(input().count('ABC')))


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


x = input()
x = input()
print(x.count('ABC'))


n = input()
s = input()
s.split()
print(s.count('ABC'))


n = int(input())
s = input()
print(sum((s[i:i + 3] == 'ABC' for i in range(n - 2))))


import re
n = int(input())
s = input()
a = []
ans = 0
for i in range(n):
	if s[i] == 'A':
		a.append(i)
for i in a:
	if s[i:i + 3] == 'ABC':
		ans += 1
print(ans)


in1 = input()
in2 = input()
print(in2.count('ABC'))


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


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


input()
print(str(input()).count('ABC'))


(N, S) = open(0).read().split()
print(S.count('ABC'))


N = int(input())
S = input()
ans = 0
i = 0
while i + 2 <= N - 1:
	if S[i:i + 3] == 'ABC':
		ans += 1
	i += 1
print(ans)
return


N = int(input())
M = input()
print(M.count('ABC'))


A = input()
V = input()
print(V.count('ABC'))


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


s = input()
s2 = input()
print(s2.count('ABC'))


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


A = input()
print(input().count('ABC'))


input()
print(input().strip().count('ABC'))


import math
from collections import Counter
from itertools import product
ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(map(int, input().split()))
n = ii()
s = input()
print(s.count('ABC'))