#P5684. [CSP-J 2019 江西] 非回文串
[CSP-J 2019 江西] 非回文串
Description
Alice has characters, all of which are lowercase English letters, numbered from , namely .
Bob plans to rearrange these characters to form a string . Bob knows that Alice has OCD, so he plans to make a non-palindromic string to annoy Alice.
Now Bob wants to know how many different ways of rearranging the characters there are such that is a non-palindromic string. A rearrangement plan means a permutation of , and it forms .
A string is non-palindromic if and only if its reversed string is different from the original string. For example, the reversed string of abcda is adcba, which is different from the original string, so abcda is a non-palindromic string. However, the reversed string of abcba is the same as the original string, so it is a palindromic string.
Since the final result may be very large, you only need to tell Bob the value of the total number of plans modulo .
Input Format
The first line contains a positive integer , which represents the number of characters.
The second line contains lowercase English letters .
Output Format
Only one line containing an integer representing the answer. The answer is taken modulo .
3
aba
4
8
aabbbbcc
39168
Hint
Constraints
For of the testdata, ;
For of the testdata, ;
For the other of the testdata, the characters only include a and b;
For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号