Under construction

Still being built. Things may change

Coins

Time limit25sMemory limit1024 MB

Summary
Count the ways to add stacks of blue and red coins so that the whole row is a second-player win, for each total stack count from k to n.
Level

Hard8 of 10

Topics
Game theory, Combinatorics, Dynamic programming
Solved
No attempts yet

Problem

Natalia and Cezary like games, especially ones they invented themselves. They decided to lay out a row of coin stacks, with exactly mm coins in each stack, where every coin is either blue or red. On her turn, Natalia picks any blue coin and removes it from the game together with all coins above it in its stack. On his turn, Cezary picks any red coin and removes it together with all coins above it in the same stack. The players move in turns, and whoever cannot make a legal move loses. That happens when all of their coins have already been removed.

A row of stacks is called fair if, when both players play optimally, the player who does not make the first move wins. In other words, if Natalia moves first, Cezary wins under optimal play, and if Cezary moves first, Natalia wins.

The pair has already built the first kk stacks, with mm coins each. They are now deciding how to finish the row. They concluded that the game should have no more than nn stacks. For each d∈[k,n]d \in [k, n], count the fair rows of dd stacks with mm coins each that begin with the stacks they have already built. Two rows are different if there exist i∈[1,d]i \in [1, d] and j∈[1,m]j \in [1, m] such that the jj-th coin of the ii-th stack is blue in one row and red in the other.

Since the answers can be very large, print them modulo 109+710^9 + 7.

Input

The first line contains three integers nn, mm, and kk: the limit on the number of stacks, the number of coins in each stack, and the number of stacks already built. Constraints: 1≤n≤321 \le n \le 32, 1≤m≤241 \le m \le 24, 0≤k≤n0 \le k \le n. The next kk lines describe the existing stacks. Line ii is a string of exactly mm characters 'N' and 'C' that lists the colors of the ii-th stack from the bottom. If the jj-th character is 'N', the jj-th coin from the bottom is blue. Otherwise the character is 'C' and that coin is red.

Output

Print one line with n−k+1n - k + 1 integers separated by spaces. The ii-th integer is the number of ways to add i−1i - 1 stacks so that the final row is fair, modulo 109+710^9 + 7.

Hint

Explanation of the first example: if no stacks are added, a row with a single stack is not fair. Adding one NNC stack makes a two-stack row fair. There are three ways to add two stacks: [CCN, NNN], [NNN, CCN], and [NCN, NCN].

Examples2

  1. Example 1

    Input
    3 3 1
    CCN
    
    Expected output
    0 1 3
    
  2. Example 2

    Input
    2 1 0
    
    Expected output
    1 0 2