Problem: Problem E Black or White

Here lies a row of a number of bricks each painted either black or white. With a single stroke of your brush, you can overpaint a part of the row of bricks at once with either black or white paint. Using white paint, all the black bricks in the painted part become white while originally white bricks remain white; with black paint, white bricks become black and black ones remain black. The number of bricks painted in one stroke, however, is limited because your brush cannot hold too much paint at a time. For each brush stroke, you can paint any part of the row with any number of bricks up to the limit.

In the first case of the sample input, the initial colors of four bricks are black, white, white, and black. You can repaint them to white, black, black, and white with two strokes: the first stroke paints all four bricks white and the second stroke paints two bricks in the middle black.

Your task is to calculate the minimum number of brush strokes needed to change the brick colors as specified. Never mind the cost of the paints.

Input

The input consists of a single test case formatted as follows.



$n$ $k$
$s$
$t$


The first line contains two integers $n$ and $k$ ($1 \leq k \leq n \leq 500 000$). $n$ is the number of bricks in the row and $k$ is the maximum number of bricks painted in a single stroke. The second line contains a string $s$ of $n$ characters, which indicates the initial colors of the bricks. The third line contains another string $t$ of $n$ characters, which indicates the desired colors of the bricks. All the characters in both s and t are either B or W meaning black and white, respectively.

Output

Output the minimum number of brush strokes required to repaint the bricks into the desired colors.

Sample Input 1


4 4
BWWB
WBBW


Sample Output 1


2


Sample Input 2


4 3
BWWB
WBBW


Sample Output 2


3


Sample Input 3


4 3
BWWW
BWWW


Sample Output 3


0


Sample Input 4


7 1
BBWBWBW
WBBWWBB


Sample Output 4


4






Example

Input

4 4
BWWB
WBBW


Output

2

Solution (in CPP):

Solution:
#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 5, inf = 1e9 + 7;

int dp[N], n, k, val[N];
char s[N], t[N];

int main() {
  scanf("%d %d %s %s", &n, &k, s+1, t+1);
  t[0] = 0;
  // genap, ganjil
  deque<int> d1, d2;
  int val1 = 0, val2 = 0;
  int cnt = 0;
  d1.push_back(0);
  dp[0] = 0;
  for (int i = 1; i <= n; ++i) {
    dp[i] = inf;
    cnt += (t[i] != t[i-1]);
    if (t[i] != t[i-1] && i > 1) {
      if (cnt & 1)
        val2++;
      else
        val1++;
    }
    while (d1.size() > 0 && d1.front() < i-k) d1.pop_front();
    while (d2.size() > 0 && d2.front() < i-k) d2.pop_front();
    if (d1.size() > 0)
      dp[i] = min(dp[i], val[d1.front()]+val1+1);
    // cerr << dp[i] << endl;
    if (d2.size() > 0)
      dp[i] = min(dp[i], val[d2.front()]+val2+1);
    // cerr << dp[i] << endl;
    if (t[i] == s[i])
      dp[i] = min(dp[i], dp[i-1]);
    bool pilih1 = ((cnt & 1) && t[i] == t[i+1]) || (((cnt & 1) == 0) && t[i] != t[i+1]);
    // cerr << i << " " << dp[i] << " " << pilih1 << " " << cnt  << " " << val1 << " " << val2 << endl;
    if (pilih1) {
      val[i] = dp[i] - val1;
      while (d1.size() > 0) {
        if (val[d1.back()] >= val[i])
          d1.pop_back();
        else
          break;
      }
      d1.push_back(i);
    }
    else {
      val[i] = dp[i] - val2;
      while (d2.size() > 0) {
        if (val[d2.back()] >= val[i])
          d2.pop_back();
        else
          break;
      }
      d2.push_back(i);
    }
  }
  printf("%d\n", dp[n]);
  return 0;
}