luogu#P8946. The Lost Symbol
The Lost Symbol
Background

Problem Description
Let the binary operator denote the number of permutations , and denote the number of combinations . Define both values to be when .
Given , , and a sequence of length that contains only and , consider all sequences of length where every number is an integer in . Compute the sum of $(\cdots(((a_1\operatorname{opt}_1 a_2)\operatorname{opt}_2 a_3)\operatorname{opt}_3 a_4)\cdots\operatorname{opt}_{n-2}a_{n-1})\operatorname{opt}_{n-1}a_n$ over all such sequences.
Output the answer modulo the prime .
Input Format
The first line contains two integers .
The next line contains a string of length representing .
Output Format
Output one integer, the answer.
2 2
C
4
2 2
A
5
8 8
CCACAAC
399968
Hint
Sample Explanation
For Sample #1:
, , , . The sum is .
For Sample #2:
, , , . The sum is .
Constraints
Bundled test is not enabled, and scoring is by test points.
For of the testdata, , and contains only and .
| Test Point ID | Special Property | ||
|---|---|---|---|
| None | |||
| consists only of | |||
| consists only of | |||
| is formed by concatenating at most consecutive blocks of and consecutive blocks of | |||
| None | |||
Translated by ChatGPT 5