XOR Dice
You are given two integers N
and D
.
Find N
six-sided dice with faces labelled with nonnegative integers not more than 10^6
such that:
- for each die, the six numbers written on its faces are all distinct, and
- if you roll all dice, the bitwise XOR of the
N
numbers on top is always divisible byD
.
Under the given constraints, it can be shown that a solution always exists.
Input Format
The only line contains the two integers N
and D
.
Output Format
Output N
lines, the i
-th of which contains six distinct space-separated nonnegative integers at most 10^6
— the faces of the i
-th die.
If there are multiple possible answers, output any of them.
Constraints
1 ≤ N ≤ 100
2 ≤ D ≤ 60
Sample 0
Input
3 2
Output
1 3 5 7 9 11 3 5 7 9 11 2023 0 2 4 6 1000000 10
Explanation
There are three dice:
- Die 1 has faces
[1, 3, 5, 7, 9, 11]
. - Die 2 has faces
[3, 5, 7, 9, 11, 2023]
. - Die 3 has faces
[0, 2, 4, 6, 1000000, 10]
.
Suppose we rolled the dice, and they landed on 7, 3, and 2. Then their bitwise XOR is 7 ⊕ 3 ⊕ 2 = 6, which is a multiple of 2.
Time Limit
1000 ms
Memory Limit
262144 KiB
Please login to submit.
Login to submit.