Being a student of Belarusian State University (BSU) is an earnest reason for pride. While studying the Theory of Algorithms course, you are obliged to solve many challenging problems before you are admitted to the final exam. Here is one of these problems.
You are given a positive integer n and 4n integers c(i,j,k) which can be equal to 0 or 1 (0≤i<n, j \in \left\\{0, 1\right\\}, k \in \left\\{0, 1\right\\}).
Consider two integers x and y between 0 and 2n−1, inclusively. Let x=∑_i=0n−1x_i⋅2i and y=∑_i=0n−1y_i⋅2i be their binary representations (x\_i, y\_j \in \left\\{0, 1\right\\}). Define f(x,y)=∑_i=0n−1c(i,x_i,y_i)⋅2i. Clearly, f(x,y) is also an integer between 0 and 2n−1.
Given two multisets A and B, find the multiset of values f(a,b) over all pairs (a,b), where a∈A, b∈B.
The first line contains an integer n (1≤n≤18).
The second line contains n binary strings of 4 digits. The i-th string consists of the values of c(i−1,0,0), c(i−1,0,1), c(i−1,1,0), c(i−1,1,1) in this particular order.
The next two lines describe multisets A and B, respectively. The description of a multiset consists of 2n integers q_0,q_1,…,q_2n−1 denoting the quantities of the numbers 0,1,…,2n−1 in the multiset (q_i≥0, ∑q_i≤109). There are no other numbers in the multisets.
Print 2n integers in a single line, the quantities of the numbers 0,1,…,2n−1 in the resulting multiset.
In the first example, you are given 5 and 6. For x\_i, y\_i \in \left\\{0, 1\right\\}, we have f(x_0+2x_1+4x_2,y_0+2y_1+4y_2)=(x_0 OR y_0)+2⋅(x_1 XOR y_1)+4⋅(x_2 AND y_2). Thus, the only number in the resulting multiset is 7.