Before becoming a successful trader William got a university degree. During his education an interesting situation happened, after which William started to listen to homework assignments much more attentively. What follows is the correct formal description of the homework assignment:

You are given a string $s$ of length $n$ only consisting of characters "a", "b" and "c". There are $q$ queries of format ($pos, c$), meaning replacing the element of string $s$ at position $pos$ with character $c$. After each query you must output the minimal number of characters in the string, which have to be replaced, so that the string doesn't contain string "abc" as a substring. A valid replacement of a character is replacing it with "a", "b" or "c".

A string $x$ is a substring of a string $y$ if $x$ can be obtained from $y$ by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.


-----Input-----

The first line contains two integers $n$ and $q$ $(1 \le n, q \le 10^5)$, the length of the string and the number of queries, respectively.

The second line contains the string $s$, consisting of characters "a", "b" and "c".

Each of the next $q$ lines contains an integer $i$ and character $c$ $(1 \le i \le n)$, index and the value of the new item in the string, respectively. It is guaranteed that character's $c$ value is "a", "b" or "c".


-----Output-----

For each query output the minimal number of characters that would have to be replaced so that the string doesn't contain "abc" as a substring.


-----Examples-----

Input
9 10
abcabcabc
1 a
1 b
2 c
3 a
4 b
5 c
8 a
9 b
1 c
4 a
Output
3
2
2
2
1
2
1
1
1
0


-----Note-----

Let's consider the state of the string after each query:

$s =$ "abcabcabc". In this case $3$ replacements can be performed to get, for instance, string $s =$ "bbcaccabb". This string does not contain "abc" as a substring.

$s =$ "bbcabcabc". In this case $2$ replacements can be performed to get, for instance, string $s =$ "bbcbbcbbc". This string does not contain "abc" as a substring.

$s =$ "bccabcabc". In this case $2$ replacements can be performed to get, for instance, string $s =$ "bccbbcbbc". This string does not contain "abc" as a substring.

$s =$ "bcaabcabc". In this case $2$ replacements can be performed to get, for instance, string $s =$ "bcabbcbbc". This string does not contain "abc" as a substring.

$s =$ "bcabbcabc". In this case $1$ replacements can be performed to get, for instance, string $s =$ "bcabbcabb". This string does not contain "abc" as a substring.

$s =$ "bcabccabc". In this case $2$ replacements can be performed to get, for instance, string $s =$ "bcabbcabb". This string does not contain "abc" as a substring.

$s =$ "bcabccaac". In this case $1$ replacements can be performed to get, for instance, string $s =$ "bcabbcaac". This string does not contain "abc" as a substring.

$s =$ "bcabccaab". In this case $1$ replacements can be performed to get, for instance, string $s =$ "bcabbcaab". This string does not contain "abc" as a substring.

$s =$ "ccabccaab". In this case $1$ replacements can be performed to get, for instance, string $s =$ "ccabbcaab". This string does not contain "abc" as a substring.

$s =$ "ccaaccaab". In this case the string does not contain "abc" as a substring and no replacements are needed.

Difficulty: EASY

Solutions:
import sys
import bisect
import math
from collections import deque
input = lambda : sys.stdin.readline().strip()
mod = 10 ** 9 + 7

def solve():
	(n, q) = map(int, input().split())
	s = input()
	cnt = 0
	for i in range(n):
		if i + 2 < n and s[i:i + 3] == 'abc':
			cnt += 1
	s = list(s)
	ans = ''
	for _q in range(q):
		(pos, char) = input().split()
		pos = int(pos)
		pos -= 1
		if s[pos] != char:
			if s[pos] == 'a' and pos + 2 < n and (s[pos:pos + 3] == ['a', 'b', 'c']):
				cnt -= 1
			elif s[pos] == 'b' and 0 < pos < n - 1 and (s[pos - 1:pos + 2] == ['a', 'b', 'c']):
				cnt -= 1
			elif s[pos] == 'c' and pos > 1 and (s[pos - 2:pos + 1] == ['a', 'b', 'c']):
				cnt -= 1
			s[pos] = char
			if s[pos] == 'a' and pos + 2 < n and (s[pos:pos + 3] == ['a', 'b', 'c']):
				cnt += 1
			elif s[pos] == 'b' and 0 < pos < n - 1 and (s[pos - 1:pos + 2] == ['a', 'b', 'c']):
				cnt += 1
			elif s[pos] == 'c' and pos > 1 and (s[pos - 2:pos + 1] == ['a', 'b', 'c']):
				cnt += 1
		ans += str(cnt) + '\n'
	return ans[:-1]
t = 1
for _ in range(t):
	print(solve())


from sys import stdin
input = stdin.readline
(n, q) = [int(i) for i in input().split()]
s = list(input())
m = ''.join(s)
c = m.count('abc')
for i in range(q):
	(a, b) = input().split()
	a = int(a) - 1
	if s[a] == b:
		print(c)
		continue
	if s[a] == 'a':
		if a < n - 2 and s[a + 1] == 'b' and (s[a + 2] == 'c'):
			c -= 1
	elif s[a] == 'c':
		if a > 1 and s[a - 2] == 'a' and (s[a - 1] == 'b'):
			c -= 1
	elif s[a] == 'b':
		if a < n - 1 and a > 0 and (s[a - 1] == 'a') and (s[a + 1] == 'c'):
			c -= 1
	s[a] = b
	if b == 'a':
		if a < n - 2 and s[a + 1] == 'b' and (s[a + 2] == 'c'):
			c += 1
	elif b == 'c':
		if a > 1 and s[a - 2] == 'a' and (s[a - 1] == 'b'):
			c += 1
	elif a < n - 1 and a > 0 and (s[a - 1] == 'a') and (s[a + 1] == 'c'):
		c += 1
	print(c)


(n, q) = input().split()
(n, q) = (int(n), int(q))
s = input()
abc = s.count('abc')
s = list(s)
lst = []
while q > 0:
	(i, c) = input().split()
	i = int(i)
	if s[i - 1] != c:
		if i >= 1 and i + 1 <= len(s) - 1:
			if s[i - 1] == 'a' and s[i] == 'b' and (s[i + 1] == 'c'):
				abc -= 1
			elif c == 'a' and s[i] == 'b' and (s[i + 1] == 'c'):
				abc += 1
		if i >= 2 and i <= len(s) - 1:
			if s[i - 1] == 'b' and s[i - 2] == 'a' and (s[i] == 'c'):
				abc -= 1
			elif c == 'b' and s[i - 2] == 'a' and (s[i] == 'c'):
				abc += 1
		if i >= 3:
			if s[i - 1] == 'c' and s[i - 2] == 'b' and (s[i - 3] == 'a'):
				abc -= 1
			elif c == 'c' and s[i - 2] == 'b' and (s[i - 3] == 'a'):
				abc += 1
	s[i - 1] = c
	lst.append(str(abc))
	q -= 1
print('\n'.join(lst))


import sys

def doStuff(i):
	if s[i] == 'c':
		if i > 1:
			if s[i - 1] == 'b' and s[i - 2] == 'a':
				return True
	elif s[i] == 'b':
		if i > 0 and i < n - 1:
			if s[i - 1] == 'a' and s[i + 1] == 'c':
				return True
	elif i < n - 2:
		if s[i + 1] == 'b' and s[i + 2] == 'c':
			return True
	return False
(n, q) = map(int, sys.stdin.readline().split())
s = sys.stdin.readline().rstrip()
mn = s.count('abc')
s = list(s)
for _ in range(q):
	(i, c) = sys.stdin.readline().split()
	i = int(i) - 1
	if s[i] == c:
		print(mn)
		continue
	if doStuff(i):
		mn -= 1
	s[i] = c
	if doStuff(i):
		mn += 1
	print(mn)


import sys
input = sys.stdin.readline
(n, q) = map(int, input().split())
s = input()[:-1]
t = s.count('abc')
w = list(s)
for _ in range(q):
	(i, x) = input()[:-1].split()
	i = int(i)
	if w[i - 1] == x:
		print(t)
	else:
		d = ''.join(w[max(0, i - 3):min(i + 2, n)])
		c1 = d.count('abc')
		w[i - 1] = x
		d = ''.join(w[max(0, i - 3):min(i + 2, n)])
		c2 = d.count('abc')
		t -= c1 - c2
		print(t)


def solve(N, Q, S, queries):
	S = list(S)
	cnt = 0
	for (i, c) in enumerate(S):
		if c == 'a' and i + 2 < N and (S[i + 1] == 'b') and (S[i + 2] == 'c'):
			cnt += 1
	for (i, c) in queries:
		if S[i] == 'a' and i + 2 < N and (S[i + 1] == 'b') and (S[i + 2] == 'c'):
			cnt -= 1
		elif S[i] == 'b' and i + 1 < N and (S[i + 1] == 'c') and (i - 1 >= 0) and (S[i - 1] == 'a'):
			cnt -= 1
		elif S[i] == 'c' and i - 2 >= 0 and (S[i - 2] == 'a') and (S[i - 1] == 'b'):
			cnt -= 1
		S[i] = c
		if S[i] == 'a' and i + 2 < N and (S[i + 1] == 'b') and (S[i + 2] == 'c'):
			cnt += 1
		elif S[i] == 'b' and i + 1 < N and (S[i + 1] == 'c') and (i - 1 >= 0) and (S[i - 1] == 'a'):
			cnt += 1
		elif S[i] == 'c' and i - 2 >= 0 and (S[i - 2] == 'a') and (S[i - 1] == 'b'):
			cnt += 1
		print(cnt)
(N, Q) = list(map(int, input().split()))
S = input()
queries = []
for i in range(Q):
	(num, c) = map(str, input().split())
	queries.append((int(num) - 1, c))
solve(N, Q, S, queries)


import sys

def solve():
	inp = sys.stdin.readline
	(n, q) = map(int, inp().split())
	a = [None] * (n + 4)
	i = 2
	for c in inp():
		a[i] = c
		i += 1
	a[1] = 'd'
	a[0] = 'd'
	a[n + 2] = 'd'
	a[n + 3] = 'd'
	r = 0
	for i in range(2, n + 2):
		r += a[i] == 'a' and a[i + 1] == 'b' and (a[i + 2] == 'c')
	for i in range(q):
		(p, c) = inp().split()
		p = int(p)
		for i in range(p - 1, p + 2):
			r -= a[i] == 'a' and a[i + 1] == 'b' and (a[i + 2] == 'c')
		a[p + 1] = c
		for i in range(p - 1, p + 2):
			r += a[i] == 'a' and a[i + 1] == 'b' and (a[i + 2] == 'c')
		print(r)

def main():
	solve()
main()


(n, q) = map(int, input().split())
str = input()
res = str.count('abc')

def is_abc(my_str, idx):
	str_len = len(my_str)
	if my_str[idx - 1] == 'a':
		if idx >= str_len - 1:
			return False
		else:
			return my_str[idx - 1:idx + 2] == ['a', 'b', 'c']
	if my_str[idx - 1] == 'b':
		if idx == str_len or idx == 1:
			return False
		else:
			return my_str[idx - 2:idx + 1] == ['a', 'b', 'c']
	if my_str[idx - 1] == 'c':
		if idx < 3:
			return False
		else:
			return my_str[idx - 3:idx] == ['a', 'b', 'c']
	return False
str = list(str)
f_res = []
for _ in range(q):
	(idx, let) = input().split()
	idx = int(idx)
	if is_abc(str, idx) == True:
		str[idx - 1] = let
		if is_abc(str, idx) != True:
			res -= 1
	else:
		str[idx - 1] = let
		if is_abc(str, idx) == True:
			res += 1
	f_res.append(res)
for a in f_res:
	print(a)


import sys
import math

def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()

def multi_Fun(arr):
	count = 0
	for i in range(n - 2):
		if lst[i:i + 3] == ['a', 'b', 'c']:
			count += 1
	return count
	pass

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
(n, q) = MI()
lst = list(SI())
count = ''.join(lst).count('abc')
for __ in range(q):
	temp = SI().split()
	p = int(temp[0]) - 1
	c = temp[1]
	b1 = lst[max(p - 2, 0):min(n, p + 3)]
	b1 = ''.join(b1).count('abc')
	lst[p] = c
	b2 = ''.join(lst[max(p - 2, 0):min(n, p + 3)]).count('abc')
	count += b2 - b1
	print(count)


import sys
(n, q) = map(int, sys.stdin.readline().split())
s = list(sys.stdin.readline().strip())
idx = 2
res = 0
while idx < len(s):
	if s[idx - 2] == 'a' and s[idx - 1] == 'b' and (s[idx] == 'c'):
		res += 1
		idx += 3
	else:
		idx += 1
for _ in range(q):
	(i, c) = sys.stdin.readline().split()
	i = int(i) - 1
	start = max(0, i - 2)
	for idx in range(start, i + 1):
		if idx + 2 >= len(s):
			break
		if s[idx] == 'a' and s[idx + 1] == 'b' and (s[idx + 2] == 'c'):
			res -= 1
	s[i] = c
	for idx in range(start, i + 1):
		if idx + 2 >= len(s):
			break
		if s[idx] == 'a' and s[idx + 1] == 'b' and (s[idx + 2] == 'c'):
			res += 1
	print(res)


def c(i):
	return s[i:i + 3] == ['a', 'b', 'c']
(n, q) = map(int, input().split())
s = list(input())
cnt = 0
tc = [0] * n
r = [0] * n
for i in range(n - 2):
	if c(i):
		cnt += 1
		r[i] = 1
		r[i + 1] = 2
		r[i + 2] = 3
ans = []
for _ in range(q):
	(j, p) = input().split()
	j = int(j) - 1
	s[j] = p
	for i in range(max(0, j - 2), min(n - 2, j + 1)):
		if c(i) and r[i] != 1:
			cnt += 1
			r[i] = 1
			r[i + 1] = 2
			r[i + 2] = 3
		elif not c(i) and (r[i] == 1 or r[i + 1] == 2 or r[i + 2] == 3):
			cnt -= 1
			if r[i] == 1:
				r[i] = 0
			if r[i + 1] == 2:
				r[i + 1] = 0
			if r[i + 2] == 3:
				r[i + 2] = 0
	ans.append(cnt)
print('\n'.join(map(str, ans)))


def recalculate(pos, c, s, current):
	was = count_abc(s, pos - 2, pos + 3)
	s[pos] = c
	now = count_abc(s, pos - 2, pos + 3)
	return current - was + now

def count_abc(s, fr, to):
	count = 0
	if fr < 0:
		fr = 0
	if to > len(s):
		to = len(s)
	for i in range(fr, to - 2):
		if s[i:i + 3] == list('abc'):
			count = count + 1
	return count
import sys
line = sys.stdin.readline()
(n, q) = line.split(' ')
n = int(n)
q = int(q)
s = list(sys.stdin.readline())
current_count = count_abc(s, 0, len(s))
for _ in range(0, q):
	(pos, c) = sys.stdin.readline().split(' ')
	pos = int(pos) - 1
	c = c[0]
	current_count = recalculate(pos, c, s, current_count)
	print(current_count)


import itertools
from math import floor, log, log2, ceil, sqrt
from itertools import groupby
from decimal import Decimal, getcontext
import sys
from collections import deque
t = 1
res = []
[n, q] = list(map(int, input().split()))
for _ in range(t):
	s = list(input())
	poses = []
	starts = set()
	for i in range(n):
		if s[i] == 'a' and i + 2 < n and (''.join(s[i:i + 3]) == 'abc'):
			starts.add(i)
	count = len(starts)
	ans = []
	for _ in range(q):
		pos = input().split()
		(pos, sym) = (int(pos[0]), pos[1])
		pos -= 1
		s[pos] = sym
		start = max(pos - 2, 0)
		end = min(pos + 2, n - 1)
		for j in range(start, end + 1):
			if ''.join(s[j:j + 3]) == 'abc':
				if not j in starts:
					starts.add(j)
					count += 1
			elif j in starts:
				count -= 1
				starts.remove(j)
		ans.append(count)
for i in range(q):
	print(ans[i])


(n, q) = map(int, input().split())
s = input()
s1 = list(s)
count1 = s.count('abc')
for i in range(q):
	pk = input().split()
	p = int(pk[0]) - 1
	k = pk[1]
	if k == s1[p]:
		print(count1)
	else:
		if s1[p] == 'a':
			if p <= n - 3 and s1[p + 1] == 'b' and (s1[p + 2] == 'c'):
				if count1 > 0:
					count1 -= 1
		elif s1[p] == 'b':
			if p <= n - 2 and p >= 1 and (s1[p - 1] == 'a') and (s1[p + 1] == 'c'):
				if count1 > 0:
					count1 -= 1
		elif s1[p] == 'c':
			if p >= 2 and s1[p - 2] == 'a' and (s1[p - 1] == 'b'):
				if count1 > 0:
					count1 -= 1
		s1[p] = k
		if s1[p] == 'a':
			if p <= n - 3 and s1[p + 1] == 'b' and (s1[p + 2] == 'c'):
				if count1 < n:
					count1 += 1
		elif s1[p] == 'b':
			if p >= 1 and p <= n - 2 and (s1[p - 1] == 'a') and (s1[p + 1] == 'c'):
				if count1 < n:
					count1 += 1
		elif s1[p] == 'c':
			if p >= 2 and s1[p - 2] == 'a' and (s1[p - 1] == 'b'):
				if count1 < n:
					count1 += 1
		print(count1)


(n, q) = list(map(int, input().split()))
s = input()
abc_count = s.count('abc')
s = list(s)
for _ in range(q):
	(i, c) = list(input().split())
	i = int(i)
	if s[i - 1] == c:
		print(abc_count)
		continue
	try:
		if s[i - 1] == 'a' and i - 1 >= 0 and (s[i] == 'b') and (s[i + 1] == 'c'):
			abc_count -= 1
		elif s[i - 1] == 'b' and i - 2 >= 0 and (s[i - 2] == 'a') and (s[i] == 'c'):
			abc_count -= 1
		elif s[i - 1] == 'c' and i - 3 >= 0 and (s[i - 2] == 'b') and (s[i - 3] == 'a'):
			abc_count -= 1
	except IndexError:
		pass
	s[i - 1] = c
	try:
		if s[i - 1] == 'a' and i - 1 >= 0 and (s[i] == 'b') and (s[i + 1] == 'c'):
			abc_count += 1
		elif s[i - 1] == 'b' and i - 2 >= 0 and (s[i - 2] == 'a') and (s[i] == 'c'):
			abc_count += 1
		elif s[i - 1] == 'c' and i - 3 >= 0 and (s[i - 2] == 'b') and (s[i - 3] == 'a'):
			abc_count += 1
	except IndexError:
		pass
	print(abc_count)


def solve():
	(n, q) = [int(x) for x in input().split()]
	a = [i for i in input()]
	count = 0
	for i in range(0, n - 2):
		if a[i] == 'a' and a[i + 1] == 'b' and (a[i + 2] == 'c'):
			count += 1
	for t in range(q):
		(ind, c) = input().split()
		ind = int(ind) - 1
		if ind > 1:
			if a[ind - 2] == 'a' and a[ind - 1] == 'b' and (a[ind] == 'c'):
				count -= 1
		if ind > 0 and ind < n - 1:
			if a[ind - 1] == 'a' and a[ind] == 'b' and (a[ind + 1] == 'c'):
				count -= 1
		if ind < n - 2:
			if a[ind] == 'a' and a[ind + 1] == 'b' and (a[ind + 2] == 'c'):
				count -= 1
		a[ind] = c
		if ind > 1:
			if a[ind - 2] == 'a' and a[ind - 1] == 'b' and (a[ind] == 'c'):
				count += 1
		if ind > 0 and ind < n - 1:
			if a[ind - 1] == 'a' and a[ind] == 'b' and (a[ind + 1] == 'c'):
				count += 1
		if ind < n - 2:
			if a[ind] == 'a' and a[ind + 1] == 'b' and (a[ind + 2] == 'c'):
				count += 1
		print(count)
solve()


(n, q) = map(int, input().split())
s = input()
l = s.count('abc')
s = list(s)
r = ['a', 'b', 'c']
for _ in range(q):
	(ind, c) = input().split()
	ind = int(ind) - 1
	if s[ind:ind + 3] == r:
		l -= 1
	elif s[ind - 1:ind + 2] == r:
		l -= 1
	elif s[ind - 2:ind + 1] == r:
		l -= 1
	s[ind] = c
	if s[ind:ind + 3] == r:
		l += 1
	elif s[ind - 1:ind + 2] == r:
		l += 1
	elif s[ind - 2:ind + 1] == r:
		l += 1
	print(l)


def problem2(n, q, string, query, indexABC):
	(pos, val) = query
	if pos in indexABC or pos - 1 in indexABC or pos - 2 in indexABC:
		if val != string[pos]:
			for p in [pos, pos - 1, pos - 2]:
				if p in indexABC:
					indexABC.remove(p)
	if val == 'a':
		if pos < n - 2 and string[pos + 1] == 'b' and (string[pos + 2] == 'c') and (pos not in indexABC):
			indexABC.add(pos)
	elif val == 'b':
		if 0 < pos < n - 1 and string[pos + 1] == 'c' and (string[pos - 1] == 'a') and (pos - 1 not in indexABC):
			indexABC.add(pos - 1)
	elif 1 < pos and string[pos - 1] == 'b' and (string[pos - 2] == 'a') and (pos - 2 not in indexABC):
		indexABC.add(pos - 2)
	string[pos] = val
	return (string, indexABC)
(n, q) = [int(num) for num in input().split(' ')]
string = list(input())
indexABC = set()
for i in range(n - 2):
	if string[i] == 'a' and string[i + 1] == 'b' and (string[i + 2] == 'c'):
		indexABC.add(i)
for _ in range(q):
	query = input().split(' ')
	query = (int(query[0]) - 1, query[1])
	(string, indexABC) = problem2(n, q, string, query, indexABC)
	print(len(indexABC))


(n, q) = map(int, input().split())
str = input()
cnt = 0
for i in range(2, n):
	if str[i - 2] + str[i - 1] + str[i] == 'abc':
		cnt += 1
str = list([i for i in str])
str.append([0] * 2)
for _ in range(q):
	(pos, ch) = input().split()
	pos = int(pos) - 1
	if str[pos] == 'a' and str[pos + 1] == 'b' and (str[pos + 2] == 'c') and (ch != str[pos]):
		cnt -= 1
	elif str[pos] == 'b' and str[pos - 1] == 'a' and (str[pos + 1] == 'c') and (ch != str[pos]):
		cnt -= 1
	elif str[pos] == 'c' and str[pos - 2] == 'a' and (str[pos - 1] == 'b') and (ch != str[pos]):
		cnt -= 1
	if str[pos] == ch:
		pass
	elif ch == 'a' and str[pos + 1] == 'b' and (str[pos + 2] == 'c'):
		cnt += 1
	elif ch == 'b' and str[pos - 1] == 'a' and (str[pos + 1] == 'c'):
		cnt += 1
	elif ch == 'c' and str[pos - 2] == 'a' and (str[pos - 1] == 'b'):
		cnt += 1
	str[pos] = ch
	print(cnt)


(n, q) = map(int, input().split())
s = input()
l = list(s)
ans = s.count('abc')
for _ in range(q):
	(idx, char) = input().split()
	idx = int(idx) - 1
	if l[idx] == char:
		print(ans)
	else:
		if idx + 2 < len(l) and l[idx] == 'a' and (l[idx + 1] == 'b') and (l[idx + 2] == 'c'):
			ans -= 1
		if idx - 1 >= 0 and idx + 1 < len(s) and (l[idx] == 'b') and (l[idx - 1] == 'a') and (l[idx + 1] == 'c'):
			ans -= 1
		if idx - 2 >= 0 and l[idx] == 'c' and (l[idx - 1] == 'b') and (l[idx - 2] == 'a'):
			ans -= 1
		l[idx] = char
		if idx + 2 < len(l) and l[idx] == 'a' and (l[idx + 1] == 'b') and (l[idx + 2] == 'c'):
			ans += 1
		if idx - 1 >= 0 and idx + 1 < len(s) and (l[idx] == 'b') and (l[idx - 1] == 'a') and (l[idx + 1] == 'c'):
			ans += 1
		if idx - 2 >= 0 and l[idx] == 'c' and (l[idx - 1] == 'b') and (l[idx - 2] == 'a'):
			ans += 1
		print(ans)


(n, q) = map(int, input().split())
s = input()
ans = s.count('abc')
s = list(s)

def check(x):
	if s[x] == 'a' and x + 2 < n:
		return s[x + 1] + s[x + 2] == 'bc'
	elif s[x] == 'b' and x > 0 and (x + 1 < n):
		return s[x - 1] + s[x + 1] == 'ac'
	elif s[x] == 'c' and x > 1:
		return s[x - 2] + s[x - 1] == 'ab'
	else:
		return False
for _ in range(q):
	(x, y) = input().split()
	x = int(x) - 1
	if check(x):
		ans -= 1
	s[x] = y
	if check(x):
		ans += 1
	print(ans)


import sys
import bisect
inp = sys.stdin.readline

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // gcd(a, b)
for _ in range(1):
	(n, q) = map(int, inp().split())
	s = 'dd' + input() + 'dd'
	ans = s.count('abc')
	s = list(s)
	for _ in range(q):
		(p, c) = input().split()
		p = int(p) + 1
		x = p - 2
		y = p + 3
		ans -= ''.join(s[x:y]).count('abc')
		s[p] = c
		ans += ''.join(s[x:y]).count('abc')
		print(ans)


(n, q) = map(int, input().split())
s = [i for i in input()]
cnt = 0
state = 0
for i in range(len(s)):
	if s[i] == 'a':
		state = 1
	elif s[i] == 'b':
		if state == 1:
			state = 2
		else:
			state = 0
	else:
		if state == 2:
			cnt += 1
		state = 0
for _ in range(q):
	(i, c) = input().split()
	i = int(i) - 1
	if s[i] == 'a':
		if i + 1 < len(s) and s[i + 1] == 'b' and (i + 2 < len(s)) and (s[i + 2] == 'c'):
			cnt -= 1
	elif s[i] == 'b':
		if i > 0 and s[i - 1] == 'a' and (i + 1 < len(s)) and (s[i + 1] == 'c'):
			cnt -= 1
	elif i - 2 >= 0 and s[i - 2] == 'a' and (s[i - 1] == 'b'):
		cnt -= 1
	s[i] = c
	if s[i] == 'a':
		if i + 1 < len(s) and s[i + 1] == 'b' and (i + 2 < len(s)) and (s[i + 2] == 'c'):
			cnt += 1
	elif s[i] == 'b':
		if i > 0 and s[i - 1] == 'a' and (i + 1 < len(s)) and (s[i + 1] == 'c'):
			cnt += 1
	elif i - 2 >= 0 and s[i - 2] == 'a' and (s[i - 1] == 'b'):
		cnt += 1
	print(cnt)


(n, q) = map(int, input().split())
s = input()
starts = set()
for i in range(len(s) - 2):
	if s[i:i + 3] == 'abc':
		starts.add(i)
s = list(s)
tochange = len(starts)
for _ in range(q):
	(i, l) = input().split()
	i = int(i)
	i -= 1
	if l != s[i]:
		if s[i] == 'a' and starts.discard(i) == i:
			tochange -= 1
		elif s[i] == 'b' and starts.discard(i - 1) == i - 1:
			tochange -= 1
		elif s[i] == 'c' and starts.discard(i - 2) == i - 2:
			tochange -= 1
		if l == 'a' and i < len(s) - 2 and (s[i + 1] == 'b') and (s[i + 2] == 'c'):
			starts.add(i)
			tochange += 1
		if l == 'b' and i < len(s) - 1 and (i > 0) and (s[i + 1] == 'c') and (s[i - 1] == 'a'):
			starts.add(i - 1)
			tochange += 1
		if l == 'c' and i > 1 and (s[i - 1] == 'b') and (s[i - 2] == 'a'):
			starts.add(i - 2)
			tochange += 1
		s[i] = l
	print(len(starts))


nq = list(map(int, input().split()))
s = input()
s = list(s)
k = 0
for i in range(len(s) - 2):
	if s[i] == 'a':
		if s[i + 1] == 'b':
			if s[i + 2] == 'c':
				k += 1
for _ in range(nq[1]):
	q = input().split()
	pos = int(q[0])
	x = q[1]
	if s[pos - 1] == 'a' and pos + 1 < len(s):
		if s[pos] == 'b' and s[pos + 1] == 'c':
			k -= 1
	if (s[pos - 1] == 'b' and pos < len(s)) and pos - 2 >= 0:
		if s[pos - 2] == 'a' and s[pos] == 'c':
			k -= 1
	if s[pos - 1] == 'c' and pos - 3 >= 0:
		if s[pos - 2] == 'b' and s[pos - 3] == 'a':
			k -= 1
	s[pos - 1] = x
	if s[pos - 1] == 'a' and pos + 1 < len(s):
		if s[pos] == 'b' and s[pos + 1] == 'c':
			k += 1
	if (s[pos - 1] == 'b' and pos < len(s)) and pos - 2 >= 0:
		if s[pos - 2] == 'a' and s[pos] == 'c':
			k += 1
	if s[pos - 1] == 'c' and pos - 3 >= 0:
		if s[pos - 2] == 'b' and s[pos - 3] == 'a':
			k += 1
	print(k)


(n, q) = map(int, input().split())
s = list(input())
vis = [0] * n
ans = 0
for i in range(n):
	if s[i] == 'a' and i + 2 < n and (s[i + 1] == 'b') and (s[i + 2] == 'c'):
		vis[i] = 1
		ans += 1
for i in range(q):
	(pos, c) = input().split()
	pos = int(pos)
	pos -= 1
	if s[pos] == 'a':
		if pos + 2 < n and s[pos + 1] == 'b' and (s[pos + 2] == 'c'):
			ans -= 1
	elif s[pos] == 'b':
		if pos + 1 < n and pos - 1 >= 0 and (s[pos + 1] == 'c') and (s[pos - 1] == 'a'):
			ans -= 1
	elif pos - 2 >= 0 and s[pos - 1] == 'b' and (s[pos - 2] == 'a'):
		ans -= 1
	if c == 'a':
		if pos + 2 < n and s[pos + 1] == 'b' and (s[pos + 2] == 'c'):
			ans += 1
	elif c == 'b':
		if pos + 1 < n and pos > 0 and (s[pos + 1] == 'c') and (s[pos - 1] == 'a'):
			ans += 1
	elif pos - 2 >= 0 and s[pos - 1] == 'b' and (s[pos - 2] == 'a'):
		ans += 1
	s[pos] = c
	print(ans)


(n, q) = map(int, input().split())
A = list(input())
s = 0
for i in range(0, n - 2):
	if A[i] == 'a' and A[i + 1] == 'b' and (A[i + 2] == 'c'):
		s += 1
for i in range(0, q):
	B = [x for x in input().split()]
	j = int(B[0]) - 1
	if B[1] != A[j]:
		if j < n - 2 and A[j] == 'a' and (A[j + 1] == 'b') and (A[j + 2] == 'c'):
			s -= 1
		elif j > 0 and j < n - 1 and (A[j - 1] == 'a') and (A[j] == 'b') and (A[j + 1] == 'c'):
			s -= 1
		elif j > 1 and A[j - 2] == 'a' and (A[j - 1] == 'b') and (A[j] == 'c'):
			s -= 1
		A[j] = B[1]
		if j < n - 2 and A[j] == 'a' and (A[j + 1] == 'b') and (A[j + 2] == 'c'):
			s += 1
		elif j > 0 and j < n - 1 and (A[j - 1] == 'a') and (A[j] == 'b') and (A[j + 1] == 'c'):
			s += 1
		elif j > 1 and A[j - 2] == 'a' and (A[j - 1] == 'b') and (A[j] == 'c'):
			s += 1
	print(s)


(n, k) = map(int, input().split())
s = list(input())
ans = 0
i = 0
while i < n - 2:
	if s[i] == 'a' and s[i + 1] == 'b' and (s[i + 2] == 'c'):
		ans += 1
		i += 2
	else:
		i += 1
for _ in range(k):
	ss = input().split()
	(ind, al) = (int(ss[0]), ss[1])
	ind -= 1
	if s[ind] == al:
		print(ans)
	else:
		for j in range(max(0, ind - 2), min(n - 2, ind + 1)):
			if s[j] == 'a' and s[j + 1] == 'b' and (s[j + 2] == 'c'):
				ans -= 1
		if al == 'a' and ind < n - 2:
			if s[ind + 1] == 'b' and s[ind + 2] == 'c':
				ans += 1
		elif al == 'b' and ind < n - 1 and (ind > 0):
			if s[ind - 1] == 'a' and s[ind + 1] == 'c':
				ans += 1
		elif ind > 1 and al == 'c':
			if s[ind - 2] == 'a' and s[ind - 1] == 'b':
				ans += 1
		s[ind] = al
		print(ans)


try:
	(N, Q) = map(int, input().split())
	S = str(input())
	count = S.count('abc')
	S = 'xx' + S + 'xx'
	S = list(S)
	for q in range(Q):
		(x, y) = map(str, input().split())
		x = int(x) + 1
		temp = S[x - 2:x + 3]
		if 'abc' in ''.join(temp):
			count -= 1
		S[x] = y
		temp = S[x - 2:x + 3]
		if 'abc' in ''.join(temp):
			count += 1
		print(count)
except:
	pass


def inp():
	return list(map(int, input().split()))
(n, q) = inp()
a = list(input())
abc = set()
for i in range(n - 2):
	if a[i] == 'a':
		if a[i + 1] == 'b':
			if a[i + 2] == 'c':
				abc.add(i)
for j in range(q):
	(i, c) = input().split()
	if n < 3:
		print(0)
		continue
	i = int(i)
	i -= 1
	a[i] = c
	if i in abc:
		if c != 'a':
			abc.remove(i)
	elif i - 1 in abc:
		if c != 'b':
			abc.remove(i - 1)
	elif i - 2 in abc:
		if c != 'c':
			abc.remove(i - 2)
	if ''.join(a[i:i + 3]) == 'abc':
		abc.add(i)
	elif ''.join(a[i - 1:i + 2]) == 'abc':
		abc.add(i - 1)
	elif ''.join(a[i - 2:i + 1]) == 'abc':
		abc.add(i - 2)
	print(len(abc))


p = input
(n, q) = map(int, p().split())
s = p()
c = s.count('abc')
v = [*s]
while q:
	(a, b) = p().split()
	a = int(a) - 1
	d = 1
	q -= 1
	while d + 3:
		if 'abc' in ''.join(v[max(a - 2, 0):a + 3]):
			c -= d
		v[a] = b
		d -= 2
	print(c)


(n, q) = map(int, input().split())
s = input()
answer = s.count('abc')
s = [i for i in s]
for _ in range(q):
	(pos, c) = input().split()
	pos = int(pos) - 1
	if s[pos] != c:
		curr_s = s[max(0, pos - 2):min(n, pos + 3)]
		curr_answer = ''.join(curr_s).count('abc')
		s[pos] = c
		new_s = s[max(0, pos - 2):min(n, pos + 3)]
		new_answer = ''.join(new_s).count('abc')
		answer += new_answer - curr_answer
	print(answer)


(n, q) = map(int, input().split())
a = list(str(input()))
a = ['x', 'x'] + a + ['x', 'x']
p1 = []
p2 = []
ans = 0
cnt = 1
for i in range(4, n + 2):
	if a[i - 1] == 'b' and a[i - 2] == 'a':
		if a[i] == 'c':
			ans += 1
for i in range(q):
	(pos, ch) = input().split()
	pos = int(pos)
	pos += 1
	if ch == a[pos]:
		print(ans)
	else:
		s1 = [a[pos - 2], a[pos - 1], a[pos]]
		s2 = [a[pos - 1], a[pos], a[pos + 1]]
		s3 = [a[pos], a[pos + 1], a[pos + 2]]
		t = ['a', 'b', 'c']
		if s1 == t or s2 == t or s3 == t:
			ans -= 1
		a[pos] = ch
		s1 = [a[pos - 2], a[pos - 1], a[pos]]
		s2 = [a[pos - 1], a[pos], a[pos + 1]]
		s3 = [a[pos], a[pos + 1], a[pos + 2]]
		if s1 == t or s2 == t or s3 == t:
			ans += 1
		print(ans)


(n, q) = input().split()
n = int(n)
q = int(q)
s = list(input())
base = 0
for i in range(n - 2):
	if s[i] == 'a' and s[i + 1] == 'b' and (s[i + 2] == 'c'):
		base += 1

def makes_abc(x, i, s):
	if x == 'a':
		if i < len(s) - 2:
			if s[i + 1] == 'b' and s[i + 2] == 'c':
				return True
	if x == 'b':
		if i > 0 and i < len(s) - 1:
			if s[i - 1] == 'a' and s[i + 1] == 'c':
				return True
	if x == 'c':
		if i > 1:
			if s[i - 2] == 'a' and s[i - 1] == 'b':
				return True
	return False
while q > 0:
	q -= 1
	(i, x) = input().split()
	i = int(i)
	i = i - 1
	if s[i] != x:
		if makes_abc(s[i], i, s):
			base -= 1
		if makes_abc(x, i, s):
			base += 1
		s[i] = x
	print('  ', base)


def check_a(l, i):
	if i >= len(l) - 2:
		return False
	else:
		if l[i + 1] == 'b' and l[i + 2] == 'c':
			return True
		return False

def check_b(l, i):
	if i == 0 or i == len(l) - 1:
		return False
	else:
		if l[i - 1] == 'a' and l[i + 1] == 'c':
			return True
		return False

def check_c(l, i):
	if i < 2:
		return False
	else:
		if l[i - 1] == 'b' and l[i - 2] == 'a':
			return True
		return False

def fun(l, idx):
	if l[idx] == 'a':
		return check_a(l, idx)
	elif l[idx] == 'b':
		return check_b(l, idx)
	else:
		return check_c(l, idx)
(n, q) = map(int, input().split())
s = input().rstrip()
l = [x for x in s]
count = i = 0
while i < n - 2:
	if l[i] == 'a' and l[i + 1] == 'b' and (l[i + 2] == 'c'):
		count += 1
		i += 3
	else:
		i += 1
for z in range(q):
	(idx, c) = map(str, input().split())
	idx = int(idx) - 1
	if c == l[idx]:
		print(count)
	else:
		ans = fun(l, idx)
		if ans:
			count -= 1
		l[idx] = c
		ans2 = fun(l, idx)
		if ans2:
			count += 1
		print(count)


def check(s, i, n):
	if s[i] == 'a' and i + 2 < n:
		if s[i + 1] == 'b' and s[i + 2] == 'c':
			return True
		return False
	if s[i] == 'b' and i > 0 and (i < n - 1):
		if s[i - 1] == 'a' and s[i + 1] == 'c':
			return True
		return False
	if s[i] == 'c' and i > 1:
		if s[i - 2] == 'a' and s[i - 1] == 'b':
			return True
	return False
(n, q) = map(int, input().split())
s = list(input())
ans = 0
for i in range(n - 2):
	if s[i] == 'a' and s[i + 1] == 'b' and (s[i + 2] == 'c'):
		ans += 1
for _ in range(q):
	(p, v) = map(str, input().split())
	p = int(p) - 1
	ans -= int(check(s, p, n))
	s[p] = v
	ans += int(check(s, p, n))
	print(ans)


(q, n) = map(int, input().split())
s = '11' + input() + '11'
counter = s.count('abc')
s = list(s)
for i in range(n):
	(num, a) = input().split()
	num = int(num)
	num += 1
	st = s[num - 2] + s[num - 1] + s[num] + s[num + 1] + s[num + 2]
	st_new = s[num - 2] + s[num - 1] + a + s[num + 1] + s[num + 2]
	counter += st_new.count('abc') - st.count('abc')
	s[num] = a
	print(counter)


(N, Q) = map(int, input().split())
S = list(input())
p1 = count = 0
while p1 < N - 2:
	if S[p1:p1 + 3] == ['a', 'b', 'c']:
		count += 1
		p1 += 3
	else:
		p1 += 1
for i in range(Q):
	(ind, char) = input().split()
	ind = int(ind) - 1
	if S[ind] == 'a':
		if S[ind:min(ind + 3, N)] == ['a', 'b', 'c']:
			count -= 1
	if S[ind] == 'b':
		if S[max(0, ind - 1):min(ind + 2, N)] == ['a', 'b', 'c']:
			count -= 1
	if S[ind] == 'c':
		if S[max(0, ind - 2):ind + 1] == ['a', 'b', 'c']:
			count -= 1
	S[ind] = char
	if S[ind] == 'a':
		if S[ind:min(ind + 3, N)] == ['a', 'b', 'c']:
			count += 1
	if S[ind] == 'b':
		if S[max(0, ind - 1):min(ind + 2, N)] == ['a', 'b', 'c']:
			count += 1
	if S[ind] == 'c':
		if S[max(0, ind - 2):ind + 1] == ['a', 'b', 'c']:
			count += 1
	print(count)


(n, q) = map(int, input().split())
s = input()
ans = s.count('abc')
s = [i for i in s]
for _ in range(q):
	(i, c) = input().split()
	if 'abc' in ''.join(s[max(0, int(i) - 3):int(i) + 2]):
		ans -= 1
	s[int(i) - 1] = c
	if 'abc' in ''.join(s[max(0, int(i) - 3):int(i) + 2]):
		ans += 1
	print(ans)


(n, q) = input().split()
s = input()
ans = s.count('abc')
s = [i for i in s]
for i in range(int(q)):
	(id_num, val) = input().split()
	ans -= [0, 1]['abc' in ''.join(s[max(0, int(id_num) - 3):int(id_num) + 2])]
	s[int(id_num) - 1] = val
	ans += [0, 1]['abc' in ''.join(s[max(0, int(id_num) - 3):int(id_num) + 2])]
	print(ans)


(a, q) = map(int, input().split())
s = input()
ans = s.count('abc')
s = list(s)
for idd in range(q):
	(pos, c) = input().split()
	i = int(pos) - 1
	pehle = 0
	if i - 2 >= 0:
		if s[i - 2] == 'a' and s[i - 1] == 'b' and (s[i] == 'c'):
			pehle += 1
	if i - 1 >= 0 and i + 1 < len(s):
		if s[i - 1] == 'a' and s[i] == 'b' and (s[i + 1] == 'c'):
			pehle += 1
	if i + 2 < len(s):
		if s[i] == 'a' and s[i + 1] == 'b' and (s[i + 2] == 'c'):
			pehle += 1
	s[i] = c
	new = 0
	if i - 2 >= 0:
		if s[i - 2] == 'a' and s[i - 1] == 'b' and (s[i] == 'c'):
			new += 1
	if i - 1 >= 0 and i + 1 < len(s):
		if s[i - 1] == 'a' and s[i] == 'b' and (s[i + 1] == 'c'):
			new += 1
	if i + 2 < len(s):
		if s[i] == 'a' and s[i + 1] == 'b' and (s[i + 2] == 'c'):
			new += 1
	ans += new - pehle
	print(ans)


inputs = input().split()
(numLets, numQ) = (int(inputs[0]), int(inputs[1]))
numAbc = 0
lets = input().split()
(i, posSet) = (0, set())
lets = list(lets[0])
while i < len(lets) - 2:
	if lets[i] == 'a' and lets[i + 1] == 'b' and (lets[i + 2] == 'c'):
		posSet.add(i)
		i += 3
		numAbc += 1
	else:
		i += 1
for _ in range(numQ):
	inputs = input().split()
	(pos, let) = (int(inputs[0]), inputs[1])
	if lets[pos - 1] != let:
		if pos - 1 - (ord(lets[pos - 1]) - ord('a')) in posSet:
			posSet.remove(pos - 1 - (ord(lets[pos - 1]) - ord('a')))
		lets[pos - 1] = let
		start = max(0, pos - 3)
		end = min(pos, len(lets) - 2)
		for i in range(start, end):
			if lets[i] == 'a' and lets[i + 1] == 'b' and (lets[i + 2] == 'c'):
				posSet.add(i)
				numAbc += 1
				break
	print(len(posSet))


(n, q) = map(int, input().split())
s = input()
m = s.count('abc')
s = list(s)
for _ in range(q):
	(i, c) = input().split()
	i = int(i) - 1
	if s[i] == c:
		pass
	else:
		x0 = s[i] + s[i + 1] + s[i + 2] if i < n - 2 else ''
		y0 = s[i - 1] + s[i] + s[i + 1] if i > 0 and i < n - 1 else ''
		z0 = s[i - 2] + s[i - 1] + s[i] if i > 1 else ''
		num1 = (x0 == 'abc') + (y0 == 'abc') + (z0 == 'abc')
		s[i] = c
		x = s[i] + s[i + 1] + s[i + 2] if i < n - 2 else ''
		y = s[i - 1] + s[i] + s[i + 1] if i > 0 and i < n - 1 else ''
		z = s[i - 2] + s[i - 1] + s[i] if i > 1 else ''
		num2 = (x == 'abc') + (y == 'abc') + (z == 'abc')
		m += num2 - num1
	print(m)


(n, q) = map(int, input().split())
x = input()
s = []
for i in x:
	s.append(i)
v = [0] * n
c = 0
for i in range(n - 2):
	if s[i:i + 3] == ['a', 'b', 'c']:
		v[i] = 1
		c += 1
for i in range(q):
	(p, ch) = input().split()
	p = int(p)
	j = p - 1
	r = 0
	while j >= 0 and r < 3:
		if v[j] != 0:
			c -= 1
			v[j] = 0
			break
		j -= 1
		r += 1
	if ch == 'a':
		s[p - 1] = ch
		if p <= n - 2:
			if s[p - 1:p + 2] == ['a', 'b', 'c']:
				v[p - 1] = 1
				c += 1
		print(c)
	elif ch == 'b':
		s[p - 1] = ch
		if p <= n - 1 and p > 1:
			if s[p - 2:p + 1] == ['a', 'b', 'c']:
				v[p - 2] = 1
				c += 1
		print(c)
	else:
		s[p - 1] = ch
		if p <= n and p > 2:
			if s[p - 3:p] == ['a', 'b', 'c']:
				v[p - 3] = 1
				c += 1
		print(c)


(n, q) = map(int, input().split())
s = input()
ans = s.count('abc')
s = list(s)
for i in range(q):
	(pos, ch) = map(str, input().split())
	pos = int(pos)
	if s[pos - 1] == ch:
		print(ans)
	else:
		if pos - 2 > 0 and s[pos - 3] + s[pos - 2] + s[pos - 1] == 'abc':
			ans -= 1
		elif pos - 1 > 0 and pos < n and (s[pos - 2] + s[pos - 1] + s[pos] == 'abc'):
			ans -= 1
		elif pos + 1 < n and s[pos - 1] + s[pos] + s[pos + 1] == 'abc':
			ans -= 1
		if ch == 'c':
			if pos > 2 and s[pos - 2] == 'b' and (s[pos - 3] == 'a'):
				ans += 1
		elif ch == 'b':
			if pos > 1 and pos < n and (s[pos - 2] == 'a') and (s[pos] == 'c'):
				ans += 1
		elif pos < n - 1 and s[pos] == 'b' and (s[pos + 1] == 'c'):
			ans += 1
		print(ans)
		s[pos - 1] = ch


(n, k) = map(int, input().split())
s = input()
c = s.count('abc')
s = list(s)
while k:
	(x, y) = input().split(' ')
	x = int(x) - 1
	if y != s[x]:
		for i in range(3):
			if ''.join(s[x - i:x - i + 3]) == 'abc':
				c -= 1
		s[x] = y
		for i in range(3):
			if ''.join(s[x - i:x - i + 3]) == 'abc':
				c += 1
	k -= 1
	print(c)


import sys
from math import sqrt, gcd
from collections import deque
sys.setrecursionlimit(10 ** 8)
I = lambda : int(input())
S = lambda : input().strip()
M = lambda : map(int, input().strip().split())
L = lambda : list(map(int, input().strip().split()))
mod = 1000000007
(n, q) = M()
s = list(S())
c = 0
for i in range(n - 2):
	if s[i] == 'a' and s[i + 1] == 'b' and (s[i + 2] == 'c'):
		c += 1
for i in range(q):
	(i, ch) = input().split()
	i = int(i) - 1
	if s[i] == ch:
		print(c)
	else:
		a = 0
		for j in range(max(0, i - 2), min(i + 1, n - 2)):
			if s[j] == 'a' and s[j + 1] == 'b' and (s[j + 2] == 'c'):
				a += 1
		s[i] = ch
		for j in range(max(0, i - 2), min(i + 1, n - 2)):
			if s[j] == 'a' and s[j + 1] == 'b' and (s[j + 2] == 'c'):
				a -= 1
		c -= a
		print(c)


base = ['a', 'b', 'c']

def check(pos):
	if arr[pos - 2:pos + 1] == base or arr[pos - 1:pos + 2] == base or arr[pos:pos + 3] == base:
		return 1
	return 0
(n, q) = list(map(int, input().split()))
string = input()
arr = list(string)
(ans, cnt) = ([], 0)
for i in range(n):
	if arr[i:i + 3] == ['a', 'b', 'c']:
		cnt += 1
for t in range(q):
	(idx, val) = list(map(str, input().split()))
	idx = int(idx) - 1
	initial = check(idx)
	arr[idx] = val
	final = check(idx)
	cnt += final - initial
	print(cnt)


(n, q) = map(int, input().split())
s = input()
ans = s.count('abc')
l = list(s)
for j in range(q):
	(i, c) = map(str, input().split())
	ind = int(i) - 1
	if l[ind:ind + 3] == ['a', 'b', 'c']:
		ans -= 1
	elif l[ind - 1:ind + 2] == ['a', 'b', 'c']:
		ans -= 1
	elif l[ind - 2:ind + 1] == ['a', 'b', 'c']:
		ans -= 1
	l[int(i) - 1] = c
	if l[ind:ind + 3] == ['a', 'b', 'c']:
		ans += 1
	elif l[ind - 1:ind + 2] == ['a', 'b', 'c']:
		ans += 1
	elif l[ind - 2:ind + 1] == ['a', 'b', 'c']:
		ans += 1
	print(ans)


(n, q) = map(int, input().split())
s = list(input())
a = 0
A = set()
B = set()
C = set()
for i in range(1, n - 1):
	if s[i] == 'b':
		if s[i - 1] == 'a' and s[i + 1] == 'c':
			a += 1
for _ in range(q):
	(x, y) = input().split()
	x = int(x)
	aa = 0
	b = 0
	c = 0
	try:
		aa = -int(s[x - 3:x] == ['a', 'b', 'c'])
	except IndexError:
		pass
	try:
		b = -int(s[x - 2:x + 1] == ['a', 'b', 'c'])
	except IndexError:
		pass
	try:
		c = -int(s[x - 1:x + 2] == ['a', 'b', 'c'])
	except IndexError:
		pass
	s[x - 1] = y
	try:
		aa += int(s[x - 3:x] == ['a', 'b', 'c'])
	except IndexError:
		pass
	try:
		b += int(s[x - 2:x + 1] == ['a', 'b', 'c'])
	except IndexError:
		pass
	try:
		c += int(s[x - 1:x + 2] == ['a', 'b', 'c'])
	except IndexError:
		pass
	a += aa + b + c
	print(a)


def solve():
	(n, m) = map(int, input().split(' '))
	a = list(input())
	num = 0
	for i in range(n - 2):
		if ''.join(a[i:i + 3]) == 'abc':
			num += 1
	for i in range(m):
		(index, ch) = input().split(' ')
		index = int(index) - 1
		for j in range(max(0, index - 2), index + 1):
			if ''.join(a[j:j + 3]) == 'abc':
				num -= 1
		a[index] = ch
		for j in range(max(0, index - 2), index + 1):
			if ''.join(a[j:j + 3]) == 'abc':
				num += 1
		print(num)
solve()


def checkdelta(s, pos, c, n):
	before_count = 0
	for i in range(pos - 2, pos + 1):
		if i >= 0 and i < n - 2:
			if s[i] == 'a' and s[i + 1] == 'b' and (s[i + 2] == 'c'):
				before_count += 1
	after_count = 0
	s[pos] = c
	for i in range(pos - 2, pos + 1):
		if i >= 0 and i < n - 2:
			if s[i] == 'a' and s[i + 1] == 'b' and (s[i + 2] == 'c'):
				after_count += 1
	return (before_count, after_count)
input_string = input()
input_string = input_string.split()
n = int(input_string[0])
q = int(input_string[1])
s = list(input())
abc_count = 0
for i in range(0, n - 2):
	if s[i] == 'a' and s[i + 1] == 'b' and (s[i + 2] == 'c'):
		abc_count += 1
for _ in range(0, q):
	input_string = input()
	input_string = input_string.split()
	pos = int(input_string[0]) - 1
	c = input_string[1]
	(before_count, after_count) = checkdelta(s, pos, c, n)
	abc_count = abc_count + after_count - before_count
	print(abc_count)


def re_cnt(i):
	return 0 <= i and i + 2 < n and (s[i] == 'a') and (s[i + 1] == 'b') and (s[i + 2] == 'c')
(n, q) = map(int, input().split())
s = input()
cnt = s.count('abc')
s = list(s)
for _ in range(q):
	inp = input().split()
	pos = int(inp[0]) - 1
	cnt -= re_cnt(pos - 2)
	cnt -= re_cnt(pos - 1)
	cnt -= re_cnt(pos)
	s[pos] = inp[1]
	cnt += re_cnt(pos - 2)
	cnt += re_cnt(pos - 1)
	cnt += re_cnt(pos)
	print(cnt)


import sys
from collections import deque
import heapq
import bisect
import copy
MOD = 1000000007
NO = lambda : print('NO')
YES = lambda : print('YES')
_1 = lambda : print(-1)
ari = lambda : [int(_) for _ in input().split()]
cin = lambda : int(input())
cis = lambda : input()
show = lambda x: print(x)
fast = lambda : sys.stdin.readline()
test_case = 1
sys.setrecursionlimit(10 ** 6)

def ans():
	(n, query) = ari()
	word = list(cis())
	totalcount = 0
	for i in range(n):
		if word[i:i + 3] == ['a', 'b', 'c']:
			totalcount += 1
	for q in range(query):
		(index, w) = cis().split()
		index = int(index) - 1
		for _ in range(max(0, index - 2), index + 1):
			if word[_:_ + 3] == ['a', 'b', 'c']:
				totalcount -= 1
		word[index] = w
		for _ in range(max(0, index - 2), index + 1):
			if word[_:_ + 3] == ['a', 'b', 'c']:
				totalcount += 1
		print(totalcount)
for _ in range(test_case):
	ans()


(n, q) = map(int, input().split())
s = list(input())
cnt = 0
for i in range(n - 2):
	if ''.join(s[i:i + 3]) == 'abc':
		cnt += 1
for i in range(q):
	(index, c) = input().split()
	index = int(index) - 1
	if s[index] == c:
		print(cnt)
	else:
		for i in range(max(0, index - 2), index + 1):
			if ''.join(s[i:i + 3]) == 'abc':
				cnt -= 1
		s[index] = c
		for j in range(max(0, index - 2), index + 1):
			if ''.join(s[j:j + 3]) == 'abc':
				cnt += 1
		print(cnt)


(n, x) = map(int, input().split())
s = list(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
for _ in range(x):
	(ind, elem) = input().split()
	ind = int(ind) - 1
	if ind >= 2 and s[ind - 2] + s[ind - 1] + s[ind] == 'abc':
		r -= 1
	elif 1 <= ind <= n - 2 and s[ind - 1] + s[ind] + s[ind + 1] == 'abc':
		r -= 1
	elif ind <= n - 3 and s[ind] + s[ind + 1] + s[ind + 2] == 'abc':
		r -= 1
	s[ind] = elem
	if ind >= 2 and s[ind - 2] + s[ind - 1] + s[ind] == 'abc':
		r += 1
	elif 1 <= ind <= n - 2 and s[ind - 1] + s[ind] + s[ind + 1] == 'abc':
		r += 1
	elif ind <= n - 3 and s[ind] + s[ind + 1] + s[ind + 2] == 'abc':
		r += 1
	print(r)


(n, q) = map(int, input().split())
s = list(input())

def count(s):
	ans = 0
	for i in range(len(s) - 2):
		if s[i:i + 3] == ['a', 'b', 'c']:
			ans += 1
	return ans
ori = count(s)
for _ in range(q):
	(i, c) = input().split()
	i = int(i)
	l = 0 if i < 3 else i - 3
	r = n if i > n - 2 else i + 2
	prev = count(s[l:r])
	s[i - 1] = c
	now = count(s[l:r])
	ori -= prev - now
	print(ori)


def check(arr, ind):
	if ind < len(arr) - 2:
		if arr[ind] + arr[ind + 1] + arr[ind + 2] == 'abc':
			return 1
	if 0 < ind < len(arr) - 1:
		if arr[ind - 1] + arr[ind] + arr[ind + 1] == 'abc':
			return 1
	if ind > 1:
		if arr[ind - 2] + arr[ind - 1] + arr[ind] == 'abc':
			return 1
	return 0
(N, Q) = map(int, input().split())
S = input()
ts = S.count('abc')
arr = list(S)
for q in range(Q):
	(a, b) = map(str, input().split())
	if arr[int(a) - 1] == b:
		print(ts)
	else:
		ts -= check(arr, int(a) - 1)
		arr[int(a) - 1] = b
		ts += check(arr, int(a) - 1)
		print(ts)


def solve():
	(length, queries) = map(int, input().split())
	string = list(input())
	count = 0
	for i in range(length - 2):
		if ''.join(string[i:i + 3]) == 'abc':
			count += 1
	for i in range(queries):
		(idx, char) = input().split()
		idx = int(idx) - 1
		for j in range(max(0, idx - 2), idx + 1):
			if ''.join(string[j:j + 3]) == 'abc':
				count -= 1
		string[idx] = char
		for j in range(max(0, idx - 2), idx + 1):
			if ''.join(string[j:j + 3]) == 'abc':
				count += 1
		print(count)
solve()


(n, q) = [int(s) for s in input().split()]
s = input().strip()
a = [s[i] for i in range(n)]
abc_index = set()
for i in range(n - 2):
	if a[i] == 'a' and a[i + 1] == 'b' and (a[i + 2] == 'c'):
		abc_index.add(i)
for qq in range(q):
	(pos, c) = [s for s in input().split()]
	pos = int(pos) - 1
	a[pos] = c
	for i in range(max(0, pos - 2), min(pos + 1, n - 2)):
		if a[i] == 'a' and a[i + 1] == 'b' and (a[i + 2] == 'c'):
			abc_index.add(i)
		else:
			abc_index.discard(i)
	print(len(abc_index))


def solve():
	(n, q) = map(int, input().split(' '))
	s = list(input())
	count = 0
	for i in range(n - 2):
		if ''.join(s[i:i + 3]) == 'abc':
			count += 1
	for i in range(q):
		(i, ch) = input().split(' ')
		i = int(i) - 1
		for j in range(max(0, i - 2), i + 1):
			if ''.join(s[j:j + 3]) == 'abc':
				count -= 1
		s[i] = ch
		for j in range(max(0, i - 2), i + 1):
			if ''.join(s[j:j + 3]) == 'abc':
				count += 1
		print(count)
solve()


(n, q) = map(int, input().split())
mas = input()
mas = list(mas)
count = 0
abc = set()
if n > 3:
	for i in range(n - 2):
		if mas[i] == 'a' and mas[i + 1] == 'b' and (mas[i + 2] == 'c'):
			count += 1
			abc.add(i)
for j in range(q):
	(pos, c) = map(str, input().split())
	pos = int(pos)
	pos -= 1
	mas[pos] = c
	if n < 3:
		print(0)
	else:
		temp = 0
		for i in range(pos - 2, pos + 1):
			if i >= 0 and i < n - 2:
				if mas[i] == 'a' and mas[i + 1] == 'b' and (mas[i + 2] == 'c'):
					if i not in abc:
						abc.add(i)
						temp += 1
				elif i in abc:
					temp -= 1
					abc.discard(i)
		count += temp
		print(count)


(n, q) = map(int, input().split())
s = input()
z = s.count('abc')
s = list(s)
for _ in range(q):
	t = input().split()
	(i, c) = (int(t[0]) - 1, t[1])
	for j in range(max(0, i - 2), i + 1):
		if s[j:j + 3] == ['a', 'b', 'c']:
			z -= 1
	s[i] = c
	for j in range(max(0, i - 2), i + 1):
		if s[j:j + 3] == ['a', 'b', 'c']:
			z += 1
	print(z)


(n, q) = map(int, input().split())
s = str(input())
count = s.count('abc')
s = list(s)
while q > 0:
	(p, d) = input().split()
	p = int(p) - 1
	for i in range(max(0, p - 2), p + 1):
		if ''.join(s[i:i + 3]) == 'abc':
			count -= 1
	s[p] = d
	for j in range(max(0, p - 2), p + 1):
		if ''.join(s[j:j + 3]) == 'abc':
			count += 1
	print(count)
	q -= 1


import sys, os, io
import math
import bisect
(n, q) = [int(i) for i in input().split()]
s = list(input())
pre = 0
for i in range(n - 2):
	if ''.join(s[i:i + 3]) == 'abc':
		pre += 1
for i in range(q):
	(pos, c) = input().split()
	pos = int(pos)
	pos -= 1
	for k in range(max(0, pos - 2), pos + 1):
		if ''.join(s[k:k + 3]) == 'abc':
			pre -= 1
	s[pos] = c
	for k in range(max(0, pos - 2), pos + 1):
		if ''.join(s[k:k + 3]) == 'abc':
			pre += 1
	print(pre)