Black or White

Given a start row s and target row t of B/W bricks, find the minimum number of strokes, each painting at most k consecutive bricks one color, to reach t.

Medium7Dynamic programmingGreedyArrayImplementationNo attempts yetTime limit2sMemory limit512 MB

Problem

A row of nn bricks stands in front of you, each brick painted either black or white. One stroke of the brush repaints a contiguous part of the row in a single color. White paint turns every brick in the painted part white, and black paint turns every brick in the painted part black. The brush holds only so much paint at a time, so one stroke covers at most kk consecutive bricks. Within that limit you may start a stroke anywhere in the row and use either color.

For example, take four bricks colored black, white, white, black, and suppose you want them to end up white, black, black, white. With k=4k = 4 two strokes are enough. Paint all four bricks white, then paint the middle two black.

Compute the minimum number of strokes needed to turn the initial row into the desired row. The cost of the paint does not matter.

Input

The input consists of a single test case in the following format.

n k
s
t

The first line contains two integers nn and kk (1kn5000001 \le k \le n \le 500\,000). nn is the number of bricks in the row, and kk is the largest number of bricks one stroke paints. The second line contains a string ss of nn characters giving the initial colors. The third line contains a string tt of nn characters giving the desired colors. Every character of ss and tt is either B for black or W for white.

Output

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