#include <bits/stdc++.h>
using namespace std;
int n, m, dp[100005][2], ct[100005][5][2];
char ch[100005];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> ch >> m;
  for (int i = 1; i <= n; i++) {
    int id = i % 2;
    char tp = ch[i - 1];
    for (int j = 0; j < 3; j++)
      for (int k = 0; k < 2; k++) ct[i][j][k] = ct[i - 1][j][k];
    if (tp == 'a')
      ct[i][0][id]++;
    else if (tp == 'b')
      ct[i][1][id]++;
    else if (tp == '?')
      ct[i][2][id]++;
  }
  for (int i = m; i <= n; i++) {
    dp[i][0] = dp[i - 1][0];
    dp[i][1] = dp[i - 1][1];
    int val = 0, cost = 0;
    int sta = i - m + 1;
    int ae = ct[i][0][0] - ct[i - m][0][0];
    int ao = ct[i][0][1] - ct[i - m][0][1];
    int be = ct[i][1][0] - ct[i - m][1][0];
    int bo = ct[i][1][1] - ct[i - m][1][1];
    if (sta % 2) {
      if ((ae == 0) && (bo == 0)) {
        val = dp[i - m][0] + 1;
        cost = dp[i - m][1] + (m - ao - be);
        if ((val > dp[i][0]) || ((val == dp[i][0]) && (cost < dp[i][1]))) {
          dp[i][0] = val;
          dp[i][1] = cost;
        }
      }
    } else if ((ao == 0) && (be == 0)) {
      val = dp[i - m][0] + 1;
      cost = dp[i - m][1] + (m - ae - bo);
      if ((val > dp[i][0]) || ((val == dp[i][0]) && (cost < dp[i][1]))) {
        dp[i][0] = val;
        dp[i][1] = cost;
      }
    }
  }
  cout << dp[n][1] << endl;
  return 0;
}
