CSES - Pattern clique
  • Time limit: 2.00 s
  • Memory limit: 512 MB

We have patterns that consist of characters A, B, and ?. Here characters A and B are incompatible with each other; all other pairs of characters are compatible. In essence, ? is a wildcard that is compatible with everything else.

Two patterns x and y are neighbours if, for each position j, character j of pattern x and character j of pattern y are compatible. For example, here are two patterns that are neighbours:

ABA?BA?
?B??BAB

On the other hand, these patterns are not neighbours, because in the 6th position there is a character B in the first pattern and character A in the second pattern and these are incompatible:

ABA?BB?
?B??BAB

We say that k patterns x_1, x_2, \dotsc, x_k form a pattern clique if for all pairs 1 \le i < j \le k patterns x_i and x_j are neighbours. For example, here is a pattern clique of size k = 3:

ABA?BA?
?B??BAB
A?ABBA?

In this task, you are given n different patterns. Your task is to count the number of subsets of k patterns that form a pattern clique.

Input

The first line contains three numbers: n, m, and k.

Then there are n lines. Each line contains one pattern, and each pattern consists of m characters.

Output

Print the total number of pattern cliques of size exactly k.

Limits

  • 1 \le n \le 100
  • 1 \le m \le 100
  • 1 \le k \le 5

Example 1

Input:

10 30 5
B???????BA???A?????AA?????A???
?????A??????B?????????????A???
B??????????AA????B????????????
?A????????A???????????A?B?????
???AAA??B??AB?B?????A???B?????
AAB?B?????????????A??????????A
?A???B??????????B??????A??????
??????????AB????????????B?BAA?
????????A????????A?BB?A???BB??
B???????B?AA?????A???B????????

Output:

1

Explanation: Here there is only one pattern clique of size 5, consisting of the following patterns:

B???????BA???A?????AA?????A???
?????A??????B?????????????A???
?A????????A???????????A?B?????
???AAA??B??AB?B?????A???B?????
B???????B?AA?????A???B????????

Example 2

Input:

10 30 5
??????????????????????????????
????????????????????????????B?
????????????????????A?????????
????????????????????????B?????
B?????????????????????????????
????????????????B?????B???????
???????????????A??????????????
??????????B???????????????????
?????????????A????????????????
??????????????????????????B???

Output:

252

Explanation: Here all patterns are neighbours, and therefore there are \binom{10}{5} = 252 pattern cliques of size 5.