#P8946. The Lost Symbol

The Lost Symbol

Background

Problem Description

Let the binary operator kA⁡nk\operatorname A n denote the number of permutations Ank{\rm A}_n^k, and kC⁡nk \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,n−1]{\rm opt}_{[1,n-1]} of length n−1n-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 n−1n-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:

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

For Sample #2:

1A⁡1=11\operatorname A 1=1, 1A⁡2=21\operatorname A 2=2, 2A⁡1=02\operatorname A 1=0, 2A⁡2=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, 2≤n,m≤1052\leq n,m\leq 10^5, and opt{\rm opt} contains only A\textrm A and C\textrm C.

Test Point ID n≤n\leq m≤m\leq Special Property
1∼31\sim3 88 None
4∼64\sim6 314314 159159
7∼107\sim10 27182718 28182818
11∼1311\sim13 10510^5 10510^5 opt\rm opt consists only of A\rm A
14∼1614\sim16 opt\rm opt consists only of C\rm C
17∼2017\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
23∼2523\sim25 10510^5

Translated by ChatGPT 5