Vasya wrote down two strings s of length n and t of length m consisting of small English letters 'a' and 'b'. What is more, he knows that string t has a form "abab...", namely there are letters 'a' on odd positions and letters 'b' on even positions.

Suddenly in the morning, Vasya found that somebody spoiled his string. Some letters of the string s were replaced by character '?'.

Let's call a sequence of positions i, i + 1, ..., i + m - 1 as occurrence of string t in s, if 1 ≤ i ≤ n - m + 1 and t_1 = s_{i}, t_2 = s_{i} + 1, ..., t_{m} = s_{i} + m - 1.

The boy defines the beauty of the string s as maximum number of disjoint occurrences of string t in s. Vasya can replace some letters '?' with 'a' or 'b' (letters on different positions can be replaced with different letter). Vasya wants to make some replacements in such a way that beauty of string s is maximum possible. From all such options, he wants to choose one with the minimum number of replacements. Find the number of replacements he should make.


-----Input-----

The first line contains a single integer n (1 ≤ n ≤ 10^5) — the length of s.

The second line contains the string s of length n. It contains small English letters 'a', 'b' and characters '?' only.

The third line contains a single integer m (1 ≤ m ≤ 10^5) — the length of t. The string t contains letters 'a' on odd positions and 'b' on even positions.


-----Output-----

Print the only integer — the minimum number of replacements Vasya has to perform to make the beauty of string s the maximum possible.


-----Examples-----
Input
5
bb?a?
1

Output
2

Input
9
ab??ab???
3

Output
2



-----Note-----

In the first sample string t has a form 'a'. The only optimal option is to replace all characters '?' by 'a'.

In the second sample using two replacements we can make string equal to "aba?aba??". It is impossible to get more than two occurrences.

Source: codeforces | Difficulty: HARD
Tags: String algorithms

Dynamic programming

Data structures


Solutions:
match = 0
nonmatch = 0
count = 0

def calc_match(s, t, p):
	global match
	global nonmatch
	global count
	if p == len(s) - len(t):
		return
	if p + len(t) < len(s):
		if s[p + len(t)] == '?':
			count -= 1
		elif s[p + len(t)] == t[-1]:
			match -= 1
		else:
			nonmatch -= 1
	(match, nonmatch) = (nonmatch, match)
	if p + len(t) < len(s):
		if s[p] == '?':
			count += 1
		elif s[p] == 'a':
			match += 1
		else:
			nonmatch += 1

def init_match(s, t):
	global match
	global nonmatch
	global count
	p = len(s) - len(t)
	for i in range(len(t)):
		if s[p + i] == '?':
			count += 1
		elif s[p + i] == t[i]:
			match += 1
		else:
			nonmatch += 1
n = int(input())
s = input()
m = int(input())
t = ''
for i in range(m):
	if i % 2 == 0:
		t = t + 'a'
	else:
		t = t + 'b'
init_match(s, t)
dp = []
for i in range(n + 3):
	dp.append((0, 0))
p = n - m
while p >= 0:
	calc_match(s, t, p)
	if nonmatch == 0:
		if dp[p + 1][0] == dp[p + m][0] + 1:
			dp[p] = (dp[p + 1][0], min(dp[p + 1][1], dp[p + m][1] + count))
		elif dp[p + 1][0] > dp[p + m][0] + 1:
			dp[p] = dp[p + 1]
		else:
			dp[p] = (dp[p + m][0] + 1, dp[p + m][1] + count)
	else:
		dp[p] = dp[p + 1]
	p -= 1
print(dp[0][1])


n = int(input())
s = input()
m = int(input())
a = [0] * (n + 2)
b = [0] * (n + 2)
q = [0] * (n + 1)
dp = [(0, 0)] * (n + 2)
for i in range(0, n):
	b[i] = b[i - 2] + (s[i] == 'b')
	a[i] = a[i - 2] + (s[i] == 'a')
	q[i] = q[i - 1] + (s[i] == '?')
for i in range(n - m, -1, -1):
	dp[i] = dp[i + 1]
	i_b = 1 if m % 2 == 1 else 2
	i_a = 1 if m % 2 == 0 else 2
	if not (b[i + m - i_b] - b[i - 2] or a[i + m - i_a] - a[i - 1]):
		(t, r) = dp[i + m]
		dp[i] = min((t - 1, r + q[i + m - 1] - q[i - 1]), dp[i])
print(dp[0][1])