Under construction

Still being built. Things may change

Lucid Strings

Time limit0.5sMemory limit512 MB

Summary
Count the substrings of a string of length n that split into k equal-length pieces where all k pieces are pairwise distinct.
Level

Medium6 of 10

Topics
String matching, Hash map, String
Solved
No attempts yet

Problem

Consider a string over the 26 lowercase English letters. If the length of the string can be written as the product of two positive integers kk (≥ 2) and cc, the string can be split into kk substrings of the same length cc. If those kk substrings are pairwise distinct, the string is called a "kk-Lucid-String" (or "kk-LS" for short). A substring is a contiguous sequence of characters within a string.

For example, the string ababca has length 6, so it has three cases to check: k=2,3,6k = 2, 3, 6. For k=2k = 2, the string splits into aba and bca, which are distinct, so the string is a 2-LS. For k=3k = 3, the string splits into three substrings of length 2, but ab appears twice, so it is not a 3-LS. For k=6k = 6, the string splits into six substrings of length 1, but a and b each appear twice, so it is not a 6-LS.

Given a string SS of length nn and an integer kk, count the substrings of SS that are kk-LS. Two substrings count separately if they start at different positions in SS, even when their contents are equal.

For example, take ababca with k=2k = 2. Each of the substrings ab, ba, ab, bc, and ca splits into two distinct substrings of length 1, so each is a 2-LS. The substrings babc and abca are also 2-LS, since each splits into two distinct substrings of length 2. The whole string is a 2-LS too, so ababca has 8 substrings that are 2-LS.

Input

The first line contains two integers nn (3 ≤ nn ≤ 40,000) and kk (2 ≤ kk ≤ 40,000). Here nn is the length of the string and kk is the number of equal-length substrings in each kk-LS. You can assume that kk ≤ nn. The second line contains a string of length nn.

Output

Print one line containing the number of substrings of the input string that are kk-LS.

Examples2

  1. Example 1

    Input
    6 2
    ababca
    
    Expected output
    8
    
  2. Example 2

    Input
    6 3
    ababca
    
    Expected output
    2