Under construction

Still being built. Things may change

Yeoksam Station

Time limit2sMemory limit1024 MB

Summary
Count the distinct substrings of S that contain a palindrome of length at least K.
Level

Hard8 of 10

Topics
String, String matching, Sorting
Solved
No attempts yet

Problem

This problem is fun. It feels like my favorite string quiz. You are given a string SS of length NN and a positive integer KK. A string is called a "Yeowoo string" if it has a palindrome of length at least KK as a substring. How many distinct substrings of SS are Yeowoo strings?

A palindrome reads the same forwards and backwards, such as "기러기", "토마토", "스위스", "인도인", "별똥별", and "우영우". A substring is a contiguous part of a string that is not empty.

For example, when SS is "banana" and K=3K=3, the distinct substrings of SS are the following.

  • "a", "an", "ana", "anan", "anana"
  • "b", "ba", "ban", "bana", "banan", "banana"
  • "n", "na", "nan", "nana"

Of these, the Yeowoo strings are the following 8.

  • "ana", "anan", "anana"
  • "bana", "banan", "banana"
  • "nan", "nana"

Input

The first line contains NN and KK, separated by a space. (1≤K≤N≤505 505)\left(1\leq K\leq N\leq 505\,505\right)

The second line contains the string SS, which consists only of lowercase English letters.

Output

Print the number of distinct substrings of SS that are Yeowoo strings.

Hint

If you only focus on counting, you cannot solve this problem. Look at the core idea.

Examples1

  1. Example 1

    Input
    6 3
    banana
    
    Expected output
    8