5515: No to Palindromes!

内存限制:256 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:4 通过:4

题目描述

保罗讨厌回文。他假设字符串 s 是可以容忍的,如果每个字符都是英语字母表的前 p 个字母之一,并且 s 不包含任何长度为 2 或更大的回文连续子字符串。

保罗找到了一个长度 n 的可容忍字符串 s。帮助他找到相同长度的可容忍字符串旁边的字典顺序,否则声明该字符串不存在。

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).
Examples
Input
3 3
cba
Output
NO
Input
3 4
cba
Output
cbd
Input
4 4
abcd
Output
abda
Note
String s is lexicographically larger (or simply larger) than string t with the same length, if there is number i, such that s1=t1, ..., si=ti, si+1>ti+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.

输入格式

第一行包含两个空格分隔的整数:n 和 p (1≤n≤1000; 1≤p≤26页)。第二行包含字符串 s,由 n 个小英文字母组成。保证字符串是可以容忍的(根据上面的定义)。

输出格式

如果存在相同长度的字典顺序可容忍字符串,请打印它。否则,请打印“NO”(不带引号)。

输入样例1

3 3

cba

输出样例1:

NO

输入样例2:

3 4

cba

输出样例2:

cbd

输入样例3:

4 4

abcd

输出样例3:

abda

注意

字符串 s 在字典上比具有相同长度的字符串 t 大(或更大),如果有数字 i,则s1=t1, ..., si=tisi+1>ti+1

词典顺序上下一个可容忍字符串是字典上最小可容忍字符串,它大于给定的字符串。
回文是读取相同正向或反向的字符串

输入样例 复制

3 4
cba

输出样例 复制

cbd