11574 - Prefix to truth table   

Description

Give a prefix Boolean expression, which only has at most 26 variables ‘A’, ‘B’, ‘C’... 'Z', and 3 operators, AND ‘&’ , OR ‘|’, and ExclusiveOR '^', print its truth table which output equal to 1.

For example, if input is "4 7 &|AB|CA", then result will be

A B C D

0 1 1 0 
0 1 1 1 
1 0 0 0 
1 0 0 1 
1 0 1 0 
1 0 1 1 
1 1 0 0 
1 1 0 1 
1 1 1 0 
1 1 1 1 

Input

The input contains two unsigned short number (num and length) and a sequences of prefix expression.

  • First unsigned short number (num) means the number of variables from 'A' to 'A'+num-1. (e.g. 5 => 'A', 'B', 'C', 'D', 'E' )  1 <= num <= 26
  • Second unsigned short number (length) means the length of prefix expression.
  • A sequences of prefix expression only has at most 26 variables ‘A’, ‘B’, ‘C’... 'Z', and 3 operators, AND ‘&’ , OR ‘|’, and ExclusiveOR '^'.

Output

Print its truth table which output equal to 1. (It has ' ' behind each number)

Sample Input  Download

Sample Output  Download

Tags




Discuss