Counting strings with LCS n-1

Count length-n strings over the first m letters whose longest common subsequence with a given string S has length exactly n-1.

Hard8Dynamic programmingCombinatoricsStringNo attempts yetTime limit2sMemory limit512 MB

Problem

You are given a string SS of length nn that uses only the first mm lowercase letters of the alphabet.

Count the strings TT of length nn, built from the same mm letters, whose longest common subsequence (LCS) with SS has length exactly n1n-1.

A subsequence of a string is what remains after deleting zero or more characters and keeping the order of the characters that stay.

Input

The first line contains the string length nn and the alphabet size mm, separated by a space. (1n1000001 \le n \le 100000, 2m262 \le m \le 26)

The second line contains the string SS. Its length is nn, and it uses only the first mm lowercase letters starting from a.

Output

Print the number of strings that satisfy the condition on one line.