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 <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 500010


int main(){
  int n,k,sum;
  string s,t;

  int left[SIZE] = {}, right[SIZE] = {};
  
  cin >> n >> k >> s >> t;

  for(int i=0;i<n;i++){
    if(i == 0 || t[i-1] != t[i]) left[i]++;
    if(i == n-1 || t[i] != t[i+1]) right[i]++;
  }

  for(int i=0;i<n;i++) right[i+1] += right[i];
  for(int i=n;i>0;i--) left[i-1] += left[i];
  sum = left[0];
  
  priority_queue<pair<int,int> > pq0, pq1;
  int sameDP = 0;
  pq0.push({-INF, INF});
  pq1.push({-INF, INF});
  pq0.push({0, -1});
  
  for(int i=0;i<n;i++){
    while(pq0.size() && pq0.top().second < i - k){
      pq0.pop();
    }
    while(pq1.size() && pq1.top().second < i - k){
      pq1.pop();
    }
    
    if(t[i] != s[i]) sameDP = INF;
    
    int p0 = -1 * pq0.top().first;
    int p1 = -1 * pq1.top().first;
    int l0 = pq0.top().second;
    int l1 = pq1.top().second;
    int calc0, calc1;

    if(l0 == -1 || l0 == INF)
      calc0 = p0 + (sum - left[i+1])/2 + 1;
    else
      calc0 = p0 + right[l0]/2 + (sum - left[i+1] - right[l0])/2 + 1;

    if(l1 == -1 || l1 == INF)
      calc1 = p1 + (sum - left[i+1])/2 + 1;
    else
      calc1 = p1 + right[l1]/2 + (sum - left[i+1] - right[l1])/2 + 1;

    sameDP = min({calc0, calc1, sameDP});

    if(right[i]%2 == 0)
      pq0.push({-(sameDP - right[i]/2), i});
    else
      pq1.push({-(sameDP - right[i]/2), i});
  }

  printf("%d\n",sameDP);
  
  return 0;
}