#P5684. [CSP-J 2019 江西] 非回文串

[CSP-J 2019 江西] 非回文串

Description

Alice has nn characters, all of which are lowercase English letters, numbered from 1n1 \sim n, namely c1,c2,,cnc_1,c_2, \dots , c_n.
Bob plans to rearrange these characters to form a string SS. Bob knows that Alice has OCD, so he plans to make SS a non-palindromic string to annoy Alice.

Now Bob wants to know how many different ways of rearranging the characters there are such that SS is a non-palindromic string. A rearrangement plan means a permutation pip_i of 1n1 \sim n, and it forms S=cp1cp2cpnS = c_{p_1}c_{p_2} \dots c_{p_n}.

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 109+710^9+7.

Input Format

The first line contains a positive integer nn, which represents the number of characters.
The second line contains nn lowercase English letters cic_i.

Output Format

Only one line containing an integer representing the answer. The answer is taken modulo 109+710^9+7.

3
aba
4
8
aabbbbcc
39168

Hint

Constraints
For 20%20\% of the testdata, n8n \le 8;
For 50%50\% of the testdata, n20n \le 20;
For the other 30%30\% of the testdata, the characters only include a and b;
For 100%100\% of the testdata, 3n20003 \le n \le 2000.

Translated by ChatGPT 5