Bob's Substring Modification

View as PDF

Submit solution

Points: 20
Time limit: 1.0s
Memory limit: 512M

Problem type

Bob got two strings, a and b, which consist of only N lower case letters. For each string, there are N - K + 1 length of K substrings. Bob will use them to create two sets A and B. For every substring s_a in A, Bob can modify the consecutive suffix of s_a to any other characters at the cost of the length of modified suffix. The total cost is the sum of all modifications. Now Bob wants to modify the substrings in the set A so that the set A will contain exactly same substrings as the set B. Can you help Bob to find the minimum total cost?

Input Specification

The first line of input contains two integers N and K (1 \le K \le N \le 150\, 000), the number of strings and the length of each substring.

The second line of input contains one string a, (|a| = N).

The second line of input contains one string b, (|b| = N).

Output Specification

Output one integer, the minimal total cost to modify the set A to be the set B.

Constraints

Subtask Points Additional constraints
1 10 N \le 11.
2 20 N \le 200.
3 20 N \le 2000.
4 50 No additional constraints.

Sample Input

5 3
aabaa
ababa

Sample Output

3

Explanation for Sample

The set A = \{ aab, aba, baa\} and B = \{aba, bab, aba\}. Bob can modify aab to aba with a cost of 2, and modify baa to bab with a cost of 1. The total cost is 3.


Comments

There are no comments at the moment.