Little Bob’s computer has 2
n bytes of memory. For convenience, n-bit integers 0 to 2
n - 1 are used to index these bytes.
Now he wants to assign a value to each byte of the memory. In this problem, a byte is composed of m bits. Therefore he can only assign 0 to 2
m - 1 (inclusive) to a single byte.
Bob has some preferences on which value to be assigned to each byte. For the byte indexed by i, if it is assigned with value j (0 ≤ j < 2
m), the preference score for it is w
i,
j.
In addition, each byte has a threshold value. For two different bytes indexed by a and b, if the following two conditions are satisfied, there will be an additional score (u
a xor u
b):
1.a and b only have one bit of difference in their binary forms;
2.The assigned value of byte a is not less than its threshold value, or the assigned value of byte b is not less than its threshold value.
The total score of an assignment solution is the sum of the preference scores of all bytes plus the sum of all additional scores.
Bob wants to find an assignment solution with the maximum total score. If there are multiple solutions, you can output any of them.