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 <iostream>
#include <string>
#include <utility>
#include <vector>
#define inf 1e9

using namespace std;
typedef pair<int, int> P;

struct SegTree{
	int size;
	vector<P> seg;
	
	SegTree(){}
	SegTree(int size){
		this->size = size;
		seg.resize(1<<(size+1));
	}
	
	void init()
	{
		for(int i = 0; i < (1<<(size+1)); i++) seg[i] = make_pair(inf, i);
	}
	
	void update(int i, P val)
	{
		i += (1 << size);
		seg[i] = val;
		while(i > 1){
			i /= 2;
			seg[i] = min(seg[i*2], seg[i*2+1]);
		}
	}

	P query(int a, int b, int k, int l, int r)
	{
		if(b < l || r < a) return make_pair(inf, inf);
		if(a <= l && r <= b) return seg[k];
		P lval = query(a, b, k*2, l, (l+r)/2);
		P rval = query(a, b, k*2+1, (l+r)/2+1, r);
		return min(lval, rval);
	}
	P query(int a, int b)
	{
		return query(a, b, 1, 0, (1<<size)-1);
	}
};

int n, k;
string s, t;
bool Left[500005];
int sumB[500005], sumW[500005];
int dp[500005];
SegTree segW(19), segB(19);

int main(void)
{
	cin >> n >> k;
	cin >> s >> t;
	s = "#" + s, t = "#" + t;
	
	for(int i = 1; i <= n; i++){
		if(t[i] != t[i-1]) Left[i] = true;
	}
	for(int i = 1; i <= n; i++){
		sumB[i] = sumB[i-1];
		if(Left[i] && t[i] == 'B') sumB[i]++;
		sumW[i] = sumW[i-1];
		if(Left[i] && t[i] == 'W') sumW[i]++;
	}
	
	segB.init(), segW.init();
	segB.update(0, make_pair(0, 0)), segW.update(0, make_pair(0, 0));
	
	for(int i = 1; i <= n; i++){
		if(s[i] == t[i]) dp[i] = dp[i-1];
		else if(t[i] == 'W'){
			P p = segW.query(max(0, i-k), i-1);
			dp[i] = dp[p.second] + sumB[i] - sumB[p.second] + 1;
		}
		else if(t[i] == 'B'){
			P p = segB.query(max(0, i-k), i-1);
			dp[i] = dp[p.second] + sumW[i] - sumW[p.second] + 1;
			
		}
		if(i < n && t[i+1] == 'W' && s[i+1] == 'B') segW.update(i, make_pair(dp[i]-sumB[i], i));
		if(i < n && t[i+1] == 'B' && s[i+1] == 'W') segB.update(i, make_pair(dp[i]-sumW[i], i));
	}
	
	cout << dp[n] << endl;
	return 0;
}