#P1033F. Boolean Computer
Boolean Computer
No submission language available for this problem.
Description
Alice has a computer that operates on -bit integers. The computer has registers for values. The current content of the registers is given as an array .
The computer uses so-called "number gates" to manipulate this data. Each "number gate" takes two registers as inputs and calculates a function of the two values stored in those registers. Note that you can use the same register as both inputs.
Each "number gate" is assembled from bit gates. There are six types of bit gates: AND, OR, XOR, NOT AND, NOT OR, and NOT XOR, denoted "A", "O", "X", "a", "o", "x", respectively. Each bit gate takes two bits as input. Its output given the input bits , is given below:
To build a "number gate", one takes bit gates and assembles them into an array. A "number gate" takes two -bit integers and as input. The "number gate" splits the integers into bits and feeds the -th bit of each input to the -th bit gate. After that, it assembles the resulting bits again to form an output word.
For instance, for -bit computer we might have a "number gate" "AXoA" (AND, XOR, NOT OR, AND). For two inputs, and , this returns , as and is , xor is , not ( or ) is , and finally and is .
You are given a description of "number gates". For each gate, your goal is to report the number of register pairs for which the "number gate" outputs the number . In other words, find the number of ordered pairs where , such that , where is the function computed by the -th "number gate".
The first line contains three integers: , , and — the word size, the number of variables, and the number of gates.
The second line contains integers — the value of variables stored in the registers.
Each of the next lines contains a string with a description of a single gate. Each character of is one of "A", "O", "X", "a", "o", "x".
Print lines. The -th line should contain the number of ordered pairs of variables for which the -th gate returns zero.
Input
The first line contains three integers: , , and — the word size, the number of variables, and the number of gates.
The second line contains integers — the value of variables stored in the registers.
Each of the next lines contains a string with a description of a single gate. Each character of is one of "A", "O", "X", "a", "o", "x".
Output
Print lines. The -th line should contain the number of ordered pairs of variables for which the -th gate returns zero.
Samples
Note
In the first test case, the inputs in binary are , , . The pairs that return are , , and . As it was already mentioned in the problem statement, . The other pairs are , and .