eolymp
bolt
Try our new interface for solving problems
Problems

Moortal Cowmbat

Moortal Cowmbat

Time limit 1 second
Memory limit 128 MiB

Bessie has been playing the popular fighting game Moortal Cowmbat for a long time now. However, the game developers have recently rolled out an update that is forcing Bessie to change her play style.

The game uses m buttons labeled by the first m lowercase letters. Bessie's favorite combo of moves in the game is a length-n string s of button presses. However, due to the most recent update, every combo must now be made from a series of "streaks", where a streak is defined as a series of the same button pressed at least k times in a row. Bessie wants to modify her favorite combo to produce a new combo of the same length n, but made from streaks of button presses to satisfy the change in rules.

It takes a[ij] days for Bessie to train herself to press button j instead of button i at any specific location in her combo (i.e. it costs a[ij] to change a single specific letter in s from i to j). Note that it might take less time to switch from using button i to an intermediate button k and then from button k to button j rather than from i to j directly (or more generally, there may be a path of changes starting with i and ending with j that gives the best overall cost for switching from button i ultimately to button j).

Help Bessie determine the smallest possible number of days she needs to create a combo that supports the new requirements.

Input data

The first line contains n (1n10^5), m (1m26) and k (1kn). The second line contains s, and the final m lines contain an m * m matrix of values a[ij], where a[ij] is an integer in the range 0...1000 and a[ii] = 0 for all i.

Output data

Print a single number, representing the minimum number of days Bessie needs to change her combo into one that satisfies the new requirements.

Example

The optimal solution in this example is to change the a into b, change the d into e, and then change both e’s into c’s. This will take 1 + 4 + 0 + 0 = 5 days, and the final combo string will be bbccc.

Examples

Input example #1
5 5 2
abcde
0 1 4 4 4
2 0 4 4 4
6 5 0 3 2
5 5 5 0 4
3 7 0 5 0
Output example #1
5
Source 2019 USACO December Gold