#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
pair<int, int> d[100005];
int f[3][100005], n, m, b[100005];
char a[100005];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  cin >> m;
  for (int i = 1; i <= n; i++) {
    if (a[i] == '?')
      b[i] = b[i - 1] + 1;
    else
      b[i] = b[i - 1];
    if (a[i] != 'a') f[1][i] = f[0][i - 1] + 1;
    if (a[i] != 'b') f[0][i] = f[1][i - 1] + 1;
    if (f[!(m & 1)][i] >= m)
      d[i] = {d[i - m].first + 1, -(b[i] - b[i - m] - d[i - m].second)};
    d[i] = max(d[i - 1], d[i]);
  }
  cout << -d[n].second;
}
