PivotOJ

Moo Decomposition

시간 제한: 2000ms메모리 제한: 2048MB출처: USACO 2025 Open GoldBOJ 33763

문제

You have a long string SS of Ms and Os and an integer K1K \geq 1. Count the number of ways of ways to decompose SS into subsequences such that each subsequence is MOOOO....O with exactly KK Os, modulo 109+710^9+7.

Since the string is very long, you are not given it explicitly. Instead, you are given an integer LL (1L10181 \leq L \leq 10^{18}), and a string TT of length NN (1N1061 \leq N \leq 10^6). The string SS is the concatenation of LL copies of the string TT.

입력

The first line contains KK, NN, and LL.

The second line contains the string TT of length NN. Every character is either an M or an O.

It is guaranteed that the number of decompositions of SS is nonzero.

출력

Output the number of decompositions of string SS, modulo 109+710^9+7.

예제

예제 1

입력
2 6 1
MOOMOO
출력
1

예제 2

입력
2 6 1
MMOOOO
출력
6

예제 3

입력
1 4 2
MMOO
출력
4

예제 4

입력
1 4 100
MMOO
출력
976371285
코드를 제출하려면 로그인하세요.