Codeforces Round 265 (Div. 1)
A
No to Palindromes!
Codeforces
1700
原题
←B →
翻译中…

Paul hates palindromes. He assumes that string $*s*$ is tolerable if each its character is one of the first $*p*$ letters of the English alphabet and $*s*$ doesn't contain any palindrome contiguous substring of length 2 or more.

翻译中…

Paul has found a tolerable string $*s*$ of length $*n*$. Help him find the lexicographically next tolerable string of the same length or else state that such string does not exist.

翻译中…

Input

翻译中…

The first line contains two space-separated integers: $*n*$ and $*p*$ ($1 ≤ *n* ≤ 1000$; $1 ≤ *p* ≤ 26$). The second line contains string $*s*$, consisting of $*n*$ small English letters. It is guaranteed that the string is tolerable (according to the above definition).

翻译中…

Output

翻译中…

If the lexicographically next tolerable string of the same length exists, print it. Otherwise, print "NO" (without the quotes).

翻译中…

Note

翻译中…

String $*s*$ is lexicographically larger (or simply larger) than string $*t*$ with the same length, if there is number $*i*$, such that $*s*_{1} = *t*_{1}$, ..., $*s*_{*i*} = *t*_{*i*}$, $*s*_{*i* + 1} > *t*_{*i* + 1}$.

翻译中…

The lexicographically next tolerable string is the lexicographically minimum tolerable string which is larger than the given one.

翻译中…

A palindrome is a string that reads the same forward or reversed.

翻译中…

样例

Input #1
3 3
cba
Output #1
NO
InputCopy OutputCopy
Input #2
3 4
cba
Output #2
cbd
InputCopy OutputCopy
Input #3
4 4
abcd
Output #3
abda
InputCopy OutputCopy
题目信息
题号
464A
时间限制
1 s
内存限制
256 MB
标签
贪心
字符串

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