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 <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cstdio>
struct String {
	char* str;
	const int length;
	String(const int size) : str{ new char[size + 1] }, length{ size } {};
	~String() { delete[] str; }
	const char operator[](const int index) const {
		return str[index];
	}
};
int scanf(String& str) {
	return std::scanf("%s", str.str);
}
std::istream& operator>>(std::istream& is, String& str) {
	return std::cin >> std::setw(str.length + 1) >> str.str;
}
int main() {
	std::cin.tie(0); std::ios::sync_with_stdio(false);
	int n, k; std::cin >> n >> k;
	String from(n), to(n); std::cin >> from >> to;
	std::vector<int> left_diff(n, 0);
	for (auto i = 0; i < n; ++i) {
		if (from[i] != to[i]) left_diff[i] = i;
		else if (i > 0) left_diff[i] = left_diff[i - 1];
	}
	std::vector<int> black_segment_count(n, 0), white_segment_count(n, 0);
	if (to[0] == 'B') black_segment_count[0]++;
	else white_segment_count[0]++;
	for (auto i = 1; i < n; ++i) {
		black_segment_count[i] = black_segment_count[i - 1];
		white_segment_count[i] = white_segment_count[i - 1];
		if (to[i] != to[i - 1]) {
			if (to[i] == 'B') black_segment_count[i]++;
			else white_segment_count[i]++;
		}
	}
	
	std::deque<int> black_end, white_end;
	std::vector<int> left_min_cost(n + 1, 0);
	for (int i = 0; i < n; ++i) {
		if (to[i] != from[i]) left_min_cost[i + 1] = left_min_cost[left_diff[i]] + 1;
		else left_min_cost[i + 1] = left_min_cost[left_diff[i] + 1];
		while (!black_end.empty() && black_end.front() <= i - k) black_end.pop_front();
		while (!white_end.empty() && white_end.front() <= i - k) white_end.pop_front();
		if (to[i] == 'B') {
			if (!black_end.empty()) left_min_cost[i + 1] = std::min(left_min_cost[i + 1], left_min_cost[black_end.front()] - black_segment_count[black_end.front()] + black_segment_count[i] + 1);
			while (!black_end.empty() && left_min_cost[black_end.back()] - black_segment_count[black_end.back()] > left_min_cost[i] - black_segment_count[i])
				black_end.pop_back();
			black_end.push_back(i);
		}
		else {
			if (!white_end.empty()) left_min_cost[i + 1] = std::min(left_min_cost[i + 1], left_min_cost[white_end.front()] - white_segment_count[white_end.front()] + white_segment_count[i] + 1);
			while (!white_end.empty() && left_min_cost[white_end.back()] - white_segment_count[white_end.back()] > left_min_cost[i] - white_segment_count[i])
				white_end.pop_back();
			white_end.push_back(i);
		}
	}
	std::cout << left_min_cost.back() << std::endl;
}