Josh is trapped inside a mirror maze!
The maze consists of small rooms connected by mirrored hallways, such that there is exactly one bidirectional mirrored hallway between any two rooms. This maze is weird - hallways are not flat and can tunnel underneath each other as to not intersect each other, and there is no exit!
The hallway connecting the -th and -th room is associated with a value , representing the dizziness of the mirrors in that hallway. When Josh passes through a hallway, his dizziness will become the bitwise OR of his previous dizziness and the dizziness of that hallway.
Initially, Josh begins with a dizziness of , and starts in an unknown room. He will traverse exactly hallways. Unfortunately, Josh's poor memory and poor sense of orientation results in him being unable to differentiate between the hallways coming out from a room - he can't even remember the hallway he just came from! Therefore, for each of the hallways that Josh traverses, he will pick a hallway uniformly at random out of the hallways connected to his current room, and then traverse that hallway.
For each possible starting room, help Josh find the expected value of his dizziness after traversing all hallways.
Constraints
for . Note that there is no hallway connecting a room to itself, and that this value is included just for easier input processing.
Subtask 1 [20%]
Subtask 2 [60%]
Subtask 3 [20%]
No additional constraints.
Input Specification
The first line contains two space separated integers containing the values of and .
The -th of the following lines contains space separated integers, .
Output Specification
Print a single line containing space separated integers, with the -th integer representing the expected value of Josh's final dizziness if he was to start in the -th room. It can be shown that this expected value can be expressed in the form , where and are integers with no common divisor greater than . Instead of printing the expected value as a floating point number, print , where is an integer such that .
Sample Input
3 2
0 2 4
2 0 5
4 5 0
Sample Output
500000008 500000008 500000009
Explanation
Consider the case where Josh starts in the -st room. There are four possible moves that Josh could make, with equal probability:
- Travel to the -nd room and then back to the -st room. Josh's final dizzyness is .
- Travel to the -nd room and then to the -rd room. Josh's final dizzyness is .
- Travel to the -rd room and then back to the -st room. Josh's final dizzyness is .
- Travel to the -rd room and then to the -nd room. Josh's final dizzyness is .
Here, denotes the bitwise OR operator.
Therefore, the expected value of Josh's final dizziness is .
The answer for the first room is therefore .
Comments