QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#20911. Moo Decomposition

Statistics

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

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

Input

The first line contains $K$, $N$, and $L$.

The second line contains the string $T$ of length $N$. Every character is either an M or an O.

It is guaranteed that the number of decompositions of $S$ is nonzero.

Output

Output the number of decompositions of string $S$, modulo $10^9+7$.

Examples

Input 1

2 6 1
MOOMOO

Output 1

1

The only way to decompose $S$ into MOOs is to let the first three characters form a MOO and the last three characters form another MOO.

Input 2

2 6 1
MMOOOO

Output 2

6

There are six distinct ways to decompose the string into subsequences (uppercase letters form one MOO, lowercase letters form another):

  • MmOOoo
  • MmOoOo
  • MmOooO
  • MmoOOo
  • MmoOoO
  • MmooOO

Input 3

1 4 2
MMOO

Output 3

4

Input 4

1 4 100
MMOO

Output 4

976371285

Make sure to take the answer modulo $10^9+7$.

Scoring

  • Inputs 5-7: $K=1$, $L = 1$
  • Inputs 8-10: $K=2$, $N\leq 1000$, $L = 1$
  • Inputs 11-13: $K=1$
  • Inputs 14-19: $L = 1$
  • Inputs 20-25: No additional constraints.

Problem credits: Dhruv Rohatgi

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.