luogu#P8946. The Lost Symbol

The Lost Symbol

Background

Problem Description

Let the binary operator kAnk\operatorname A n denote the number of permutations Ank{\rm A}_n^k, and kCnk \operatorname C n denote the number of combinations Cnk{\rm C}_n^k. Define both values to be 00 when k>nk>n.

Given nn, mm, and a sequence opt[1,n1]{\rm opt}_{[1,n-1]} of length n1n-1 that contains only A\textrm A and C\textrm C, consider all sequences a[1,n]a_{[1,n]} of length nn where every number is an integer in [1,m][1,m]. 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 1141760311417603.

Input Format

The first line contains two integers n,mn,m.

The next line contains a string of length n1n-1 representing opt\text{opt}.

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:

1C1=11\operatorname C 1=1, 1C2=21\operatorname C 2=2, 2C1=02\operatorname C 1=0, 2C2=12\operatorname C 2=1. The sum is 44.

For Sample #2:

1A1=11\operatorname A 1=1, 1A2=21\operatorname A 2=2, 2A1=02\operatorname A 1=0, 2A2=22\operatorname A 2=2. The sum is 55.

Constraints

Bundled test is not enabled, and scoring is by test points.

For 100%100\% of the testdata, 2n,m1052\leq n,m\leq 10^5, and opt{\rm opt} contains only A\textrm A and C\textrm C.

Test Point ID nn\leq mm\leq Special Property
131\sim3 88 None
464\sim6 314314 159159
7107\sim10 27182718 28182818
111311\sim13 10510^5 10510^5 opt\rm opt consists only of A\rm A
141614\sim16 opt\rm opt consists only of C\rm C
172017\sim20 opt\rm opt is formed by concatenating at most 1010 consecutive blocks of A\rm A and consecutive blocks of C\rm C
21,2221,22 84928492 None
232523\sim25 10510^5

Translated by ChatGPT 5