Codeforces Round 320 (Div. 1) [Bayan Thanks-Round]
D
LCS Again
Codeforces
2700
原题
← CE →
翻译中…

You are given a string $*S*$ of length $*n*$ with each character being one of the first $*m*$ lowercase English letters.

翻译中…

Calculate how many different strings $*T*$ of length $*n*$ composed from the first $*m*$ lowercase English letters exist such that the length of LCS (longest common subsequence) between $*S*$ and $*T*$ is $*n* - 1$.

翻译中…

Recall that LCS of two strings $*S*$ and $*T*$ is the longest string $*C*$ such that $*C*$ both in $*S*$ and $*T*$ as a subsequence.

翻译中…

Input

翻译中…

The first line contains two numbers $*n*$ and $*m*$ denoting the length of string $*S*$ and number of first English lowercase characters forming the character set for strings ($1 ≤ *n* ≤ 100 000$, $2 ≤ *m* ≤ 26$).

翻译中…

The second line contains string $*S*$.

翻译中…

Output

翻译中…

Print the only line containing the answer.

翻译中…

Note

翻译中…

For the first sample, the $6$ possible strings $*T*$ are: aab, aac, aba, aca, baa, caa.

翻译中…

For the second sample, the $11$ possible strings $*T*$ are: aaa, aac, aba, abb, abc, aca, acb, baa, bab, caa, cab.

翻译中…

For the third sample, the only possible string $*T*$ is b.

翻译中…

样例

Input #1
3 3
aaa
Output #1
6
InputCopy OutputCopy
Input #2
3 3
aab
Output #2
11
InputCopy OutputCopy
Input #3
1 2
a
Output #3
1
InputCopy OutputCopy
Input #4
10 9
abacadefgh
Output #4
789
InputCopy OutputCopy
题目信息
题号
578D
时间限制
2 s
内存限制
256 MB
标签
动态规划
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。