时间限制:C/C++/Rust/Pascal 3秒,其他语言6秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld
题目描述
Given a string

of length

, which only contains the characters

,

, and

.
For any interval
![[l, r] [l, r]](https://www.nowcoder.com/equation?tex=%5Ctextstyle%20%5Bl%2C%20r%5D)
(

), if the substring from the

-th to the

-th character is entirely composed of

s, its value is

; otherwise, its value is

. The value of the string is defined as the sum of the values of all intervals.
Assuming that every

in

is independently replaced with

or

with equal probability, what is the expected value of the string? Output the result modulo

.
输入描述:
The first line contains two integers

and

(

), representing the length of the string and the parameter for calculating the value, respectively.
The second line contains a string

of length

, which consists only of the characters

,

, and

.
输出描述:
Output a single integer, the expected value of the string modulo

.
Formally, let

. It can be shown that the answer can be expressed as an irreducible fraction

, where

and

are integers and

. Output the integer equal to

. In other words, output such an integer

that

and

.