Ayeong runs the music show "The Great Mixing Song Festival" at the CHBS network. The show invites singers to perform a new song built by mixing existing songs, and an audience panel picks the best arrangement.
Next week's theme is "mixing the hits of an era". Take the song that ranked first in each year, then combine songs released close in time into one new song. The rules are as follows.
You are given the song that ranked first in each of the last N years. Ayeong decides how many mixings to make. Maximize the total satisfaction.
The first line contains the number of years of songs N (1≤N≤500), the largest year difference allowed inside one mixing m (1≤m≤6), and the number of songs used in one mixing c (2≤c≤m+1), separated by spaces.
Each of the next N lines contains the melody Si (1≤∣Si∣≤500) of the song that ranked first in year i. Every melody consists only of the lowercase letters a to g, which stand for notes. The song on line i comes from year i, so year i and year j differ by ∣i−j∣.
Print the maximum possible sum of the satisfactions of the mixings you make.
In the second example the best plan mixes the songs of years 1, 3, 4 into one song and the songs of years 5, 6, 7 into another. The longest common melodies of the two mixings are bcde and bcd, and their lengths add up to 7. The song of year 2 is used in no mixing.