#abc356c. C - Keys

C - Keys

Score : 300300 points

问题陈述

你有 NN 把钥匙,编号为 1,2,,N1, 2, \dots, N。 其中一些是真正的钥匙,而其他的是假钥匙。

有一扇门,门 X,你可以插入任意数量的钥匙。门 X 只有在至少插入了 KK 把真正的钥匙时才会打开。

你已经对这些钥匙进行了 MM 次测试。第 ii 次测试的步骤如下:

  • 你插入了 CiC_i 把钥匙 Ai,1,Ai,2,,Ai,CiA_{i,1}, A_{i,2}, \dots, A_{i,C_i} 到门 X。
  • 测试结果由一个英文字母 RiR_i 表示。
    • Ri=R_i = o 表示在第 ii 次测试中门 X 打开了。
    • Ri=R_i = x 表示在第 ii 次测试中门 X 没有打开。

2N2^N 种可能的组合,哪些钥匙是真正的,哪些是假钥匙。在这些组合中,找出不与任何测试结果相矛盾的组合数量。 有可能给定的测试结果是错误的,没有任何组合满足条件。在这种情况下,报告 00

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

You have NN keys numbered 1,2,,N1, 2, \dots, N.
Some of these are real keys, while the others are dummies.

There is a door, Door X, into which you can insert any number of keys. Door X will open if and only if at least KK real keys are inserted.

You have conducted MM tests on these keys. The ii-th test went as follows:

  • You inserted CiC_i keys Ai,1,Ai,2,,Ai,CiA_{i,1}, A_{i,2}, \dots, A_{i,C_i} into Door X.
  • The test result is represented by a single English letter RiR_i.
    • Ri=R_i = o means that Door X opened in the ii-th test.
    • Ri=R_i = x means that Door X did not open in the ii-th test.

There are 2N2^N possible combinations of which keys are real and which are dummies. Among these, find the number of combinations that do not contradict any of the test results.
It is possible that the given test results are incorrect and no combination satisfies the conditions. In such a case, report 00.

Constraints

  • NN, MM, KK, CiC_i, and Ai,jA_{i,j} are integers.
  • 1KN151 \le K \le N \le 15
  • 1M1001 \le M \le 100
  • 1CiN1 \le C_i \le N
  • 1Ai,jN1 \le A_{i,j} \le N
  • Ai,jAi,kA_{i,j} \neq A_{i,k} if jkj \neq k.
  • RiR_i is o or x.

Input

The input is given from Standard Input in the following format:

NN MM KK

C1C_1 A1,1A_{1,1} A1,2A_{1,2} \dots A1,C1A_{1,C_1} R1R_1

C2C_2 A2,1A_{2,1} A2,2A_{2,2} \dots A2,C2A_{2,C_2} R2R_2

\vdots

CMC_M AM,1A_{M,1} AM,2A_{M,2} \dots AM,CMA_{M,C_M} RMR_M

Output

Print the answer as an integer.

Sample Input 1

3 2 2
3 1 2 3 o
2 2 3 x

Sample Output 1

2

In this input, there are three keys and two tests were conducted.
Two correct keys are required to open Door X.

  • In the first test, keys 1,2,31, 2, 3 were used, and Door X opened.
  • In the second test, keys 2,32, 3 were used, and Door X did not open.

There are two combinations of which keys are real and which are dummies that do not contradict any of the test results:

  • Key 11 is real, key 22 is a dummy, and key 33 is real.
  • Key 11 is real, key 22 is real, and key 33 is a dummy.

Sample Input 2

4 5 3
3 1 2 3 o
3 2 3 4 o
3 3 4 1 o
3 4 1 2 o
4 1 2 3 4 x

Sample Output 2

0

As mentioned in the problem statement, the answer may be 00.

Sample Input 3

11 4 9
10 1 2 3 4 5 6 7 8 9 10 o
11 1 2 3 4 5 6 7 8 9 10 11 o
10 11 10 9 8 7 6 5 4 3 2 x
10 11 9 1 4 3 7 5 6 2 10 x

Sample Output 3

8