Consider infix boolean expressions, consisting of:
Now let's define the operator precedence for binary operators: let $$$p_\star$$$ be the precedence for the operator $$$\star$$$, the lower $$$p_\star$$$ is, the higher its precedence is. For example, consider the consider the expression $$$a \star_1 b \star_2 c$$$:
Your task is to build the truth table for a given boolean expression $$$s$$$, but to reduce the size of the output, let's hash it in the following manner:
The first line contains a string $$$s$$$ ($$$1 \leq |s| \leq 100$$$): an infix valid boolean expression with at most $$$16$$$ distinct variables.
The second line contains six integers, each between 2 and 7: $$$p_\&$$$, $$$p_\wedge$$$, $$$p_|$$$, $$$p_\#$$$, $$$p_\%$$$ and $$$p_\$$$$, the precedence for each binary operator.
Print one integer: the hash of the truth table for the expression $$$s$$$.
x|y 2 3 4 5 6 7
14
~x|y&z 2 3 4 5 6 7
143
~x|y&z 2 3 2 5 6 7
138
a%b|c^(d&e#f)$g 4 2 5 3 7 6
123140419684712618
~~x 2 3 4 5 6 7
2
The truth tables for the six binary operators are: $$$$$$ \begin{array}{|c|c|c|c|c|} \hline x & y & x \& y & x \wedge y & x | y & x \# y & x \% y & x \$ y \\ \hline 0 & 0 & 0 & 0 & 0 & 1 & 1 & 1 \\ \hline 0 & 1 & 0 & 1 & 1 & 1 & 0 & 0 \\ \hline 1 & 0 & 0 & 1 & 1 & 1 & 0 & 0 \\ \hline 1 & 1 & 1 & 0 & 1 & 0 & 1 & 0 \\ \hline \end{array} $$$$$$
In the second example we see that & is evaluated first than |, so the truth table is: $$$$$$ \begin{array}{|c|c|c|} \hline Row & x & y & z & \sim x | y \& z \\ \hline 0 & 0 & 0 & 0 & 1 \\ \hline 1 & 0 & 0 & 1 & 1 \\ \hline 2 & 0 & 1 & 0 & 1 \\ \hline 3 & 0 & 1 & 1 & 1 \\ \hline 4 & 1 & 0 & 0 & 0 \\ \hline 5 & 1 & 0 & 1 & 0 \\ \hline 6 & 1 & 1 & 0 & 0 \\ \hline 7 & 1 & 1 & 1 & 1 \\ \hline \end{array} $$$$$$ The rows that evaluate to $$$1$$$ are $$$0,1,2,3,7$$$, so the answer is $$$2^0+2^1+2^2+2^3+2^7=143$$$.
In the third example both & and | have the same precedence, so we evaluate from left to right (remember that $$$\sim$$$ still has higher precedence): $$$$$$ \begin{array}{|c|c|c|} \hline Row & x & y & z & \sim x | y \& z \\ \hline 0 & 0 & 0 & 0 & 0 \\ \hline 1 & 0 & 0 & 1 & 1 \\ \hline 2 & 0 & 1 & 0 & 0 \\ \hline 3 & 0 & 1 & 1 & 1 \\ \hline 4 & 1 & 0 & 0 & 0 \\ \hline 5 & 1 & 0 & 1 & 0 \\ \hline 6 & 1 & 1 & 0 & 0 \\ \hline 7 & 1 & 1 & 1 & 1 \\ \hline \end{array} $$$$$$ The rows that evaluate to $$$1$$$ are $$$1,3,7$$$, so the answer is $$$2^1+2^3+2^7=138$$$.
| Name |
|---|


