atcoder#ARC127B. [ARC127B] Ternary Strings

[ARC127B] Ternary Strings

Score : 500500 points

Problem Statement

Given are integers NN and LL. Find a tuple of 3N3N strings (S1,S2,,S3N)(S_1,S_2,\cdots,S_{3N}) that satisfies all of the following conditions.

  • SiS_i is a string of length LL consisting of 0, 1, 2.
  • All SiS_i are pairwise distinct.
  • For every jj (1jL1 \leq j \leq L) and every c=c=0, 1, 2, the following holds.
    • For exactly NN of the strings SiS_i, the jj-th character is cc.
  • For exactly NN of the strings SiS_i, the jj-th character is cc.
  • Let tt be the lexicographically largest string among S1,S2,,S3NS_1,S_2,\cdots,S_{3N}. tt for this tuple is the lexicographically smallest among all strings that tt can be.

Constraints

  • 1N5×1041 \leq N \leq 5 \times 10^4
  • 1L151 \leq L \leq 15
  • 3N3L3N \leq 3^L
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN LL

Output

Print the answer in the following format:

S1S_1

S2S_2

\vdots

S3NS_{3N}

If there are multiple solutions satisfying the conditions, any of them will be accepted.

2 2
00
02
11
12
20
21

This Sample Output satisfies all conditions.

For example, there are two strings whose second character is 0.

Also, we have t=t=21 in this sample, and tt is never lexicographically smaller than this.